Search in sources :

Example 66 with Multipart

use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.

the class MigrationTest method migrateHtmlWithRelatedMessage.

@Test
public void migrateHtmlWithRelatedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertHtmlWithRelatedMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("10");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(9, msg.getId());
    Assert.assertEquals(11, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(1, msg.getAttachmentCount());
    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------050707070308090509030605", msgBody.getBoundary());
    Multipart multipartAlternativePart = (Multipart) msgBody.getBodyPart(0).getBody();
    BodyPart htmlPart = multipartAlternativePart.getBodyPart(1);
    String msgTextContent = MessageExtractor.getTextFromPart(htmlPart);
    Assert.assertNotNull(msgTextContent);
    Assert.assertTrue(msgTextContent.contains("cid:part1.07090108.09020601@example.org"));
    Assert.assertEquals("image/jpeg", msgBody.getBodyPart(1).getMimeType());
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 67 with Multipart

use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.

the class MigrationTest method migrateMixedWithAttachments.

@Test
public void migrateMixedWithAttachments() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMixedWithAttachments(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("4");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(3, msg.getId());
    Assert.assertEquals(8, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals("multipart/mixed", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
    Assert.assertEquals("----5D6OUTIYLNN2X63O0R2M0V53TOUAQP", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
    Assert.assertEquals(2, msg.getAttachmentCount());
    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(3, body.getCount());
    Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
    LocalBodyPart attachmentPart = (LocalBodyPart) body.getBodyPart(1);
    Assert.assertEquals("image/png", attachmentPart.getMimeType());
    Assert.assertEquals("2", attachmentPart.getServerExtra());
    Assert.assertEquals("attachment", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), null));
    Assert.assertEquals("k9small.png", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "filename"));
    Assert.assertEquals("2250", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "size"));
    FileBackedBody attachmentBody = (FileBackedBody) attachmentPart.getBody();
    Assert.assertEquals(2250, attachmentBody.getSize());
    Assert.assertEquals(MimeUtil.ENC_BINARY, attachmentBody.getEncoding());
    Assert.assertEquals("application/whatevs", body.getBodyPart(2).getMimeType());
    Assert.assertNull(body.getBodyPart(2).getBody());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 68 with Multipart

use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.

the class MigrationTest method migratePgpMimeSignedMessage.

@Test
public void migratePgpMimeSignedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpMimeSignedMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("5");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(4, msg.getId());
    Assert.assertEquals(8, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/mixed", msg.getMimeType());
    Assert.assertEquals(2, msg.getAttachmentCount());
    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(3, body.getCount());
    Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
    Assert.assertEquals("image/png", body.getBodyPart(1).getMimeType());
    Assert.assertEquals("application/pgp-signature", body.getBodyPart(2).getMimeType());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 69 with Multipart

use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.

the class MigrationTest method migratePgpMimeEncryptedMessage.

@Test
public void migratePgpMimeEncryptedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpMimeEncryptedMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("6");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(5, msg.getId());
    Assert.assertEquals(13, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/encrypted", msg.getMimeType());
    Assert.assertEquals(2, msg.getAttachmentCount());
    Multipart body = (Multipart) msg.getBody();
    Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
    Assert.assertEquals("application/pgp-encrypted", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "protocol"));
    Assert.assertEquals("UoPmpPX/dBe4BELn", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
    Assert.assertEquals("UoPmpPX/dBe4BELn", body.getBoundary());
    Assert.assertEquals(2, body.getCount());
    Assert.assertEquals("application/pgp-encrypted", body.getBodyPart(0).getMimeType());
    Assert.assertEquals("application/octet-stream", body.getBodyPart(1).getMimeType());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 70 with Multipart

use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.

the class AttachmentResolverTest method buildCidMap__onMultipartWithEmptyBodyPart__shouldReturnEmptyMap.

@Test
public void buildCidMap__onMultipartWithEmptyBodyPart__shouldReturnEmptyMap() throws Exception {
    Multipart multipartBody = MimeMultipart.newInstance();
    BodyPart bodyPart = spy(new MimeBodyPart());
    Part multipartPart = new MimeBodyPart(multipartBody);
    multipartBody.addBodyPart(bodyPart);
    Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
    verify(bodyPart).getContentId();
    assertTrue(result.isEmpty());
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

BodyPart (com.fsck.k9.mail.BodyPart)57 Part (com.fsck.k9.mail.Part)51 Test (org.junit.Test)47 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)38 Multipart (com.fsck.k9.mail.Multipart)33 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)29 Message (com.fsck.k9.mail.Message)25 Body (com.fsck.k9.mail.Body)22 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)21 ArrayList (java.util.ArrayList)14 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)13 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)13 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 TextBody (com.fsck.k9.mail.internet.TextBody)7 MessagingException (com.fsck.k9.mail.MessagingException)6 Stack (java.util.Stack)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)5 FetchProfile (com.fsck.k9.mail.FetchProfile)5 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)5