use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageViewInfo method createWithErrorState.
public static MessageViewInfo createWithErrorState(Message message, boolean isMessageIncomplete) {
try {
Body emptyBody = new TextBody("");
Part emptyPart = new MimeBodyPart(emptyBody, "text/plain");
String subject = message.getSubject();
return new MessageViewInfo(message, isMessageIncomplete, emptyPart, subject, false, null, null, null, null, null, null);
} catch (MessagingException e) {
throw new AssertionError(e);
}
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageBuilder method addInlineAttachmentsToMessage.
private void addInlineAttachmentsToMessage(final MimeMultipart mp) throws MessagingException {
for (String cid : inlineAttachments.keySet()) {
Attachment attachment = inlineAttachments.get(cid);
if (attachment.getState() != Attachment.LoadingState.COMPLETE) {
continue;
}
Body body = new TempFileBody(attachment.getFileName());
MimeBodyPart bp = MimeBodyPart.create(body);
addContentType(bp, attachment.getContentType(), attachment.getName());
addContentDisposition(bp, "inline", attachment.getName(), attachment.getSize());
bp.addHeader(MimeHeader.HEADER_CONTENT_ID, cid);
mp.addBodyPart(bp);
}
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageBuilder method addAttachmentsToMessage.
/**
* Add attachments as parts into a MimeMultipart container.
* @param mp MimeMultipart container in which to insert parts.
* @throws MessagingException
*/
private void addAttachmentsToMessage(final MimeMultipart mp) throws MessagingException {
for (Attachment attachment : attachments) {
if (attachment.getState() != Attachment.LoadingState.COMPLETE) {
continue;
}
Body body = new TempFileBody(attachment.getFileName());
MimeBodyPart bp = MimeBodyPart.create(body);
addContentType(bp, attachment.getContentType(), attachment.getName());
addContentDisposition(bp, "attachment", attachment.getName(), attachment.getSize());
mp.addBodyPart(bp);
}
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class BodyTextExtractor method getBodyTextFromMessage.
/**
* Fetch the body text from a messagePart in the desired messagePart format. This method handles
* conversions between formats (html to text and vice versa) if necessary.
*/
@NonNull
public static String getBodyTextFromMessage(Part messagePart, SimpleMessageFormat format) {
Part part;
if (format == SimpleMessageFormat.HTML) {
// HTML takes precedence, then text.
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
if (part != null) {
Timber.d("getBodyTextFromMessage: HTML requested, HTML found.");
return getTextFromPartOrEmpty(part);
}
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
if (part != null) {
Timber.d("getBodyTextFromMessage: HTML requested, text found.");
String text = getTextFromPartOrEmpty(part);
return HtmlConverter.textToHtml(text);
}
} else if (format == SimpleMessageFormat.TEXT) {
// Text takes precedence, then html.
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
if (part != null) {
Timber.d("getBodyTextFromMessage: Text requested, text found.");
return getTextFromPartOrEmpty(part);
}
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
if (part != null) {
Timber.d("getBodyTextFromMessage: Text requested, HTML found.");
String text = getTextFromPartOrEmpty(part);
return HtmlConverter.htmlToText(text);
}
}
// If we had nothing interesting, return an empty string.
return "";
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageCryptoHelper method getMultipartSignedContentPartIfAvailable.
@Nullable
private static MimeBodyPart getMultipartSignedContentPartIfAvailable(Part part) {
MimeBodyPart replacementPart = NO_REPLACEMENT_PART;
Body body = part.getBody();
if (body instanceof MimeMultipart) {
MimeMultipart multipart = ((MimeMultipart) part.getBody());
if (multipart.getCount() >= 1) {
replacementPart = (MimeBodyPart) multipart.getBodyPart(0);
}
}
return replacementPart;
}
Aggregations