use of com.fsck.k9.mail.internet.TextBody in project k-9 by k9mail.
the class MessageCryptoHelper method extractClearsignedTextReplacementPart.
private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) {
try {
String clearsignedText = MessageExtractor.getTextFromPart(part);
String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText);
if (replacementText == null) {
Timber.e("failed to extract clearsigned text for replacement part");
return NO_REPLACEMENT_PART;
}
return new MimeBodyPart(new TextBody(replacementText), "text/plain");
} catch (MessagingException e) {
Timber.e(e, "failed to create clearsigned text replacement part");
return NO_REPLACEMENT_PART;
}
}
use of com.fsck.k9.mail.internet.TextBody in project k-9 by k9mail.
the class MessageExtractor method getTextFromPart.
public static String getTextFromPart(Part part, long textSizeLimit) {
try {
if ((part != null) && (part.getBody() != null)) {
final Body body = part.getBody();
if (body instanceof TextBody) {
return ((TextBody) body).getRawText();
}
final String mimeType = part.getMimeType();
if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*") || part.isMimeType("application/pgp")) {
return getTextFromTextPart(part, body, mimeType, textSizeLimit);
} else {
throw new MessagingException("Provided non-text part: " + mimeType);
}
} else {
throw new MessagingException("Provided invalid part");
}
} catch (IOException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
} catch (MessagingException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
}
return null;
}
use of com.fsck.k9.mail.internet.TextBody in project k-9 by k9mail.
the class Multipart method setCharset.
public void setCharset(String charset) throws MessagingException {
if (mParts.isEmpty())
return;
BodyPart part = mParts.get(0);
Body body = part.getBody();
if (body instanceof TextBody) {
CharsetSupport.setCharset(charset, part);
((TextBody) body).setCharset(charset);
}
}
use of com.fsck.k9.mail.internet.TextBody in project k-9 by k9mail.
the class TextBodyBuilder method buildTextPlain.
/**
* Build the {@link Body} that will contain the text of the message.
*
* @return {@link TextBody} instance that contains the entered text and
* possibly the quoted original message.
*/
public TextBody buildTextPlain() {
// The length of the formatted version of the user-supplied text/reply
int composedMessageLength;
// The offset of the user-supplied text/reply in the final text body
int composedMessageOffset;
// Get the user-supplied text
String text = mMessageContent;
// Capture composed message length before we start attaching quoted parts and signatures.
composedMessageLength = text.length();
composedMessageOffset = 0;
// Do we have to modify an existing message to include our reply?
if (mIncludeQuotedText) {
String quotedText = getQuotedText();
if (mAppendSignature) {
// Append signature to the text/reply
if (mReplyAfterQuote || mSignatureBeforeQuotedText) {
text += getSignature();
}
}
if (mReplyAfterQuote) {
composedMessageOffset = quotedText.length() + "\r\n".length();
text = quotedText + "\r\n" + text;
} else {
text += "\r\n\r\n" + quotedText;
}
if (mAppendSignature) {
// Place signature immediately after the quoted text
if (!(mReplyAfterQuote || mSignatureBeforeQuotedText)) {
text += getSignature();
}
}
} else {
// There is no text to quote so simply append the signature if available
if (mAppendSignature) {
// Append signature to the text/reply
text += getSignature();
}
}
TextBody body = new TextBody(text);
body.setComposedMessageLength(composedMessageLength);
body.setComposedMessageOffset(composedMessageOffset);
return body;
}
use of com.fsck.k9.mail.internet.TextBody in project k-9 by k9mail.
the class TextBodyBuilder method buildTextHtml.
/**
* Build the {@link Body} that will contain the text of the message.
*
* @return {@link com.fsck.k9.mail.internet.TextBody} instance that contains the entered text and
* possibly the quoted original message.
*/
public TextBody buildTextHtml() {
// The length of the formatted version of the user-supplied text/reply
int composedMessageLength;
// The offset of the user-supplied text/reply in the final text body
int composedMessageOffset;
// Get the user-supplied text
String text = mMessageContent;
// Do we have to modify an existing message to include our reply?
if (mIncludeQuotedText) {
InsertableHtmlContent quotedHtmlContent = getQuotedTextHtml();
if (K9.isDebug()) {
Timber.d("insertable: %s", quotedHtmlContent.toDebugString());
}
if (mAppendSignature) {
// Append signature to the reply
if (mReplyAfterQuote || mSignatureBeforeQuotedText) {
text += getSignature();
}
}
// Convert the text to HTML
text = textToHtmlFragment(text);
/*
* Set the insertion location based upon our reply after quote
* setting. Additionally, add some extra separators between the
* composed message and quoted message depending on the quote
* location. We only add the extra separators when we're
* sending, that way when we load a draft, we don't have to know
* the length of the separators to remove them before editing.
*/
if (mReplyAfterQuote) {
quotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.AFTER_QUOTE);
if (mInsertSeparator) {
text = "<br clear=\"all\">" + text;
}
} else {
quotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE);
if (mInsertSeparator) {
text += "<br><br>";
}
}
if (mAppendSignature) {
// Place signature immediately after the quoted text
if (!(mReplyAfterQuote || mSignatureBeforeQuotedText)) {
quotedHtmlContent.insertIntoQuotedFooter(getSignatureHtml());
}
}
quotedHtmlContent.setUserContent(text);
// Save length of the body and its offset. This is used when thawing drafts.
composedMessageLength = text.length();
composedMessageOffset = quotedHtmlContent.getInsertionPoint();
text = quotedHtmlContent.toString();
} else {
// There is no text to quote so simply append the signature if available
if (mAppendSignature) {
text += getSignature();
}
// Convert the text to HTML
text = textToHtmlFragment(text);
//TODO: Wrap this in proper HTML tags
composedMessageLength = text.length();
composedMessageOffset = 0;
}
TextBody body = new TextBody(text);
body.setComposedMessageLength(composedMessageLength);
body.setComposedMessageOffset(composedMessageOffset);
return body;
}
Aggregations