@Test public void testAdd() throws IOException, MessagingException, PasswordException, GeneralSecurityException { assertEquals(0, folderDir1.list().length); folder1.add(email1); assertEquals(2, folderDir1.list().length); folder1.add(email2); assertEquals(4, folderDir1.list().length); String messageId1 = email1.getMessageID(); TestUtil.assertEquals("Email in folder differs from the original!", email1, folder1.getEmail(messageId1)); TestUtil.assertUnequal("Folder returned the wrong email!", email2, folder1.getEmail(messageId1)); String messageId2 = email2.getMessageID(); TestUtil.assertEquals("Email in folder differs from the original!", email2, folder1.getEmail(messageId2)); TestUtil.assertUnequal("Folder returned the wrong email!", email2, folder2.getEmail(messageId2)); }
public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException { if (getEmailFile(email.getMessageID()).exists()) { log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID()+ ">"); return; } File emailFile = getEmailFile(email); log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">"); OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder)); try { email.writeTo(emailOutputStream); } finally { emailOutputStream.close(); } saveMetadata(email); for (FolderListener listener: folderListeners) listener.elementAdded(email.getMessageID()); }
EmailFolder extends Folder<Email> { public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException { if (getEmailFile(email.getMessageID()).exists()) { log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID()+ ">"); return; } File emailFile = getEmailFile(email); log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">"); OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder)); try { email.writeTo(emailOutputStream); } finally { emailOutputStream.close(); } saveMetadata(email); for (FolderListener listener: folderListeners) listener.elementAdded(email.getMessageID()); } }
EmailFolder extends Folder<Email> { public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException { if (getEmailFile(email.getMessageID()).exists()) { log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID()+ ">"); return; } File emailFile = getEmailFile(email); log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">"); OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder)); try { email.writeTo(emailOutputStream); } finally { emailOutputStream.close(); } saveMetadata(email); for (FolderListener listener: folderListeners) listener.elementAdded(email.getMessageID()); } EmailFolder(File storageDir, PasswordHolder passwordHolder); }
EmailFolder extends Folder<Email> { public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException { if (getEmailFile(email.getMessageID()).exists()) { log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID()+ ">"); return; } File emailFile = getEmailFile(email); log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">"); OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder)); try { email.writeTo(emailOutputStream); } finally { emailOutputStream.close(); } saveMetadata(email); for (FolderListener listener: folderListeners) listener.elementAdded(email.getMessageID()); } 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 void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException { if (getEmailFile(email.getMessageID()).exists()) { log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID()+ ">"); return; } File emailFile = getEmailFile(email); log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">"); OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder)); try { email.writeTo(emailOutputStream); } finally { emailOutputStream.close(); } saveMetadata(email); for (FolderListener listener: folderListeners) listener.elementAdded(email.getMessageID()); } 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);  }