Skip to content

Commit

Permalink
Merge pull request #1501 from k9mail/decrypted-reply
Browse files Browse the repository at this point in the history
Decrypted reply
  • Loading branch information
cketti authored Jul 24, 2016
2 parents a58ca46 + 19cd7b9 commit df761b9
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 148 deletions.
71 changes: 36 additions & 35 deletions k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -133,7 +133,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,

private static final int MSG_PROGRESS_ON = 1;
private static final int MSG_PROGRESS_OFF = 2;
private static final int MSG_SKIPPED_ATTACHMENTS = 3;
public static final int MSG_SAVED_DRAFT = 4;
private static final int MSG_DISCARDED_DRAFT = 5;

Expand Down Expand Up @@ -278,12 +277,6 @@ public void handleMessage(android.os.Message msg) {
case MSG_PROGRESS_OFF:
setProgressBarIndeterminateVisibility(false);
break;
case MSG_SKIPPED_ATTACHMENTS:
Toast.makeText(
MessageCompose.this,
getString(R.string.message_compose_attachments_skipped_toast),
Toast.LENGTH_LONG).show();
break;
case MSG_SAVED_DRAFT:
mDraftId = (Long) msg.obj;
Toast.makeText(
Expand Down Expand Up @@ -373,10 +366,8 @@ public void onCreate(Bundle savedInstanceState) {
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);
Expand Down Expand Up @@ -474,7 +465,9 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
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) {
Expand Down Expand Up @@ -1139,30 +1132,30 @@ public void loadQuotedTextForEdit() {
throw new IllegalStateException("tried to edit quoted message with no referenced message");
}

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

/**
* 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: {
Expand All @@ -1184,7 +1177,9 @@ private void processSourceMessage(LocalMessage message) {
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("");

Expand Down Expand Up @@ -1221,7 +1216,7 @@ private void processMessageToReplyTo(Message message) throws MessagingException
}

// 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);
Expand All @@ -1233,7 +1228,9 @@ private void processMessageToReplyTo(Message message) throws MessagingException

}

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);
Expand All @@ -1255,16 +1252,12 @@ private void processMessageToForward(Message message) throws MessagingException
}

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

if (!mSourceMessageProcessed) {
if (message.isSet(Flag.X_DOWNLOADED_PARTIAL) || !attachmentPresenter.loadAttachments(message, 0)) {
mHandler.sendEmptyMessage(MSG_SKIPPED_ATTACHMENTS);
}
}
quotedMessagePresenter.processMessageToForward(messageViewInfo);
attachmentPresenter.processMessageToForward(messageViewInfo);
}

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());

Expand Down Expand Up @@ -1301,7 +1294,9 @@ private void processDraftMessage(LocalMessage message) throws MessagingException
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());
}

Expand Down Expand Up @@ -1341,7 +1336,7 @@ private void processDraftMessage(LocalMessage message) throws MessagingException
updateSignature();
updateFrom();

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

static class SendMessageTask extends AsyncTask<Void, Void, Void> {
Expand Down Expand Up @@ -1524,22 +1519,22 @@ public void launchUserInteractionPendingIntent(PendingIntent pendingIntent, int
}
}

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);
Log.e(K9.LOG_TAG, "Could not re-process source message; deleting quoted text to be safe.", e);
}
updateMessageFormat();
} else {
processSourceMessage(message);
processSourceMessage(messageViewInfo);
mSourceMessageProcessed = true;
}
}
Expand All @@ -1559,7 +1554,7 @@ public void onMessageDataLoadFailed() {
@Override
public void onMessageViewInfoLoadFinished(LocalMessage localMessage, MessageViewInfo messageViewInfo) {
mHandler.sendEmptyMessage(MSG_PROGRESS_OFF);
loadLocalMessageForDisplay(localMessage, mAction);
loadLocalMessageForDisplay(messageViewInfo, mAction);
}

@Override
Expand Down Expand Up @@ -1731,6 +1726,12 @@ public void performSendAfterChecks() {
public void performSaveAfterChecks() {
MessageCompose.this.performSaveAfterChecks();
}

@Override
public void showMissingAttachmentsPartialMessageWarning() {
Toast.makeText(MessageCompose.this,
getString(R.string.message_compose_attachments_skipped_toast), Toast.LENGTH_LONG).show();
}
};

}
23 changes: 19 additions & 4 deletions k9mail/src/main/java/com/fsck/k9/activity/MessageList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -53,7 +54,6 @@
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;
Expand Down Expand Up @@ -1210,17 +1210,32 @@ public void onResendMessage(LocalMessage message) {

@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
Expand Down
16 changes: 14 additions & 2 deletions k9mail/src/main/java/com/fsck/k9/activity/MessageLoaderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -28,6 +29,7 @@
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
Expand Down Expand Up @@ -83,6 +85,7 @@ public class MessageLoaderHelper {

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

private MessageCryptoHelper messageCryptoHelper;

Expand All @@ -99,10 +102,18 @@ public MessageLoaderHelper(Context context, LoaderManager loaderManager, Fragmen
// 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();
}

Expand Down Expand Up @@ -248,7 +259,8 @@ private void startOrResumeCryptoOperation() {
messageCryptoHelper = new MessageCryptoHelper(context, account.getOpenPgpProvider());
retainCryptoHelperFragment.setData(messageCryptoHelper);
}
messageCryptoHelper.asyncStartOrResumeProcessingMessage(localMessage, messageCryptoCallback);
messageCryptoHelper.asyncStartOrResumeProcessingMessage(
localMessage, messageCryptoCallback, cachedDecryptionResult);
}

private void cancelAndClearCryptoOperation() {
Expand Down
Loading

0 comments on commit df761b9

Please sign in to comment.