@Test public void testMove() throws IOException, MessagingException, PasswordException, GeneralSecurityException { folder1.add(email1); folder1.move(email1, folder2); assertEquals("Source folder is not empty!", 0, folderDir1.list().length); assertEquals("Target folder does not contain two files!", 2, folderDir2.list().length); FolderIterator<Email> iterator = folder2.iterate(); TestUtil.assertEquals("Email differs from the original!", email1, iterator.next()); }
public boolean move(String messageId, EmailFolder newFolder) { File oldEmailFile = getEmailFile(messageId); if (!oldEmailFile.exists()) { log.error("Cannot move email with message ID " + messageId + " to folder [" + newFolder + "]: email file doesn't exist in directory <" + getStorageDirectory() + ">."); return false; } File newEmailFile = new File(newFolder.getStorageDirectory(), oldEmailFile.getName()); boolean success; try { success = move(oldEmailFile, newEmailFile); } catch (IOException e) { log.error("Cannot move email file <" + oldEmailFile.getAbsolutePath() + "> to <" + newEmailFile.getAbsolutePath() + ">", e); success = false; } if (!success) return false; File oldMetaFile = getMetadataFile(oldEmailFile); if (oldMetaFile.exists()) { File newMetaFile = getMetadataFile(newEmailFile); try { success &= move(oldMetaFile, newMetaFile); } catch (IOException e) { log.error("Cannot move metadata file <" + oldMetaFile.getAbsolutePath() + "> to <" + newMetaFile.getAbsolutePath() + ">", e); success = false; } } if (success) { for (FolderListener listener: folderListeners) listener.elementRemoved(messageId); for (FolderListener listener: newFolder.folderListeners) listener.elementAdded(messageId); } return success; }
EmailFolder extends Folder<Email> { public boolean move(String messageId, EmailFolder newFolder) { File oldEmailFile = getEmailFile(messageId); if (!oldEmailFile.exists()) { log.error("Cannot move email with message ID " + messageId + " to folder [" + newFolder + "]: email file doesn't exist in directory <" + getStorageDirectory() + ">."); return false; } File newEmailFile = new File(newFolder.getStorageDirectory(), oldEmailFile.getName()); boolean success; try { success = move(oldEmailFile, newEmailFile); } catch (IOException e) { log.error("Cannot move email file <" + oldEmailFile.getAbsolutePath() + "> to <" + newEmailFile.getAbsolutePath() + ">", e); success = false; } if (!success) return false; File oldMetaFile = getMetadataFile(oldEmailFile); if (oldMetaFile.exists()) { File newMetaFile = getMetadataFile(newEmailFile); try { success &= move(oldMetaFile, newMetaFile); } catch (IOException e) { log.error("Cannot move metadata file <" + oldMetaFile.getAbsolutePath() + "> to <" + newMetaFile.getAbsolutePath() + ">", e); success = false; } } if (success) { for (FolderListener listener: folderListeners) listener.elementRemoved(messageId); for (FolderListener listener: newFolder.folderListeners) listener.elementAdded(messageId); } return success; } }
EmailFolder extends Folder<Email> { public boolean move(String messageId, EmailFolder newFolder) { File oldEmailFile = getEmailFile(messageId); if (!oldEmailFile.exists()) { log.error("Cannot move email with message ID " + messageId + " to folder [" + newFolder + "]: email file doesn't exist in directory <" + getStorageDirectory() + ">."); return false; } File newEmailFile = new File(newFolder.getStorageDirectory(), oldEmailFile.getName()); boolean success; try { success = move(oldEmailFile, newEmailFile); } catch (IOException e) { log.error("Cannot move email file <" + oldEmailFile.getAbsolutePath() + "> to <" + newEmailFile.getAbsolutePath() + ">", e); success = false; } if (!success) return false; File oldMetaFile = getMetadataFile(oldEmailFile); if (oldMetaFile.exists()) { File newMetaFile = getMetadataFile(newEmailFile); try { success &= move(oldMetaFile, newMetaFile); } catch (IOException e) { log.error("Cannot move metadata file <" + oldMetaFile.getAbsolutePath() + "> to <" + newMetaFile.getAbsolutePath() + ">", e); success = false; } } if (success) { for (FolderListener listener: folderListeners) listener.elementRemoved(messageId); for (FolderListener listener: newFolder.folderListeners) listener.elementAdded(messageId); } return success; } EmailFolder(File storageDir, PasswordHolder passwordHolder); }
EmailFolder extends Folder<Email> { public boolean move(String messageId, EmailFolder newFolder) { File oldEmailFile = getEmailFile(messageId); if (!oldEmailFile.exists()) { log.error("Cannot move email with message ID " + messageId + " to folder [" + newFolder + "]: email file doesn't exist in directory <" + getStorageDirectory() + ">."); return false; } File newEmailFile = new File(newFolder.getStorageDirectory(), oldEmailFile.getName()); boolean success; try { success = move(oldEmailFile, newEmailFile); } catch (IOException e) { log.error("Cannot move email file <" + oldEmailFile.getAbsolutePath() + "> to <" + newEmailFile.getAbsolutePath() + ">", e); success = false; } if (!success) return false; File oldMetaFile = getMetadataFile(oldEmailFile); if (oldMetaFile.exists()) { File newMetaFile = getMetadataFile(newEmailFile); try { success &= move(oldMetaFile, newMetaFile); } catch (IOException e) { log.error("Cannot move metadata file <" + oldMetaFile.getAbsolutePath() + "> to <" + newMetaFile.getAbsolutePath() + ">", e); success = false; } } if (success) { for (FolderListener listener: folderListeners) listener.elementRemoved(messageId); for (FolderListener listener: newFolder.folderListeners) listener.elementAdded(messageId); } return success; } EmailFolder(File storageDir, PasswordHolder passwordHolder); void add(Email email); void changePassword(byte[] oldPassword, DerivedKey newKey); List<Email> getElements(AddressDisplayFilter displayFilter, EmailAttribute sortColumn, boolean descending); Email getEmail(String messageId); boolean move(String messageId, EmailFolder newFolder); boolean move(Email email, EmailFolder newFolder); int getNumNewEmails(); Email getLatestUnreadEmail(); void setRecent(String messageId, boolean isRecent); void setNew(String messageId, boolean isNew); void setNew(Email email, boolean isNew); void setReplied(String messageId, boolean replied); void saveMetadata(Email email); boolean delete(String messageId); void addFolderListener(FolderListener folderListener); void removeFolderListener(FolderListener folderListener); }
EmailFolder extends Folder<Email> { public boolean move(String messageId, EmailFolder newFolder) { File oldEmailFile = getEmailFile(messageId); if (!oldEmailFile.exists()) { log.error("Cannot move email with message ID " + messageId + " to folder [" + newFolder + "]: email file doesn't exist in directory <" + getStorageDirectory() + ">."); return false; } File newEmailFile = new File(newFolder.getStorageDirectory(), oldEmailFile.getName()); boolean success; try { success = move(oldEmailFile, newEmailFile); } catch (IOException e) { log.error("Cannot move email file <" + oldEmailFile.getAbsolutePath() + "> to <" + newEmailFile.getAbsolutePath() + ">", e); success = false; } if (!success) return false; File oldMetaFile = getMetadataFile(oldEmailFile); if (oldMetaFile.exists()) { File newMetaFile = getMetadataFile(newEmailFile); try { success &= move(oldMetaFile, newMetaFile); } catch (IOException e) { log.error("Cannot move metadata file <" + oldMetaFile.getAbsolutePath() + "> to <" + newMetaFile.getAbsolutePath() + ">", e); success = false; } } if (success) { for (FolderListener listener: folderListeners) listener.elementRemoved(messageId); for (FolderListener listener: newFolder.folderListeners) listener.elementAdded(messageId); } return success; } EmailFolder(File storageDir, PasswordHolder passwordHolder); void add(Email email); void changePassword(byte[] oldPassword, DerivedKey newKey); List<Email> getElements(AddressDisplayFilter displayFilter, EmailAttribute sortColumn, boolean descending); Email getEmail(String messageId); boolean move(String messageId, EmailFolder newFolder); boolean move(Email email, EmailFolder newFolder); int getNumNewEmails(); Email getLatestUnreadEmail(); void setRecent(String messageId, boolean isRecent); void setNew(String messageId, boolean isNew); void setNew(Email email, boolean isNew); void setReplied(String messageId, boolean replied); void saveMetadata(Email email); boolean delete(String messageId); void addFolderListener(FolderListener folderListener); void removeFolderListener(FolderListener folderListener);  }