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

Commit ac4840c9 authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

encrypt replies by default

parent a878a1c7
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.message.AutocryptStatusInteractor;
import com.fsck.k9.message.ComposePgpEnableByDefaultDecider;
import com.fsck.k9.message.ComposePgpInlineDecider;
import com.fsck.k9.message.IdentityField;
import com.fsck.k9.message.IdentityHeaderParser;
@@ -279,9 +280,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        RecipientMvpView recipientMvpView = new RecipientMvpView(this);
        ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
        ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider();
        recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(),
                recipientMvpView, account, composePgpInlineDecider, AutocryptStatusInteractor.getInstance(),
                new ReplyToParser(), this);
                recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider,
                AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this);
        recipientPresenter.asyncUpdateCryptoStatus();


+7 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.message.AutocryptStatusInteractor;
import com.fsck.k9.message.AutocryptStatusInteractor.RecipientAutocryptStatus;
import com.fsck.k9.message.ComposePgpEnableByDefaultDecider;
import com.fsck.k9.message.ComposePgpInlineDecider;
import com.fsck.k9.message.MessageBuilder;
import com.fsck.k9.message.PgpMessageBuilder;
@@ -71,6 +72,7 @@ public class RecipientPresenter implements PermissionPingCallback {
    // transient state, which is either obtained during construction and initialization, or cached
    private final Context context;
    private final RecipientMvpView recipientMvpView;
    private final ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider;
    private final ComposePgpInlineDecider composePgpInlineDecider;
    private final AutocryptStatusInteractor autocryptStatusInteractor;
    private final RecipientsChangedListener listener;
@@ -87,19 +89,20 @@ public class RecipientPresenter implements PermissionPingCallback {

    // persistent state, saved during onSaveInstanceState
    private RecipientType lastFocusedType = RecipientType.TO;
    // TODO initialize cryptoMode to other values under some circumstances, e.g. if we reply to an encrypted e-mail
    private CryptoMode currentCryptoMode = CryptoMode.NO_CHOICE;
    private boolean cryptoEnablePgpInline = false;


    public RecipientPresenter(Context context, LoaderManager loaderManager,
            RecipientMvpView recipientMvpView, Account account, ComposePgpInlineDecider composePgpInlineDecider,
            ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider,
            AutocryptStatusInteractor autocryptStatusInteractor,
            ReplyToParser replyToParser, RecipientsChangedListener recipientsChangedListener) {
        this.recipientMvpView = recipientMvpView;
        this.context = context;
        this.autocryptStatusInteractor = autocryptStatusInteractor;
        this.composePgpInlineDecider = composePgpInlineDecider;
        this.composePgpEnableByDefaultDecider = composePgpEnableByDefaultDecider;
        this.replyToParser = replyToParser;
        this.listener = recipientsChangedListener;

@@ -170,6 +173,9 @@ public class RecipientPresenter implements PermissionPingCallback {
        if (shouldSendAsPgpInline) {
            cryptoEnablePgpInline = true;
        }

        boolean shouldEnablePgpByDefault = composePgpEnableByDefaultDecider.shouldEncryptByDefault(message);
        currentCryptoMode = shouldEnablePgpByDefault ? CryptoMode.CHOICE_ENABLED : CryptoMode.NO_CHOICE;
    }

    public void initFromTrustIdAction(String trustId) {
@@ -432,9 +438,6 @@ public class RecipientPresenter implements PermissionPingCallback {
        recipientMvpView.setRecipientTokensShowCryptoEnabled(cachedCryptoStatus.isEncryptionEnabled());

        CryptoStatusDisplayType cryptoStatusDisplayType = cachedCryptoStatus.getCryptoStatusDisplayType();
        if (cryptoStatusDisplayType == CryptoStatusDisplayType.ERROR) {
            recipientMvpView.showErrorOpenPgpRetrieveStatus();
        }
        recipientMvpView.showCryptoStatus(cryptoStatusDisplayType);
        recipientMvpView.showCryptoSpecialMode(cachedCryptoStatus.getCryptoSpecialModeDisplayType());
    }
+20 −0
Original line number Diff line number Diff line
package com.fsck.k9.message;


import java.util.List;

import com.fsck.k9.crypto.MessageDecryptVerifier;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Part;


public class ComposePgpEnableByDefaultDecider {
    public boolean shouldEncryptByDefault(Message localMessage) {
        return messageIsEncrypted(localMessage);
    }

    private boolean messageIsEncrypted(Message localMessage) {
        List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(localMessage);
        return !encryptedParts.isEmpty();
    }
}