Search in sources :

Example 16 with Email

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();
    }
}
Also used : EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) Email(i2p.bote.email.Email) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 17 with Email

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()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EmailIdentity(i2p.bote.email.EmailIdentity) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Example 18 with Email

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()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Example 19 with Email

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);
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) Email(i2p.bote.email.Email) Set(java.util.Set) FolderListener(i2p.bote.folder.FolderListener) MessagingException(javax.mail.MessagingException) Iterator(java.util.Iterator)

Example 20 with Email

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);
}
Also used : Email(i2p.bote.email.Email) Test(org.junit.Test)

Aggregations

Email (i2p.bote.email.Email)24 PasswordException (i2p.bote.fileencryption.PasswordException)10 MessagingException (javax.mail.MessagingException)8 IOException (java.io.IOException)7 GeneralSecurityException (java.security.GeneralSecurityException)6 InternetAddress (javax.mail.internet.InternetAddress)6 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Address (javax.mail.Address)4 Bitmap (android.graphics.Bitmap)3 Attachment (i2p.bote.email.Attachment)3 EmailIdentity (i2p.bote.email.EmailIdentity)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 ContentAttachment (i2p.bote.android.util.ContentAttachment)2 Person (i2p.bote.android.util.Person)2 ContactsCompletionView (i2p.bote.android.widget.ContactsCompletionView)2 NoIdentityForSenderException (i2p.bote.email.NoIdentityForSenderException)2 EmailFolder (i2p.bote.folder.EmailFolder)2