Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f58de59 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

compose: use MessageViewInfo.rootPart for content extraction

parent 99f65f33
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -75,19 +75,17 @@ public class QuotedMessageHelper {
        InsertableHtmlContent insertable = findInsertionPoints(messageBody);

        String sentDate = getSentDateText(resources, originalMessage);
        String fromAddress = Address.toString(originalMessage.getFrom());
        if (quoteStyle == QuoteStyle.PREFIX) {
            StringBuilder header = new StringBuilder(QUOTE_BUFFER_LENGTH);
            header.append("<div class=\"gmail_quote\">");
            if (sentDate.length() != 0) {
                header.append(HtmlConverter.textToHtmlFragment(String.format(
                        resources.getString(R.string.message_compose_reply_header_fmt_with_date),
                        sentDate,
                        Address.toString(originalMessage.getFrom()))
                        resources.getString(R.string.message_compose_reply_header_fmt_with_date), sentDate, fromAddress)
                ));
            } else {
                header.append(HtmlConverter.textToHtmlFragment(String.format(
                        resources.getString(R.string.message_compose_reply_header_fmt),
                        Address.toString(originalMessage.getFrom()))
                        resources.getString(R.string.message_compose_reply_header_fmt), fromAddress)
                ));
            }
            header.append("<blockquote class=\"gmail_quote\" " +
@@ -102,9 +100,9 @@ public class QuotedMessageHelper {
            StringBuilder header = new StringBuilder();
            header.append("<div style='font-size:10.0pt;font-family:\"Tahoma\",\"sans-serif\";padding:3.0pt 0in 0in 0in'>\r\n");
            header.append("<hr style='border:none;border-top:solid #E1E1E1 1.0pt'>\r\n"); // This gets converted into a horizontal line during html to text conversion.
            if (originalMessage.getFrom() != null && Address.toString(originalMessage.getFrom()).length() != 0) {
            if (originalMessage.getFrom() != null && fromAddress.length() != 0) {
                header.append("<b>").append(resources.getString(R.string.message_compose_quote_header_from)).append("</b> ")
                        .append(HtmlConverter.textToHtmlFragment(Address.toString(originalMessage.getFrom())))
                        .append(HtmlConverter.textToHtmlFragment(fromAddress))
                        .append("<br>\r\n");
            }
            if (sentDate.length() != 0) {
+7 −8
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class QuotedMessagePresenter {
            // Figure out which message format to use for the quoted text by looking if the source
            // message contains a text/html part. If it does, we use that.
            quotedTextFormat =
                    (MimeUtility.findFirstPartByMimeType(messageViewInfo.message, "text/html") == null) ?
                    (MimeUtility.findFirstPartByMimeType(messageViewInfo.rootPart, "text/html") == null) ?
                            SimpleMessageFormat.TEXT : SimpleMessageFormat.HTML;
        } else {
            quotedTextFormat = SimpleMessageFormat.HTML;
@@ -99,7 +99,7 @@ public class QuotedMessagePresenter {

        // Handle the original message in the reply
        // If we already have sourceMessageBody, use that.  It's pre-populated if we've got crypto going on.
        String content = QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.message, quotedTextFormat);
        String content = QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.rootPart, quotedTextFormat);

        if (quotedTextFormat == SimpleMessageFormat.HTML) {
            // Strip signature.
@@ -118,7 +118,7 @@ public class QuotedMessagePresenter {

            // TODO: Also strip the signature from the text/plain part
            view.setQuotedText(QuotedMessageHelper.quoteOriginalTextMessage(resources, messageViewInfo.message,
                    QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.message, SimpleMessageFormat.TEXT),
                    QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.rootPart, SimpleMessageFormat.TEXT),
                    quoteStyle, account.getQuotePrefix()));

        } else if (quotedTextFormat == SimpleMessageFormat.TEXT) {
@@ -283,11 +283,11 @@ public class QuotedMessagePresenter {
                }
            }
            if (bodyPlainOffset != null && bodyPlainLength != null) {
                processSourceMessageText(messageViewInfo.message, bodyPlainOffset, bodyPlainLength, false);
                processSourceMessageText(messageViewInfo.rootPart, bodyPlainOffset, bodyPlainLength, false);
            }
        } else if (messageFormat == MessageFormat.TEXT) {
            quotedTextFormat = SimpleMessageFormat.TEXT;
            processSourceMessageText(messageViewInfo.message, bodyOffset, bodyLength, true);
            processSourceMessageText(messageViewInfo.rootPart, bodyOffset, bodyLength, true);
        } else {
            Log.e(K9.LOG_TAG, "Unhandled message format.");
        }
@@ -305,14 +305,13 @@ public class QuotedMessagePresenter {
    /**
     * Pull out the parts of the now loaded source message and apply them to the new message
     * depending on the type of message being composed.
     * @param message Source message
     * @param bodyOffset Insertion point for reply.
     * @param bodyLength Length of reply.
     * @param viewMessageContent Update mMessageContentView or not.
     */
    private void processSourceMessageText(Message message, int bodyOffset, int bodyLength, boolean viewMessageContent)
    private void processSourceMessageText(Part rootMessagePart, int bodyOffset, int bodyLength, boolean viewMessageContent)
            throws MessagingException {
        Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
        Part textPart = MimeUtility.findFirstPartByMimeType(rootMessagePart, "text/plain");
        if (textPart == null) {
            return;
        }