Search in sources :

Example 36 with Part

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

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withEmptyMultipartMixed_shouldReturnNull.

@Test
public void findPrimaryCryptoPart_withEmptyMultipartMixed_shouldReturnNull() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    Message message = messageFromBody(multipart("mixed"));
    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 37 with Part

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

the class MessageDecryptVerifierTest method findSigned__withComplexMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withComplexMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", multipart("mixed", bodypart("text/plain"), bodypart("application/pdf")), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(message, messageCryptoAnnotations);
    assertEquals(1, signedParts.size());
    assertSame(message, signedParts.get(0));
}
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) Test(org.junit.Test)

Example 38 with Part

use of com.fsck.k9.mail.Part 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 39 with Part

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

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline.

@Test
public void findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    BodyPart pgpInlinePart = bodypart("text/plain", PGP_INLINE_DATA);
    Message message = messageFromBody(multipart("alternative", pgpInlinePart, bodypart("text/html")));
    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 40 with Part

use of com.fsck.k9.mail.Part 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

Part (com.fsck.k9.mail.Part)113 Test (org.junit.Test)92 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)78 BodyPart (com.fsck.k9.mail.BodyPart)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)39 Message (com.fsck.k9.mail.Message)32 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)30 Body (com.fsck.k9.mail.Body)29 Multipart (com.fsck.k9.mail.Multipart)27 ArrayList (java.util.ArrayList)27 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)20 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)19 MessagingException (com.fsck.k9.mail.MessagingException)16 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)16 TextBody (com.fsck.k9.mail.internet.TextBody)14 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)13 Viewable (com.fsck.k9.mail.internet.Viewable)10 Uri (android.net.Uri)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6