Search in sources :

Example 16 with BodyPart

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

the class MessageDecryptVerifierTest method findSigned__withSimpleMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withSimpleMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", bodypart("text/plain"), 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 17 with BodyPart

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

the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubEncrypted__shouldReturnRoot.

@Test
public void findEncrypted__withMultipartMixedSubEncrypted__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("mixed", multipart("encrypted", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream"))));
    List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
    assertEquals(1, encryptedParts.size());
    assertSame(getPart(message, 0), encryptedParts.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 18 with BodyPart

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

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

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

Aggregations

BodyPart (com.fsck.k9.mail.BodyPart)49 Part (com.fsck.k9.mail.Part)38 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 Test (org.junit.Test)32 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 Multipart (com.fsck.k9.mail.Multipart)21 Body (com.fsck.k9.mail.Body)17 Message (com.fsck.k9.mail.Message)17 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)13 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)11 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)11 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 MessagingException (com.fsck.k9.mail.MessagingException)9 OutputStream (java.io.OutputStream)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)7 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)7 ArrayList (java.util.ArrayList)6 Stack (java.util.Stack)6 TextBody (com.fsck.k9.mail.internet.TextBody)5