Search in sources :

Example 11 with Multipart

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

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

the class AttachmentResolver method buildCidToAttachmentUriMap.

@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
    HashMap<String, Uri> result = new HashMap<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(rootPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (Part bodyPart : multipart.getBodyParts()) {
                partsToCheck.push(bodyPart);
            }
        } else {
            try {
                String contentId = part.getContentId();
                if (contentId != null) {
                    AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
                    result.put(contentId, attachmentInfo.internalUri);
                }
            } catch (MessagingException e) {
                Timber.e(e, "Error extracting attachment info");
            }
        }
    }
    return Collections.unmodifiableMap(result);
}
Also used : Multipart(com.fsck.k9.mail.Multipart) HashMap(java.util.HashMap) MessagingException(com.fsck.k9.mail.MessagingException) Part(com.fsck.k9.mail.Part) Uri(android.net.Uri) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 13 with Multipart

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

the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted.

@Test
public void findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted() throws Exception {
    Message message = messageFromBody(multipart("mixed", multipart("encrypted", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")), bodypart("text/plain")));
    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 14 with Multipart

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

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

the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubTextAndSigned__shouldReturnSigned.

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

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