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

Commit 62361da1 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

compose: pass MessageViewInfo around instead of just the Message

parent a58ca462
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -1146,23 +1146,23 @@ public class MessageCompose extends K9Activity implements OnClickListener,
     * 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
     * @param messageViewInfo
     *         The source message used to populate the various text fields.
     */
    private void processSourceMessage(LocalMessage message) {
    private void processSourceMessage(MessageViewInfo messageViewInfo) {
        try {
            switch (mAction) {
                case REPLY:
                case REPLY_ALL: {
                    processMessageToReplyTo(message);
                    processMessageToReplyTo(messageViewInfo);
                    break;
                }
                case FORWARD: {
                    processMessageToForward(message);
                    processMessageToForward(messageViewInfo);
                    break;
                }
                case EDIT_DRAFT: {
                    processDraftMessage(message);
                    processDraftMessage(messageViewInfo);
                    break;
                }
                default: {
@@ -1184,7 +1184,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        updateMessageFormat();
    }

    private void processMessageToReplyTo(Message message) throws MessagingException {
    private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
        Message message = messageViewInfo.message;

        if (message.getSubject() != null) {
            final String subject = PREFIX.matcher(message.getSubject()).replaceFirst("");

@@ -1221,7 +1223,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }

        // Quote the message and setup the UI.
        quotedMessagePresenter.initFromReplyToMessage(message, mAction);
        quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, mAction);

        if (mAction == Action.REPLY || mAction == Action.REPLY_ALL) {
            Identity useIdentity = IdentityHelper.getRecipientIdentityFromMessage(mAccount, message);
@@ -1233,7 +1235,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,

    }

    private void processMessageToForward(Message message) throws MessagingException {
    private void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
        Message message = messageViewInfo.message;

        String subject = message.getSubject();
        if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
            mSubjectView.setText("Fwd: " + subject);
@@ -1255,7 +1259,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }

        // Quote the message and setup the UI.
        quotedMessagePresenter.processMessageToForward(message);
        quotedMessagePresenter.processMessageToForward(messageViewInfo);

        if (!mSourceMessageProcessed) {
            if (message.isSet(Flag.X_DOWNLOADED_PARTIAL) || !attachmentPresenter.loadAttachments(message, 0)) {
@@ -1264,7 +1268,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }
    }

    private void processDraftMessage(LocalMessage message) throws MessagingException {
    private void processDraftMessage(MessageViewInfo messageViewInfo) throws MessagingException {
        Message message = messageViewInfo.message;
        mDraftId = MessagingController.getInstance(getApplication()).getId(message);
        mSubjectView.setText(message.getSubject());

@@ -1301,7 +1306,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
            mSignatureChanged = true;
        } else {
            newIdentity.setSignatureUse(message.getFolder().getSignatureUse());
            if (message instanceof LocalMessage) {
                newIdentity.setSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
            }
            newIdentity.setSignature(mIdentity.getSignature());
        }

@@ -1341,7 +1348,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        updateSignature();
        updateFrom();

        quotedMessagePresenter.processDraftMessage(message, k9identity);
        quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
    }

    static class SendMessageTask extends AsyncTask<Void, Void, Void> {
@@ -1524,14 +1531,14 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }
    }

    public void loadLocalMessageForDisplay(LocalMessage message, Action action) {
    public void loadLocalMessageForDisplay(MessageViewInfo messageViewInfo, Action action) {
        // We check to see if we've previously processed the source message since this
        // could be called when switching from HTML to text replies. If that happens, we
        // only want to update the UI with quoted text (which picks the appropriate
        // part).
        if (mSourceMessageProcessed) {
            try {
                quotedMessagePresenter.populateUIWithQuotedMessage(message, true, action);
                quotedMessagePresenter.populateUIWithQuotedMessage(messageViewInfo, true, action);
            } catch (MessagingException e) {
                // Hm, if we couldn't populate the UI after source reprocessing, let's just delete it?
                quotedMessagePresenter.showOrHideQuotedText(QuotedTextMode.HIDE);
@@ -1539,7 +1546,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            }
            updateMessageFormat();
        } else {
            processSourceMessage(message);
            processSourceMessage(messageViewInfo);
            mSourceMessageProcessed = true;
        }
    }
@@ -1559,7 +1566,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        @Override
        public void onMessageViewInfoLoadFinished(LocalMessage localMessage, MessageViewInfo messageViewInfo) {
            mHandler.sendEmptyMessage(MSG_PROGRESS_OFF);
            loadLocalMessageForDisplay(localMessage, mAction);
            loadLocalMessageForDisplay(messageViewInfo, mAction);
        }

        @Override
+3 −3
Original line number Diff line number Diff line
@@ -191,12 +191,12 @@ public class RecipientPresenter implements PermissionPingCallback {
        outState.putBoolean(STATE_KEY_CRYPTO_ENABLE_PGP_INLINE, cryptoEnablePgpInline);
    }

    public void initFromDraftMessage(LocalMessage message) {
    public void initFromDraftMessage(Message message) {
        initRecipientsFromDraftMessage(message);
        initPgpInlineFromDraftMessage(message);
    }

    private void initRecipientsFromDraftMessage(LocalMessage message) {
    private void initRecipientsFromDraftMessage(Message message) {
        addToAddresses(message.getRecipients(RecipientType.TO));

        Address[] ccRecipients = message.getRecipients(RecipientType.CC);
@@ -206,7 +206,7 @@ public class RecipientPresenter implements PermissionPingCallback {
        addBccAddresses(bccRecipients);
    }

    private void initPgpInlineFromDraftMessage(LocalMessage message) {
    private void initPgpInlineFromDraftMessage(Message message) {
        cryptoEnablePgpInline = message.isSet(Flag.X_DRAFT_OPENPGP_INLINE);
    }

+17 −16
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.fsck.k9.mail.internet.MessageExtractor;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mailstore.AttachmentResolver;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.message.IdentityField;
import com.fsck.k9.message.InsertableHtmlContent;
import com.fsck.k9.message.MessageBuilder;
@@ -96,7 +97,7 @@ public class QuotedMessagePresenter {
     * @param showQuotedText
     *         {@code true} if the quoted text should be shown, {@code false} otherwise.
     */
    public void populateUIWithQuotedMessage(Message sourceMessage, boolean showQuotedText, Action action)
    public void populateUIWithQuotedMessage(MessageViewInfo messageViewInfo, boolean showQuotedText, Action action)
            throws MessagingException {
        MessageFormat origMessageFormat = account.getMessageFormat();

@@ -107,7 +108,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(sourceMessage, "text/html") == null) ?
                    (MimeUtility.findFirstPartByMimeType(messageViewInfo.message, "text/html") == null) ?
                            SimpleMessageFormat.TEXT : SimpleMessageFormat.HTML;
        } else {
            quotedTextFormat = SimpleMessageFormat.HTML;
@@ -118,7 +119,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 = sourceMessageBody != null ? sourceMessageBody :
                QuotedMessageHelper.getBodyTextFromMessage(sourceMessage, quotedTextFormat);
                QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.message, quotedTextFormat);

        if (quotedTextFormat == SimpleMessageFormat.HTML) {
            // Strip signature.
@@ -129,15 +130,15 @@ public class QuotedMessagePresenter {

            // Add the HTML reply header to the top of the content.
            quotedHtmlContent = QuotedMessageHelper.quoteOriginalHtmlMessage(
                    resources, sourceMessage, content, quoteStyle);
                    resources, messageViewInfo.message, content, quoteStyle);

            // Load the message with the reply header. TODO replace with MessageViewInfo data
            view.setQuotedHtml(quotedHtmlContent.getQuotedContent(),
                    AttachmentResolver.createFromPart(sourceMessage));

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

        } else if (quotedTextFormat == SimpleMessageFormat.TEXT) {
@@ -146,7 +147,7 @@ public class QuotedMessagePresenter {
            }

            view.setQuotedText(QuotedMessageHelper.quoteOriginalTextMessage(
                    resources, sourceMessage, content, quoteStyle, account.getQuotePrefix()));
                    resources, messageViewInfo.message, content, quoteStyle, account.getQuotePrefix()));
        }

        if (showQuotedText) {
@@ -186,17 +187,17 @@ public class QuotedMessagePresenter {
                (QuotedTextMode) savedInstanceState.getSerializable(STATE_KEY_QUOTED_TEXT_MODE));
    }

    public void processMessageToForward(Message message) throws MessagingException {
    public void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
        quoteStyle = QuoteStyle.HEADER;
        populateUIWithQuotedMessage(message, true, Action.FORWARD);
        populateUIWithQuotedMessage(messageViewInfo, true, Action.FORWARD);
    }

    public void initFromReplyToMessage(Message message, Action action)
    public void initFromReplyToMessage(MessageViewInfo messageViewInfo, Action action)
            throws MessagingException {
        populateUIWithQuotedMessage(message, account.isDefaultQuotedTextShown(), action);
        populateUIWithQuotedMessage(messageViewInfo, account.isDefaultQuotedTextShown(), action);
    }

    public void processDraftMessage(LocalMessage message, Map<IdentityField, String> k9identity)
    public void processDraftMessage(MessageViewInfo messageViewInfo, Map<IdentityField, String> k9identity)
            throws MessagingException {
        quoteStyle = k9identity.get(IdentityField.QUOTE_STYLE) != null
                ? QuoteStyle.valueOf(k9identity.get(IdentityField.QUOTE_STYLE))
@@ -255,7 +256,7 @@ public class QuotedMessagePresenter {
            // composition window. If that's the case, try and convert it to text to
            // match the behavior in text mode.
            view.setMessageContentCharacters(
                    QuotedMessageHelper.getBodyTextFromMessage(message, SimpleMessageFormat.TEXT));
                    QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.message, SimpleMessageFormat.TEXT));
            forcePlainText = true;

            showOrHideQuotedText(quotedMode);
@@ -263,7 +264,7 @@ public class QuotedMessagePresenter {
        }

        if (messageFormat == MessageFormat.HTML) {
            Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
            Part part = MimeUtility.findFirstPartByMimeType(messageViewInfo.message, "text/html");
            if (part != null) { // Shouldn't happen if we were the one who saved it.
                quotedTextFormat = SimpleMessageFormat.HTML;
                String text = MessageExtractor.getTextFromPart(part);
@@ -302,11 +303,11 @@ public class QuotedMessagePresenter {
                }
            }
            if (bodyPlainOffset != null && bodyPlainLength != null) {
                processSourceMessageText(message, bodyPlainOffset, bodyPlainLength, false);
                processSourceMessageText(messageViewInfo.message, bodyPlainOffset, bodyPlainLength, false);
            }
        } else if (messageFormat == MessageFormat.TEXT) {
            quotedTextFormat = SimpleMessageFormat.TEXT;
            processSourceMessageText(message, bodyOffset, bodyLength, true);
            processSourceMessageText(messageViewInfo.message, bodyOffset, bodyLength, true);
        } else {
            Log.e(K9.LOG_TAG, "Unhandled message format.");
        }