From 94e5b88727b47ecae50a2f541bd2f30a24833197 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 20 Sep 2017 02:03:17 +0200 Subject: [PATCH] Don't default to prefer-encrypt mutual --- .../k9/activity/compose/ComposeCryptoStatus.java | 15 +++++++++++++-- .../k9/activity/compose/RecipientPresenter.java | 1 + .../fsck/k9/message/PgpMessageBuilderTest.java | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java index ec88c16f3..9711b139e 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/ComposeCryptoStatus.java @@ -25,6 +25,7 @@ public class ComposeCryptoStatus { private Long openPgpKeyId; private String[] recipientAddresses; private boolean enablePgpInline; + private boolean preferEncryptMutual; private CryptoMode cryptoMode; private RecipientAutocryptStatus recipientAutocryptStatus; @@ -83,7 +84,7 @@ public class ComposeCryptoStatus { case NO_CHOICE: if (recipientAutocryptStatusType == RecipientAutocryptStatusType.NO_RECIPIENTS) { return CryptoStatusDisplayType.NO_CHOICE_EMPTY; - } else if (recipientAutocryptStatusType.canEncrypt() && recipientAutocryptStatusType.isMutual()) { // TODO check own "mutual" status + } else if (canEncryptAndIsMutual()) { if (recipientAutocryptStatusType.isConfirmed()) { return CryptoStatusDisplayType.NO_CHOICE_MUTUAL_TRUSTED; } else { @@ -168,7 +169,7 @@ public class ComposeCryptoStatus { } boolean canEncryptAndIsMutual() { - return allRecipientsCanEncrypt() && recipientAutocryptStatus.type.isMutual(); + return allRecipientsCanEncrypt() && preferEncryptMutual && recipientAutocryptStatus.type.isMutual(); } boolean hasAutocryptPendingIntent() { @@ -186,6 +187,7 @@ public class ComposeCryptoStatus { private Long openPgpKeyId; private List recipients; private Boolean enablePgpInline; + private Boolean preferEncryptMutual; public ComposeCryptoStatusBuilder setCryptoProviderState(CryptoProviderState cryptoProviderState) { this.cryptoProviderState = cryptoProviderState; @@ -212,6 +214,11 @@ public class ComposeCryptoStatus { return this; } + public ComposeCryptoStatusBuilder setPreferEncryptMutual(boolean preferEncryptMutual) { + this.preferEncryptMutual = preferEncryptMutual; + return this; + } + public ComposeCryptoStatus build() { if (cryptoProviderState == null) { throw new AssertionError("cryptoProviderState must be set!"); @@ -225,6 +232,9 @@ public class ComposeCryptoStatus { if (enablePgpInline == null) { throw new AssertionError("enablePgpInline must be set!"); } + if (preferEncryptMutual == null) { + throw new AssertionError("preferEncryptMutual must be set!"); + } ArrayList recipientAddresses = new ArrayList<>(); for (Recipient recipient : recipients) { @@ -237,6 +247,7 @@ public class ComposeCryptoStatus { result.recipientAddresses = recipientAddresses.toArray(new String[0]); result.openPgpKeyId = openPgpKeyId; result.enablePgpInline = enablePgpInline; + result.preferEncryptMutual = preferEncryptMutual; return result; } } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java index 61924cb5d..07914d877 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java @@ -400,6 +400,7 @@ public class RecipientPresenter implements PermissionPingCallback { .setCryptoProviderState(cryptoProviderState) .setCryptoMode(currentCryptoMode) .setEnablePgpInline(cryptoEnablePgpInline) + .setPreferEncryptMutual(false) // TODO introduce a setting .setRecipients(getAllRecipients()) .setOpenPgpKeyId(accountCryptoKey) .build(); diff --git a/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java b/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java index 1736faa2c..13dc237ef 100644 --- a/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +++ b/k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java @@ -546,6 +546,7 @@ public class PgpMessageBuilderTest { private ComposeCryptoStatusBuilder createDefaultComposeCryptoStatusBuilder() { return new ComposeCryptoStatusBuilder() .setEnablePgpInline(false) + .setPreferEncryptMutual(false) .setOpenPgpKeyId(TEST_KEY_ID) .setRecipients(new ArrayList()) .setCryptoProviderState(CryptoProviderState.OK);