Search in sources :

Example 6 with Multipart

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

the class LocalFolder method addChildrenToStack.

private void addChildrenToStack(Stack<PartContainer> stack, Part part, long parentMessageId) {
    Body body = part.getBody();
    if (body instanceof Multipart) {
        Multipart multipart = (Multipart) body;
        for (int i = multipart.getCount() - 1; i >= 0; i--) {
            BodyPart childPart = multipart.getBodyPart(i);
            stack.push(new PartContainer(parentMessageId, childPart));
        }
    } else if (body instanceof Message) {
        Message innerMessage = (Message) body;
        stack.push(new PartContainer(parentMessageId, innerMessage));
    }
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) Multipart(com.fsck.k9.mail.Multipart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) Body(com.fsck.k9.mail.Body) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody)

Example 7 with Multipart

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

the class TextPartFinder method findFirstTextPart.

@Nullable
public Part findFirstTextPart(@NonNull Part part) {
    String mimeType = part.getMimeType();
    Body body = part.getBody();
    if (body instanceof Multipart) {
        Multipart multipart = (Multipart) body;
        if (isSameMimeType(mimeType, "multipart/alternative")) {
            return findTextPartInMultipartAlternative(multipart);
        } else {
            return findTextPartInMultipart(multipart);
        }
    } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) {
        return part;
    }
    return null;
}
Also used : Multipart(com.fsck.k9.mail.Multipart) Body(com.fsck.k9.mail.Body) Nullable(android.support.annotation.Nullable)

Example 8 with Multipart

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

the class TextPartFinder method findTextPartInMultipart.

private Part findTextPartInMultipart(Multipart multipart) {
    for (BodyPart bodyPart : multipart.getBodyParts()) {
        String mimeType = bodyPart.getMimeType();
        Body body = bodyPart.getBody();
        if (body instanceof Multipart) {
            Part candidatePart = findFirstTextPart(bodyPart);
            if (candidatePart != null) {
                return candidatePart;
            }
        } else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) {
            return bodyPart;
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Body(com.fsck.k9.mail.Body)

Example 9 with Multipart

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

the class MessageDecryptVerifier method getSignatureData.

public static byte[] getSignatureData(Part part) throws IOException, MessagingException {
    if (isPartMultipartSigned(part)) {
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart multi = (Multipart) body;
            BodyPart signatureBody = multi.getBodyPart(1);
            if (isSameMimeType(signatureBody.getMimeType(), APPLICATION_PGP_SIGNATURE)) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                signatureBody.getBody().writeTo(bos);
                return bos.toByteArray();
            }
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Body(com.fsck.k9.mail.Body)

Example 10 with Multipart

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

the class MessageDecryptVerifier method findPgpInlineParts.

public static List<Part> findPgpInlineParts(Part startPart) {
    List<Part> inlineParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (isPartPgpInlineEncryptedOrSigned(part)) {
            inlineParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return inlineParts;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) 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) ArrayList(java.util.ArrayList) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

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