fix(identity): use correct sender identity for non-draft messages edited as new messages - #11432
Open
danielcoderman wants to merge 1 commit into
Open
fix(identity): use correct sender identity for non-draft messages edited as new messages#11432danielcoderman wants to merge 1 commit into
danielcoderman wants to merge 1 commit into
Conversation
The sender identity is retrieved from non-draft messages being edited as new messages with the help of an IdentityHelper function because messages that aren't saved as drafts (sent/received) don't have k9identity metadata attached. Fixes thunderbird#11348
Contributor
|
Missing report label. Set exactly one of: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution Summary
Linked Issue/Ticket: #11348
RFC / Technical Design (if applicable):
Description
This PR fixes issue #11348 by getting the correct sender identity for non-draft messages edited as new messages. It:
processDraftMessagemethod ofMessageComposewhich assigns the correct sender identitygetSenderIdentityFromMessagefunction inIdentityHelperfindIdentitymethod inLegacyAccountDtoto first match an identity by email and name before matching by only emailIdentityHelperfunctionProblem:
Messages edited as new messages go through the same code path as draft messages opened for editing, starting from the call to
MessageActions.actionEditDraftthey both make (seeopenMessageandonEditAsNewMessageinMessageHomeActivity). At some point after this call they both go through theprocessDraftMessagemethod inMessageCompose. Here is where the problem is. InprocessDraftMessagethe identity metadata is extracted from the K9 identity header if it's attached to the message being processed. This K9 identity header is only attached to messages saved as drafts which means that since this was the only way of getting the identity metadata, inprocessDraftMessage, non-draft messages ended up using the default identity set in theonCreatemethod ofMessageCompose(line 497).Approach:
I added an else block to the if statement in
processDraftMessage(line 1561) that basically checks if there's an available k9 identity header. In this else block a call to a new function I wrote,IdentityHelper.getSenderIdentityFromMessage, is made. This function takes in the account the message belongs to and the message itself as arguments. It then gets theAddressobject corresponding to the sender of the message and passes it to the updatedfindIdentitymethod which returns the matching identity. Theidentityfield inMessageComposeis set to this returned matching identity in the else block and from there the rest of the code takes care of updating the screen so that the right identity metadata is displayed.I noticed the
findIdentitymethod didn't take into account thepersonalfield of the passed inAddressobject (corresponds to thenamefield of anIdentityobject), so I updated it so that it first tries to match an identity to both email and name, and if that doesn't work then it finds an identity that just matches the email. At first I removed matching by email only but that failed existing tests, and I later found that names for identities aren't required, and that identity names can be edited. That's why I decided to leave the email only matching because it's necessary. For the case where identity names can be edited, the default identity is still returned if the edited identity shares the same email as the default identity. I don't know if that matters, but the only way to get around that with my current approach would be if theAddressobject corresponding to the sender of the message contained some sort of ID that doesn't change. Of course theIdentityobjects would also need this same kind of ID in order for matching to work.Tests:
I created 3 new tests and a private helper function, in the existing
IdentityHelperTestfile, for the newgetSenderIdentityFromMessagefunction which also happen to indirectly test the updatedfindIdentitymethod. These tests follow the same style of tests in the existing test file, but I can update them to follow the AAA pattern mentioned in the test guide.I couldn't find an existing test file for
LegacyAccountDtoto directly testfindIdentityafter updating it. I can also add tests for it, but since I couldn't find them I first want to make sure I'm not doing anything wrong. Similarly, I couldn't find existing tests for theprocessDraftMessagemethod ofMessageCompose, but I'm not exactly sure how the testing would work there.Notes:
findIdentityalso fixed a bug where clicking the message header of an email you sent with a second identity (sharing the same email as the default identity) showed a bottom sheet displaying the default identityMessageComposesolves this issue "Edit as new mail" after send fail always sets the identity to default identity? #11348 which happens to occur for any message edited as a new message, not just for failed messages in the Outbox which are edited as new messages.AI Disclosure
Select one of the following (mandatory)
Contribution Checklist
gradlew spotlessCheckto check andgradlew spotlessApplyto format your source code; will be checked by CI).gradlew testDebugUnitTest; will be checked by CI).