Search in sources :

Example 21 with Part

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

the class LocalFolder method loadMessageParts.

private void loadMessageParts(SQLiteDatabase db, LocalMessage message) throws MessagingException {
    Map<Long, Part> partById = new HashMap<>();
    String[] columns = { // 0
    "id", // 1
    "type", // 2
    "parent", // 3
    "mime_type", // 4
    "decoded_body_size", // 5
    "display_name", // 6
    "header", // 7
    "encoding", // 8
    "charset", // 9
    "data_location", // 10
    "data", // 11
    "preamble", // 12
    "epilogue", // 13
    "boundary", // 14
    "content_id", // 15
    "server_extra" };
    Cursor cursor = db.query("message_parts", columns, "root = ?", new String[] { String.valueOf(message.getMessagePartId()) }, null, null, "seq");
    try {
        while (cursor.moveToNext()) {
            loadMessagePart(message, partById, cursor);
        }
    } finally {
        cursor.close();
    }
}
Also used : HashMap(java.util.HashMap) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Cursor(android.database.Cursor)

Example 22 with Part

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

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

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

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

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