Search in sources :

Example 1 with SimpleMessageFormat

use of com.fsck.k9.message.SimpleMessageFormat in project k-9 by k9mail.

the class MessageCompose method updateMessageFormat.

public void updateMessageFormat() {
    MessageFormat origMessageFormat = account.getMessageFormat();
    SimpleMessageFormat messageFormat;
    if (origMessageFormat == MessageFormat.TEXT) {
        // The user wants to send text/plain messages. We don't override that choice under
        // any circumstances.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (quotedMessagePresenter.isForcePlainText() && quotedMessagePresenter.includeQuotedText()) {
        // Right now we send a text/plain-only message when the quoted text was edited, no
        // matter what the user selected for the message format.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (recipientPresenter.isForceTextMessageFormat()) {
        // Right now we only support PGP inline which doesn't play well with HTML. So force
        // plain text in those cases.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (origMessageFormat == MessageFormat.AUTO) {
        if (action == Action.COMPOSE || quotedMessagePresenter.isQuotedTextText() || !quotedMessagePresenter.includeQuotedText()) {
            // If the message format is set to "AUTO" we use text/plain whenever possible. That
            // is, when composing new messages and replying to or forwarding text/plain
            // messages.
            messageFormat = SimpleMessageFormat.TEXT;
        } else {
            messageFormat = SimpleMessageFormat.HTML;
        }
    } else {
        // In all other cases use HTML
        messageFormat = SimpleMessageFormat.HTML;
    }
    setCurrentMessageFormat(messageFormat);
}
Also used : SimpleMessageFormat(com.fsck.k9.message.SimpleMessageFormat) MessageFormat(com.fsck.k9.Account.MessageFormat) SimpleMessageFormat(com.fsck.k9.message.SimpleMessageFormat)

Example 2 with SimpleMessageFormat

use of com.fsck.k9.message.SimpleMessageFormat 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) {
    String messageText = text;
    TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText);
    /*
         * 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;
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody)

Example 3 with SimpleMessageFormat

use of com.fsck.k9.message.SimpleMessageFormat 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.
     */
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 MessageExtractor.getTextFromPart(part);
        }
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: HTML requested, text found.");
            String text = MessageExtractor.getTextFromPart(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 MessageExtractor.getTextFromPart(part);
        }
        part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
        if (part != null) {
            Timber.d("getBodyTextFromMessage: Text requested, HTML found.");
            String text = MessageExtractor.getTextFromPart(part);
            return HtmlConverter.htmlToText(text);
        }
    }
    // If we had nothing interesting, return an empty string.
    return "";
}
Also used : Part(com.fsck.k9.mail.Part)

Aggregations

MessageFormat (com.fsck.k9.Account.MessageFormat)1 Part (com.fsck.k9.mail.Part)1 TextBody (com.fsck.k9.mail.internet.TextBody)1 SimpleMessageFormat (com.fsck.k9.message.SimpleMessageFormat)1