Search in sources :

Example 11 with Part

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

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

the class LocalFolder method saveMessagePart.

private long saveMessagePart(SQLiteDatabase db, PartContainer partContainer, long rootMessagePartId, int order) throws IOException, MessagingException {
    Part part = partContainer.part;
    ContentValues cv = new ContentValues();
    if (rootMessagePartId != -1) {
        cv.put("root", rootMessagePartId);
    }
    cv.put("parent", partContainer.parent);
    cv.put("seq", order);
    cv.put("server_extra", part.getServerExtra());
    return updateOrInsertMessagePart(db, cv, part, INVALID_MESSAGE_PART_ID);
}
Also used : ContentValues(android.content.ContentValues) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part)

Example 13 with Part

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

the class MessageFulltextCreator method extractText.

private String extractText(Message message) {
    Part textPart = textPartFinder.findFirstTextPart(message);
    if (textPart == null || hasEmptyBody(textPart)) {
        return null;
    }
    String text = MessageExtractor.getTextFromPart(textPart, MAX_CHARACTERS_CHECKED_FOR_FTS);
    String mimeType = textPart.getMimeType();
    if (!MimeUtility.isSameMimeType(mimeType, "text/html")) {
        return text;
    }
    return HtmlConverter.htmlToText(text);
}
Also used : Part(com.fsck.k9.mail.Part)

Example 14 with Part

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

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

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