use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class PgpMessageBuilder method mimeBuildEncryptedMessage.
private void mimeBuildEncryptedMessage(@NonNull Body encryptedBodyPart) throws MessagingException {
MimeMultipart multipartEncrypted = createMimeMultipart();
multipartEncrypted.setSubType("encrypted");
multipartEncrypted.addBodyPart(MimeBodyPart.create(new TextBody("Version: 1"), "application/pgp-encrypted"));
MimeBodyPart encryptedPart = MimeBodyPart.create(encryptedBodyPart, "application/octet-stream; name=\"encrypted.asc\"");
encryptedPart.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "inline; filename=\"encrypted.asc\"");
multipartEncrypted.addBodyPart(encryptedPart);
MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartEncrypted);
String contentType = String.format("multipart/encrypted; boundary=\"%s\";\r\n protocol=\"application/pgp-encrypted\"", multipartEncrypted.getBoundary());
currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageBuilder method buildText.
/**
* Build the {@link Body} that will contain the text of the message.
*
* <p>
* Draft messages are treated somewhat differently in that signatures are not appended and HTML
* separators between composed text and quoted text are not added.
* </p>
*
* @param isDraft
* If {@code true} we build a message that will be saved as a draft (as opposed to
* sent).
* @param simpleMessageFormat
* Specifies what type of message to build ({@code text/plain} vs. {@code text/html}).
*
* @return {@link TextBody} instance that contains the entered text and possibly the quoted
* original message.
*/
private TextBody buildText(boolean isDraft, SimpleMessageFormat simpleMessageFormat) {
TextBodyBuilder textBodyBuilder = new TextBodyBuilder(text);
/*
* Find out if we need to include the original message as quoted text.
*
* We include the quoted text in the body if the user didn't choose to
* hide it. We always include the quoted text when we're saving a draft.
* That's so the user is able to "un-hide" the quoted text if (s)he
* opens a saved draft.
*/
boolean includeQuotedText = (isDraft || quotedTextMode == QuotedTextMode.SHOW);
boolean isReplyAfterQuote = (quoteStyle == QuoteStyle.PREFIX && this.isReplyAfterQuote);
textBodyBuilder.setIncludeQuotedText(false);
if (includeQuotedText) {
if (simpleMessageFormat == SimpleMessageFormat.HTML && quotedHtmlContent != null) {
textBodyBuilder.setIncludeQuotedText(true);
textBodyBuilder.setQuotedTextHtml(quotedHtmlContent);
textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
}
if (simpleMessageFormat == SimpleMessageFormat.TEXT && quotedText.length() > 0) {
textBodyBuilder.setIncludeQuotedText(true);
textBodyBuilder.setQuotedText(quotedText);
textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
}
}
textBodyBuilder.setInsertSeparator(!isDraft);
boolean useSignature = (!isDraft && identity.getSignatureUse());
if (useSignature) {
textBodyBuilder.setAppendSignature(true);
textBodyBuilder.setSignature(signature);
textBodyBuilder.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
} else {
textBodyBuilder.setAppendSignature(false);
}
TextBody body;
if (simpleMessageFormat == SimpleMessageFormat.HTML) {
body = textBodyBuilder.buildTextHtml();
} else {
body = textBodyBuilder.buildTextPlain();
}
return body;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageHelper method isCompletePartAvailable.
public static boolean isCompletePartAvailable(Part part) {
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(part);
while (!partsToCheck.isEmpty()) {
Part currentPart = partsToCheck.pop();
Body body = currentPart.getBody();
boolean isBodyMissing = body == null;
if (isBodyMissing) {
return false;
}
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (BodyPart bodyPart : multipart.getBodyParts()) {
partsToCheck.push(bodyPart);
}
}
}
return true;
}
use of com.fsck.k9.mail.Body 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;
}
use of com.fsck.k9.mail.Body 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;
}
Aggregations