Loading app/core/src/main/java/com/fsck/k9/autocrypt/AutocryptDraftStateHeaderParser.kt +0 −4 Original line number Diff line number Diff line Loading @@ -39,8 +39,4 @@ class AutocryptDraftStateHeaderParser internal constructor() { } return false } companion object { val instance = AutocryptDraftStateHeaderParser() } } app/core/src/main/java/com/fsck/k9/autocrypt/KoinModule.kt +1 −0 Original line number Diff line number Diff line Loading @@ -4,4 +4,5 @@ import org.koin.dsl.module.applicationContext val autocryptModule = applicationContext { bean { AutocryptTransferMessageCreator(get()) } bean { AutocryptDraftStateHeaderParser() } } No newline at end of file app/ui/src/main/java/com/fsck/k9/activity/MessageCompose.java +6 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.widget.Toast; import com.fsck.k9.Account; import com.fsck.k9.Account.MessageFormat; import com.fsck.k9.DI; import com.fsck.k9.Identity; import com.fsck.k9.K9; import com.fsck.k9.Preferences; Loading @@ -63,6 +64,7 @@ import com.fsck.k9.activity.compose.RecipientMvpView; import com.fsck.k9.activity.compose.RecipientPresenter; import com.fsck.k9.activity.compose.SaveMessageTask; import com.fsck.k9.activity.misc.Attachment; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.controller.MessageReference; import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingListener; Loading Loading @@ -284,11 +286,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, RecipientMvpView recipientMvpView = new RecipientMvpView(this); ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider(); ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider(); OpenPgpApiManager openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), this); recipientPresenter = new RecipientPresenter(getApplicationContext(), getSupportLoaderManager(), openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider, AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this ); AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this, DI.get(AutocryptDraftStateHeaderParser.class)); recipientPresenter.asyncUpdateCryptoStatus(); Loading Loading @@ -1302,7 +1305,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, draftId = MessagingController.getInstance(getApplication()).getId(message); subjectView.setText(messageViewInfo.subject); recipientPresenter.initFromDraftMessage(message); recipientPresenter.initFromDraftMessage(message, messageViewInfo.rootPart); // Read In-Reply-To header from draft final String[] inReplyTo = message.getHeader("In-Reply-To"); Loading app/ui/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +36 −9 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState; import com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder; import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.autocrypt.AutocryptDraftStateHeader; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.MailTo; import com.fsck.k9.helper.ReplyToParser; Loading @@ -35,6 +37,7 @@ import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Part; import com.fsck.k9.message.AutocryptStatusInteractor; import com.fsck.k9.message.AutocryptStatusInteractor.RecipientAutocryptStatus; import com.fsck.k9.message.ComposePgpEnableByDefaultDecider; Loading Loading @@ -73,12 +76,13 @@ public class RecipientPresenter { private final ComposePgpInlineDecider composePgpInlineDecider; private final AutocryptStatusInteractor autocryptStatusInteractor; private final RecipientsChangedListener listener; private final OpenPgpApiManager openPgpApiManager; private final AutocryptDraftStateHeaderParser draftStateHeaderParser; private ReplyToParser replyToParser; private Account account; private Boolean hasContactPicker; @Nullable private ComposeCryptoStatus cachedCryptoStatus; private OpenPgpApiManager openPgpApiManager; // persistent state, saved during onSaveInstanceState Loading @@ -93,7 +97,8 @@ public class RecipientPresenter { ComposePgpInlineDecider composePgpInlineDecider, ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider, AutocryptStatusInteractor autocryptStatusInteractor, ReplyToParser replyToParser, RecipientsChangedListener recipientsChangedListener) { ReplyToParser replyToParser, RecipientsChangedListener recipientsChangedListener, AutocryptDraftStateHeaderParser draftStateHeaderParser) { this.recipientMvpView = recipientMvpView; this.context = context; this.autocryptStatusInteractor = autocryptStatusInteractor; Loading @@ -102,6 +107,7 @@ public class RecipientPresenter { this.replyToParser = replyToParser; this.listener = recipientsChangedListener; this.openPgpApiManager = openPgpApiManager; this.draftStateHeaderParser = draftStateHeaderParser; recipientMvpView.setPresenter(this); recipientMvpView.setLoaderManager(loaderManager); Loading Loading @@ -220,11 +226,24 @@ public class RecipientPresenter { outState.putBoolean(STATE_KEY_CRYPTO_ENABLE_PGP_INLINE, cryptoEnablePgpInline); } public void initFromDraftMessage(Message message) { public void initFromDraftMessage(Message message, Part rootPart) { initRecipientsFromDraftMessage(message); initEncryptionStatus(message); String[] draftStateHeader = rootPart.getHeader(AutocryptDraftStateHeader.AUTOCRYPT_DRAFT_STATE_HEADER); if (draftStateHeader.length == 1) { initEncryptionStateFromDraftStateHeader(draftStateHeader[0]); } else { initPgpInlineFromDraftMessage(message); } } private void initEncryptionStateFromDraftStateHeader(String headerValue) { AutocryptDraftStateHeader autocryptDraftStateHeader = draftStateHeaderParser.parseAutocryptDraftStateHeader(headerValue); if (autocryptDraftStateHeader != null) { initEncryptionStateFromDraftStateHeader(autocryptDraftStateHeader); } } private void initRecipientsFromDraftMessage(Message message) { addToAddresses(message.getRecipients(RecipientType.TO)); Loading @@ -236,10 +255,18 @@ public class RecipientPresenter { addBccAddresses(bccRecipients); } private void initEncryptionStatus(Message message) { boolean isEncryptedDraft = composePgpEnableByDefaultDecider.shouldEncryptByDefault(message); if (isEncryptedDraft) { currentCryptoMode = CryptoMode.CHOICE_ENABLED; private void initEncryptionStateFromDraftStateHeader(AutocryptDraftStateHeader draftState) { cryptoEnablePgpInline = draftState.isPgpInline(); isReplyToEncryptedMessage = draftState.isReply(); if (!draftState.isByChoice()) { // TODO if it's not by choice, we're going with our defaults. should we do something here if those differ? return; } if (draftState.isSignOnly()) { currentCryptoMode = CryptoMode.SIGN_ONLY; } else { currentCryptoMode = draftState.isEncrypt() ? CryptoMode.CHOICE_ENABLED : CryptoMode.CHOICE_DISABLED; } } Loading app/ui/src/test/java/com/fsck/k9/activity/compose/RecipientPresenterTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ import android.content.Context; import android.support.v4.app.LoaderManager; import com.fsck.k9.Account; import com.fsck.k9.DI; import com.fsck.k9.K9RobolectricTest; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.helper.ReplyToParser; import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses; import com.fsck.k9.mail.Address; Loading Loading @@ -90,7 +92,8 @@ public class RecipientPresenterTest extends K9RobolectricTest { recipientPresenter = new RecipientPresenter( context, loaderManager, openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider, autocryptStatusInteractor, replyToParser, listener composePgpEnableByDefaultDecider, autocryptStatusInteractor, replyToParser, listener, DI.get(AutocryptDraftStateHeaderParser.class) ); ArgumentCaptor<OpenPgpApiManagerCallback> callbackCaptor = ArgumentCaptor.forClass(OpenPgpApiManagerCallback.class); Loading Loading
app/core/src/main/java/com/fsck/k9/autocrypt/AutocryptDraftStateHeaderParser.kt +0 −4 Original line number Diff line number Diff line Loading @@ -39,8 +39,4 @@ class AutocryptDraftStateHeaderParser internal constructor() { } return false } companion object { val instance = AutocryptDraftStateHeaderParser() } }
app/core/src/main/java/com/fsck/k9/autocrypt/KoinModule.kt +1 −0 Original line number Diff line number Diff line Loading @@ -4,4 +4,5 @@ import org.koin.dsl.module.applicationContext val autocryptModule = applicationContext { bean { AutocryptTransferMessageCreator(get()) } bean { AutocryptDraftStateHeaderParser() } } No newline at end of file
app/ui/src/main/java/com/fsck/k9/activity/MessageCompose.java +6 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.widget.Toast; import com.fsck.k9.Account; import com.fsck.k9.Account.MessageFormat; import com.fsck.k9.DI; import com.fsck.k9.Identity; import com.fsck.k9.K9; import com.fsck.k9.Preferences; Loading @@ -63,6 +64,7 @@ import com.fsck.k9.activity.compose.RecipientMvpView; import com.fsck.k9.activity.compose.RecipientPresenter; import com.fsck.k9.activity.compose.SaveMessageTask; import com.fsck.k9.activity.misc.Attachment; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.controller.MessageReference; import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingListener; Loading Loading @@ -284,11 +286,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, RecipientMvpView recipientMvpView = new RecipientMvpView(this); ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider(); ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider(); OpenPgpApiManager openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), this); recipientPresenter = new RecipientPresenter(getApplicationContext(), getSupportLoaderManager(), openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider, AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this ); AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this, DI.get(AutocryptDraftStateHeaderParser.class)); recipientPresenter.asyncUpdateCryptoStatus(); Loading Loading @@ -1302,7 +1305,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, draftId = MessagingController.getInstance(getApplication()).getId(message); subjectView.setText(messageViewInfo.subject); recipientPresenter.initFromDraftMessage(message); recipientPresenter.initFromDraftMessage(message, messageViewInfo.rootPart); // Read In-Reply-To header from draft final String[] inReplyTo = message.getHeader("In-Reply-To"); Loading
app/ui/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +36 −9 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState; import com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder; import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.autocrypt.AutocryptDraftStateHeader; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.MailTo; import com.fsck.k9.helper.ReplyToParser; Loading @@ -35,6 +37,7 @@ import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Part; import com.fsck.k9.message.AutocryptStatusInteractor; import com.fsck.k9.message.AutocryptStatusInteractor.RecipientAutocryptStatus; import com.fsck.k9.message.ComposePgpEnableByDefaultDecider; Loading Loading @@ -73,12 +76,13 @@ public class RecipientPresenter { private final ComposePgpInlineDecider composePgpInlineDecider; private final AutocryptStatusInteractor autocryptStatusInteractor; private final RecipientsChangedListener listener; private final OpenPgpApiManager openPgpApiManager; private final AutocryptDraftStateHeaderParser draftStateHeaderParser; private ReplyToParser replyToParser; private Account account; private Boolean hasContactPicker; @Nullable private ComposeCryptoStatus cachedCryptoStatus; private OpenPgpApiManager openPgpApiManager; // persistent state, saved during onSaveInstanceState Loading @@ -93,7 +97,8 @@ public class RecipientPresenter { ComposePgpInlineDecider composePgpInlineDecider, ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider, AutocryptStatusInteractor autocryptStatusInteractor, ReplyToParser replyToParser, RecipientsChangedListener recipientsChangedListener) { ReplyToParser replyToParser, RecipientsChangedListener recipientsChangedListener, AutocryptDraftStateHeaderParser draftStateHeaderParser) { this.recipientMvpView = recipientMvpView; this.context = context; this.autocryptStatusInteractor = autocryptStatusInteractor; Loading @@ -102,6 +107,7 @@ public class RecipientPresenter { this.replyToParser = replyToParser; this.listener = recipientsChangedListener; this.openPgpApiManager = openPgpApiManager; this.draftStateHeaderParser = draftStateHeaderParser; recipientMvpView.setPresenter(this); recipientMvpView.setLoaderManager(loaderManager); Loading Loading @@ -220,11 +226,24 @@ public class RecipientPresenter { outState.putBoolean(STATE_KEY_CRYPTO_ENABLE_PGP_INLINE, cryptoEnablePgpInline); } public void initFromDraftMessage(Message message) { public void initFromDraftMessage(Message message, Part rootPart) { initRecipientsFromDraftMessage(message); initEncryptionStatus(message); String[] draftStateHeader = rootPart.getHeader(AutocryptDraftStateHeader.AUTOCRYPT_DRAFT_STATE_HEADER); if (draftStateHeader.length == 1) { initEncryptionStateFromDraftStateHeader(draftStateHeader[0]); } else { initPgpInlineFromDraftMessage(message); } } private void initEncryptionStateFromDraftStateHeader(String headerValue) { AutocryptDraftStateHeader autocryptDraftStateHeader = draftStateHeaderParser.parseAutocryptDraftStateHeader(headerValue); if (autocryptDraftStateHeader != null) { initEncryptionStateFromDraftStateHeader(autocryptDraftStateHeader); } } private void initRecipientsFromDraftMessage(Message message) { addToAddresses(message.getRecipients(RecipientType.TO)); Loading @@ -236,10 +255,18 @@ public class RecipientPresenter { addBccAddresses(bccRecipients); } private void initEncryptionStatus(Message message) { boolean isEncryptedDraft = composePgpEnableByDefaultDecider.shouldEncryptByDefault(message); if (isEncryptedDraft) { currentCryptoMode = CryptoMode.CHOICE_ENABLED; private void initEncryptionStateFromDraftStateHeader(AutocryptDraftStateHeader draftState) { cryptoEnablePgpInline = draftState.isPgpInline(); isReplyToEncryptedMessage = draftState.isReply(); if (!draftState.isByChoice()) { // TODO if it's not by choice, we're going with our defaults. should we do something here if those differ? return; } if (draftState.isSignOnly()) { currentCryptoMode = CryptoMode.SIGN_ONLY; } else { currentCryptoMode = draftState.isEncrypt() ? CryptoMode.CHOICE_ENABLED : CryptoMode.CHOICE_DISABLED; } } Loading
app/ui/src/test/java/com/fsck/k9/activity/compose/RecipientPresenterTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ import android.content.Context; import android.support.v4.app.LoaderManager; import com.fsck.k9.Account; import com.fsck.k9.DI; import com.fsck.k9.K9RobolectricTest; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode; import com.fsck.k9.autocrypt.AutocryptDraftStateHeaderParser; import com.fsck.k9.helper.ReplyToParser; import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses; import com.fsck.k9.mail.Address; Loading Loading @@ -90,7 +92,8 @@ public class RecipientPresenterTest extends K9RobolectricTest { recipientPresenter = new RecipientPresenter( context, loaderManager, openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider, autocryptStatusInteractor, replyToParser, listener composePgpEnableByDefaultDecider, autocryptStatusInteractor, replyToParser, listener, DI.get(AutocryptDraftStateHeaderParser.class) ); ArgumentCaptor<OpenPgpApiManagerCallback> callbackCaptor = ArgumentCaptor.forClass(OpenPgpApiManagerCallback.class); Loading