Search in sources :

Example 1 with Alternative

use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.

the class MessageDecryptVerifier method findPrimaryPartInAlternative.

private static Part findPrimaryPartInAlternative(Part part) {
    Body body = part.getBody();
    if (part.isMimeType("multipart/alternative") && body instanceof Multipart) {
        Multipart multipart = (Multipart) body;
        if (multipart.getCount() == 0) {
            return null;
        }
        BodyPart firstBodyPart = multipart.getBodyPart(0);
        if (isPartPgpInlineEncryptedOrSigned(firstBodyPart)) {
            return firstBodyPart;
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) Body(com.fsck.k9.mail.Body)

Example 2 with Alternative

use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withMultipartMixedContainingMultipartAlternativeContainingPgpInline.

@Test
public void findPrimaryCryptoPart_withMultipartMixedContainingMultipartAlternativeContainingPgpInline() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    BodyPart pgpInlinePart = bodypart("text/plain", PGP_INLINE_DATA);
    Message message = messageFromBody(multipart("mixed", multipart("alternative", pgpInlinePart, bodypart("text/html")), bodypart("application/octet-stream")));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertSame(pgpInlinePart, cryptoPart);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Alternative

use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.

the class MigrationTest method migrateTextHtml.

@Test
public void migrateTextHtml() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMultipartAlternativeMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("9");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(8, msg.getId());
    Assert.assertEquals(9, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/alternative", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());
    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------060200010509000000040004", msgBody.getBoundary());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 4 with Alternative

use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withEmptyMultipartAlternative_shouldReturnNull.

@Test
public void findPrimaryCryptoPart_withEmptyMultipartAlternative_shouldReturnNull() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    Message message = messageFromBody(multipart("alternative"));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertNull(cryptoPart);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Alternative

use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withEmptyMultipartAlternativeInsideMultipartMixed_shouldReturnNull.

@Test
public void findPrimaryCryptoPart_withEmptyMultipartAlternativeInsideMultipartMixed_shouldReturnNull() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    Message message = messageFromBody(multipart("mixed", multipart("alternative")));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertNull(cryptoPart);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Part (com.fsck.k9.mail.Part)20 BodyPart (com.fsck.k9.mail.BodyPart)18 Test (org.junit.Test)18 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)9 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)9 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)9 ArrayList (java.util.ArrayList)9 Multipart (com.fsck.k9.mail.Multipart)8 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)7 Message (com.fsck.k9.mail.Message)6 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 Body (com.fsck.k9.mail.Body)5 Viewable (com.fsck.k9.mail.internet.Viewable)4 Alternative (com.fsck.k9.mail.internet.Viewable.Alternative)4 Html (com.fsck.k9.mail.internet.Viewable.Html)4 Text (com.fsck.k9.mail.internet.Viewable.Text)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 FetchProfile (com.fsck.k9.mail.FetchProfile)3 Flowed (com.fsck.k9.mail.internet.Viewable.Flowed)3 MessageHeader (com.fsck.k9.mail.internet.Viewable.MessageHeader)3