Search in sources :

Example 1 with MimeBodyPart

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

the class AttachmentResolverTest method buildCidMap__onTwoPart__shouldReturnBothUris.

@Test
public void buildCidMap__onTwoPart__shouldReturnBothUris() throws Exception {
    Multipart multipartBody = MimeMultipart.newInstance();
    Part multipartPart = new MimeBodyPart(multipartBody);
    BodyPart subPart1 = new MimeBodyPart();
    BodyPart subPart2 = new MimeBodyPart();
    multipartBody.addBodyPart(subPart1);
    multipartBody.addBodyPart(subPart2);
    subPart1.setHeader(MimeHeader.HEADER_CONTENT_ID, "cid-1");
    subPart2.setHeader(MimeHeader.HEADER_CONTENT_ID, "cid-2");
    when(attachmentInfoExtractor.extractAttachmentInfo(subPart1)).thenReturn(new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_1, false, subPart1, true));
    when(attachmentInfoExtractor.extractAttachmentInfo(subPart2)).thenReturn(new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_2, false, subPart2, true));
    Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
    assertEquals(2, result.size());
    assertEquals(ATTACHMENT_TEST_URI_1, result.get("cid-1"));
    assertEquals(ATTACHMENT_TEST_URI_2, result.get("cid-2"));
}
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)

Example 2 with MimeBodyPart

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

the class AttachmentResolverTest method buildCidMap__onMultipartWithNoParts__shouldReturnEmptyMap.

@Test
public void buildCidMap__onMultipartWithNoParts__shouldReturnEmptyMap() throws Exception {
    Multipart multipartBody = MimeMultipart.newInstance();
    Part multipartPart = new MimeBodyPart(multipartBody);
    Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
    assertTrue(result.isEmpty());
}
Also used : 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)

Example 3 with MimeBodyPart

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

the class MessageDecryptVerifierTest method findEncryptedPartsShouldReturnMultipleEncryptedParts.

@Test
public void findEncryptedPartsShouldReturnMultipleEncryptedParts() throws Exception {
    MimeMessage message = new MimeMessage();
    MimeMultipart multipartMixed = MimeMultipart.newInstance();
    multipartMixed.setSubType("mixed");
    MimeMessageHelper.setBody(message, multipartMixed);
    MimeMultipart multipartEncryptedOne = MimeMultipart.newInstance();
    multipartEncryptedOne.setSubType("encrypted");
    MimeBodyPart bodyPartOne = new MimeBodyPart(multipartEncryptedOne);
    setContentTypeWithProtocol(bodyPartOne, MIME_TYPE_MULTIPART_ENCRYPTED, PROTCOL_PGP_ENCRYPTED);
    multipartMixed.addBodyPart(bodyPartOne);
    MimeBodyPart bodyPartTwo = new MimeBodyPart(null, "text/plain");
    multipartMixed.addBodyPart(bodyPartTwo);
    MimeMultipart multipartEncryptedThree = MimeMultipart.newInstance();
    multipartEncryptedThree.setSubType("encrypted");
    MimeBodyPart bodyPartThree = new MimeBodyPart(multipartEncryptedThree);
    setContentTypeWithProtocol(bodyPartThree, MIME_TYPE_MULTIPART_ENCRYPTED, PROTCOL_PGP_ENCRYPTED);
    multipartMixed.addBodyPart(bodyPartThree);
    List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
    assertEquals(2, encryptedParts.size());
    assertSame(bodyPartOne, encryptedParts.get(0));
    assertSame(bodyPartThree, encryptedParts.get(1));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) 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) Test(org.junit.Test)

Example 4 with MimeBodyPart

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

the class MessageDecryptVerifierTest method multipart.

MimeBodyPart multipart(String type, BodyPart... subParts) throws MessagingException {
    MimeMultipart multiPart = MimeMultipart.newInstance();
    multiPart.setSubType(type);
    for (BodyPart subPart : subParts) {
        multiPart.addBodyPart(subPart);
    }
    return new MimeBodyPart(multiPart);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 5 with MimeBodyPart

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

the class LocalStoreTest method findPartById__withTwoTimesNestedLocalMessagePart.

@Test
public void findPartById__withTwoTimesNestedLocalMessagePart() throws Exception {
    LocalBodyPart searchRoot = new LocalBodyPart(null, null, 1L, -1L);
    LocalMimeMessage needlePart = new LocalMimeMessage(null, null, 123L);
    MimeMultipart mimeMultipartInner = new MimeMultipart("boundary");
    mimeMultipartInner.addBodyPart(new MimeBodyPart(needlePart));
    MimeMultipart mimeMultipart = new MimeMultipart("boundary");
    mimeMultipart.addBodyPart(new MimeBodyPart(mimeMultipartInner));
    searchRoot.setBody(mimeMultipart);
    Part part = LocalStore.findPartById(searchRoot, 123L);
    assertSame(needlePart, part);
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Aggregations

MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)42 Test (org.junit.Test)22 Part (com.fsck.k9.mail.Part)15 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)15 TextBody (com.fsck.k9.mail.internet.TextBody)11 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)11 BodyPart (com.fsck.k9.mail.BodyPart)9 MessagingException (com.fsck.k9.mail.MessagingException)7 Uri (android.net.Uri)5 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)5 PendingIntent (android.app.PendingIntent)4 Body (com.fsck.k9.mail.Body)4 Multipart (com.fsck.k9.mail.Multipart)4 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)4 Intent (android.content.Intent)3 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)3 InputStream (java.io.InputStream)3