use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.
the class EmailFolder method createFolderElement.
@Override
protected Email createFolderElement(File emailFile) throws Exception {
InputStream emailStream = null;
try {
emailStream = new BufferedInputStream(new EncryptedInputStream(new FileInputStream(emailFile), passwordHolder));
InputStream metadataStream = null;
File metadataFile = getMetadataFile(emailFile);
if (metadataFile.exists())
metadataStream = new BufferedInputStream(new EncryptedInputStream(new FileInputStream(metadataFile), passwordHolder));
Email email = new Email(emailStream, metadataStream, passwordHolder);
String messageIdString = emailFile.getName().substring(0, 44);
email.setMessageID(messageIdString);
return email;
} finally {
if (emailStream != null)
emailStream.close();
}
}
use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.
the class OutboxProcessorTest method testSendEmail.
@Test
public void testSendEmail() throws Exception {
EmailIdentity identity = TestUtil.createTestIdentities().get(0).identity;
String address = "tester <" + identity.getKey() + ">";
when(identities.extractIdentity(address)).thenReturn(identity);
testEmail = new Email(true);
testEmail.setFrom(new InternetAddress(address));
testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
testEmail.setSubject("Test", "UTF-8");
testEmail.setText("foobar");
op.sendEmail(testEmail);
ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
verify(dht, times(2)).store(arg.capture());
List<DhtStorablePacket> values = arg.getAllValues();
assertTrue(values.get(0) instanceof EncryptedEmailPacket);
assertTrue(values.get(1) instanceof IndexPacket);
assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.
the class OutboxProcessorTest method testSendAnonymousEmail.
@Test
public void testSendAnonymousEmail() throws Exception {
testEmail = new Email(true);
testEmail.setFrom(new InternetAddress("anonymous"));
testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
testEmail.setSubject("Test", "UTF-8");
testEmail.setText("foobar");
op.sendEmail(testEmail);
ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
verify(dht, times(2)).store(arg.capture());
List<DhtStorablePacket> values = arg.getAllValues();
assertTrue(values.get(0) instanceof EncryptedEmailPacket);
assertTrue(values.get(1) instanceof IndexPacket);
assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.
the class BoteMailbox method startListening.
protected void startListening() {
folderListener = new FolderListener() {
public void elementAdded(String messageId) {
try {
// Add new emails to map
Email email = folder.getEmail(messageId);
email.setFlag(Flag.RECENT, true);
messageMap.put(email, new BoteMessage(email, getMailboxId()));
updateMessages();
} catch (PasswordException e) {
throw new RuntimeException(_t("Password required or invalid password provided"), e);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void elementUpdated() {
// Noop, BoteMessage has a reference to the Email
}
public void elementRemoved(String messageId) {
// Remove old email from map
Set<Email> emails = messageMap.keySet();
Iterator<Email> iter = emails.iterator();
while (iter.hasNext()) {
Email email = iter.next();
if (email.getMessageID().equals(messageId)) {
iter.remove();
break;
}
}
updateMessages();
}
};
folder.addFolderListener(folderListener);
}
use of i2p.bote.email.Email in project i2p.i2p-bote by i2p.
the class EmailFolderTest method testSetNew.
@Test
public void testSetNew() throws IOException, MessagingException, PasswordException, GeneralSecurityException {
folder1.add(email1);
FolderIterator<Email> iterator = folder1.iterate();
Email emailFromFolder = iterator.next();
assertEquals("\"unread\" flag is false after adding email to folder!", emailFromFolder.isUnread(), true);
folder1.setNew(email1.getMessageID(), false);
}
Aggregations