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

Commit 99f65f33 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

compose: hand cached decryption result back to OpenKeychain

parent e19fd5e5
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -113,8 +113,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
    public static final String ACTION_EDIT_DRAFT = "com.fsck.k9.intent.action.EDIT_DRAFT";

    public static final String EXTRA_ACCOUNT = "account";
    public static final String EXTRA_MESSAGE_BODY  = "messageBody";
    public static final String EXTRA_MESSAGE_REFERENCE = "message_reference";
    public static final String EXTRA_MESSAGE_DECRYPTION_RESULT  = "message_decryption_result";

    private static final String STATE_KEY_SOURCE_MESSAGE_PROCED =
        "com.fsck.k9.activity.MessageCompose.stateKeySourceMessageProced";
@@ -366,10 +366,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        EolConvertingEditText upperSignature = (EolConvertingEditText)findViewById(R.id.upper_signature);
        EolConvertingEditText lowerSignature = (EolConvertingEditText)findViewById(R.id.lower_signature);

        String sourceMessageBody = intent.getStringExtra(EXTRA_MESSAGE_BODY);

        QuotedMessageMvpView quotedMessageMvpView = new QuotedMessageMvpView(this);
        quotedMessagePresenter = new QuotedMessagePresenter(this, quotedMessageMvpView, mAccount, sourceMessageBody);
        quotedMessagePresenter = new QuotedMessagePresenter(this, quotedMessageMvpView, mAccount);
        attachmentPresenter = new AttachmentPresenter(getApplicationContext(), attachmentMvpView, getLoaderManager());

        mMessageContentView = (EolConvertingEditText)findViewById(R.id.message_content);
@@ -467,7 +465,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                messageLoaderHelper = new MessageLoaderHelper(this, getLoaderManager(), getFragmentManager(),
                        messageLoaderCallbacks);
                mHandler.sendEmptyMessage(MSG_PROGRESS_ON);
                messageLoaderHelper.asyncStartOrResumeLoadingMessage(mMessageReference);

                Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT);
                messageLoaderHelper.asyncStartOrResumeLoadingMessage(mMessageReference, cachedDecryptionResult);
            }

            if (mAction != Action.EDIT_DRAFT) {
@@ -1132,7 +1132,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            throw new IllegalStateException("tried to edit quoted message with no referenced message");
        }

        messageLoaderHelper.asyncStartOrResumeLoadingMessage(mMessageReference);
        messageLoaderHelper.asyncStartOrResumeLoadingMessage(mMessageReference, null);
    }

    /**
+19 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -53,7 +54,6 @@ import com.fsck.k9.search.SearchSpecification;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.search.SearchSpecification.SearchField;
import com.fsck.k9.ui.messageview.CryptoInfoDialog.OnClickShowCryptoKeyListener;
import com.fsck.k9.ui.messageview.MessageViewFragment;
import com.fsck.k9.ui.messageview.MessageViewFragment.MessageViewFragmentListener;
import com.fsck.k9.view.MessageHeader;
@@ -1210,17 +1210,32 @@ public class MessageList extends K9Activity implements MessageListFragmentListen

    @Override
    public void onForward(LocalMessage message) {
        MessageActions.actionForward(this, message, null);
        onForward(message, null);
    }

    @Override
    public void onForward(LocalMessage message, Parcelable decryptionResultForReply) {
        MessageActions.actionForward(this, message, decryptionResultForReply);
    }

    @Override
    public void onReply(LocalMessage message) {
        MessageActions.actionReply(this, message, false, null);
        onReply(message, null);
    }

    @Override
    public void onReply(LocalMessage message, Parcelable decryptionResultForReply) {
        MessageActions.actionReply(this, message, false, decryptionResultForReply);
    }

    @Override
    public void onReplyAll(LocalMessage message) {
        MessageActions.actionReply(this, message, true, null);
        onReplyAll(message, null);
    }

    @Override
    public void onReplyAll(LocalMessage message, Parcelable decryptionResultForReply) {
        MessageActions.actionReply(this, message, true, decryptionResultForReply);
    }

    @Override
+14 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.Loader;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
@@ -28,6 +29,7 @@ import com.fsck.k9.ui.crypto.MessageCryptoCallback;
import com.fsck.k9.ui.crypto.MessageCryptoHelper;
import com.fsck.k9.ui.message.LocalMessageExtractorLoader;
import com.fsck.k9.ui.message.LocalMessageLoader;
import org.openintents.openpgp.OpenPgpDecryptionResult;


/** This class is responsible for loading a message start to finish, and
@@ -83,6 +85,7 @@ public class MessageLoaderHelper {

    private LocalMessage localMessage;
    private MessageCryptoAnnotations messageCryptoAnnotations;
    private OpenPgpDecryptionResult cachedDecryptionResult;

    private MessageCryptoHelper messageCryptoHelper;

@@ -99,10 +102,18 @@ public class MessageLoaderHelper {
    // public interface

    @UiThread
    public void asyncStartOrResumeLoadingMessage(MessageReference messageReference) {
    public void asyncStartOrResumeLoadingMessage(MessageReference messageReference, Parcelable cachedDecryptionResult) {
        this.messageReference = messageReference;
        this.account = Preferences.getPreferences(context).getAccount(messageReference.getAccountUuid());

        if (cachedDecryptionResult != null) {
            if (cachedDecryptionResult instanceof OpenPgpDecryptionResult) {
                this.cachedDecryptionResult = (OpenPgpDecryptionResult) cachedDecryptionResult;
            } else {
                Log.e(K9.LOG_TAG, "Got decryption result of unknown type - ignoring");
            }
        }

        startOrResumeLocalMessageLoader();
    }

@@ -248,7 +259,8 @@ public class MessageLoaderHelper {
            messageCryptoHelper = new MessageCryptoHelper(context, account.getOpenPgpProvider());
            retainCryptoHelperFragment.setData(messageCryptoHelper);
        }
        messageCryptoHelper.asyncStartOrResumeProcessingMessage(localMessage, messageCryptoCallback);
        messageCryptoHelper.asyncStartOrResumeProcessingMessage(
                localMessage, messageCryptoCallback, cachedDecryptionResult);
    }

    private void cancelAndClearCryptoOperation() {
+7 −18
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.fsck.k9.activity.compose;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;

import com.fsck.k9.Account;
import com.fsck.k9.Preferences;
@@ -28,15 +29,11 @@ public class MessageActions {
    /**
     * Get intent for composing a new message as a reply to the given message. If replyAll is true
     * the function is reply all instead of simply reply.
     * @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
     */
    public static Intent getActionReplyIntent(
            Context context,
            LocalMessage message,
            boolean replyAll,
            String messageBody) {
            Context context, LocalMessage message, boolean replyAll, Parcelable decryptionResult) {
        Intent i = new Intent(context, MessageCompose.class);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_BODY, messageBody);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_DECRYPTION_RESULT, decryptionResult);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
        if (replyAll) {
            i.setAction(MessageCompose.ACTION_REPLY_ALL);
@@ -58,27 +55,19 @@ public class MessageActions {
    /**
     * Compose a new message as a reply to the given message. If replyAll is true the function
     * is reply all instead of simply reply.
     * @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
     */
    public static void actionReply(
            Context context,
            LocalMessage message,
            boolean replyAll,
            String messageBody) {
        context.startActivity(getActionReplyIntent(context, message, replyAll, messageBody));
            Context context, LocalMessage message, boolean replyAll, Parcelable decryptionResult) {
        context.startActivity(getActionReplyIntent(context, message, replyAll, decryptionResult));
    }

    /**
     * Compose a new message as a forward of the given message.
     * @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
     */
    public static void actionForward(
            Context context,
            LocalMessage message,
            String messageBody) {
    public static void actionForward(Context context, LocalMessage message, Parcelable decryptionResult) {
        Intent i = new Intent(context, MessageCompose.class);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_BODY, messageBody);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
        i.putExtra(MessageCompose.EXTRA_MESSAGE_DECRYPTION_RESULT, decryptionResult);
        i.setAction(MessageCompose.ACTION_FORWARD);
        context.startActivity(i);
    }
+3 −22
Original line number Diff line number Diff line
@@ -46,33 +46,17 @@ public class QuotedMessagePresenter {
    private QuoteStyle quoteStyle;
    private boolean forcePlainText;

    /**
     * "Original" message body
     *
     * <p>
     * The contents of this string will be used instead of the body of a referenced message when
     * replying to or forwarding a message.<br>
     * Right now this is only used when replying to a signed or encrypted message. It then contains
     * the stripped/decrypted body of that message.
     * </p>
     * <p><strong>Note:</strong>
     * When this field is not {@code null} we assume that the message we are composing right now
     * should be encrypted.
     * </p>
     */
    private String sourceMessageBody;

    private SimpleMessageFormat quotedTextFormat;
    private InsertableHtmlContent quotedHtmlContent;
    private Account account;


    public QuotedMessagePresenter(MessageCompose messageCompose, QuotedMessageMvpView quotedMessageMvpView,
            Account account, String sourceMessageBody) {
    public QuotedMessagePresenter(
            MessageCompose messageCompose, QuotedMessageMvpView quotedMessageMvpView, Account account) {
        this.messageCompose = messageCompose;
        this.resources = messageCompose.getResources();
        this.view = quotedMessageMvpView;
        this.sourceMessageBody = sourceMessageBody;
        onSwitchAccount(account);

        quotedTextMode = QuotedTextMode.NONE;
@@ -113,12 +97,9 @@ public class QuotedMessagePresenter {
            quotedTextFormat = SimpleMessageFormat.HTML;
        }

        // TODO -- I am assuming that sourceMessageBody will always be a text part.  Is this a safe assumption?

        // 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(messageViewInfo.message, quotedTextFormat);
        String content = QuotedMessageHelper.getBodyTextFromMessage(messageViewInfo.message, quotedTextFormat);

        if (quotedTextFormat == SimpleMessageFormat.HTML) {
            // Strip signature.
Loading