GODT-2226: Fix moving drafts to trash

Only handle draft updates if the event was a message update. Also
includes Gluon update.
This commit is contained in:
Leander Beernaert
2023-01-12 11:13:06 +01:00
parent 0580842ad2
commit 931ed119bb
6 changed files with 37 additions and 5 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.18
require (
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/gluon v0.14.2-0.20230111132924-ace48198e45a
github.com/ProtonMail/gluon v0.14.2-0.20230112101229-07a5a074643e
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.2.4-0.20230112102613-6ad201cdb337
github.com/ProtonMail/go-rfc5322 v0.11.0

4
go.sum
View File

@ -28,8 +28,8 @@ github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf h1:yc9daCCYUefEs
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
github.com/ProtonMail/gluon v0.14.2-0.20230111132924-ace48198e45a h1:yx/1F4jGMLVTUVeycIGwe90l5YQWrvoTbPOYWC4FLkY=
github.com/ProtonMail/gluon v0.14.2-0.20230111132924-ace48198e45a/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
github.com/ProtonMail/gluon v0.14.2-0.20230112101229-07a5a074643e h1:3UfVqUoBAh8R+FO+F+l0XkXerO6v0lD8waMFfwkdP/c=
github.com/ProtonMail/gluon v0.14.2-0.20230112101229-07a5a074643e/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=

View File

@ -409,8 +409,9 @@ func (user *User) handleMessageEvents(ctx context.Context, messageEvents []proto
}
case proton.EventUpdate, proton.EventUpdateFlags:
// Draft update means to completely remove old message and upload the new data again.
if event.Message.IsDraft() {
// Draft update means to completely remove old message and upload the new data again, but we should
// only do this if the event is of type EventUpdate otherwise label switch operations will not work.
if event.Message.IsDraft() && event.Action == proton.EventUpdate {
if err := user.handleUpdateDraftEvent(
logging.WithLogrusField(ctx, "action", "update draft"),
event,

View File

@ -121,6 +121,7 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^the address "([^"]*)" of account "([^"]*)" has the following messages in "([^"]*)":$`, s.theAddressOfAccountHasTheFollowingMessagesInMailbox)
ctx.Step(`^the address "([^"]*)" of account "([^"]*)" has (\d+) messages in "([^"]*)"$`, s.theAddressOfAccountHasMessagesInMailbox)
ctx.Step(`^the following fields were changed in draft (\d+) for address "([^"]*)" of account "([^"]*)":$`, s.theFollowingFieldsWereChangedInDraftForAddressOfAccount)
ctx.Step(`^draft (\d+) for address "([^"]*)" of account "([^"]*) was moved to trash$`, s.drafAtIndexWasMovedToTrashForAddressOfAccount)
// === REPORTER ===
ctx.Step(`^test skips reporter checks$`, s.skipReporterChecks)

View File

@ -44,3 +44,10 @@ Feature: IMAP Draft messages
| someone@example.com | Basic Draft | This is a draft body, but longer |
And IMAP client "1" sees 1 messages in "Drafts"
Scenario: Draft moved to trash remotely
When draft 1 for address "[user:user]@[domain]" of account "[user:user] was moved to trash
Then IMAP client "1" eventually sees the following messages in "Trash":
| body |
| This is a dra |
And IMAP client "1" sees 0 messages in "Drafts"

View File

@ -297,6 +297,29 @@ func (s *scenario) theFollowingFieldsWereChangedInDraftForAddressOfAccount(draft
})
}
func (s *scenario) drafAtIndexWasMovedToTrashForAddressOfAccount(draftIndex int, address, username string) error {
draftID, err := s.t.getDraftID(username, draftIndex)
if err != nil {
return fmt.Errorf("failed to get draft ID: %w", err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
return s.t.withClient(ctx, username, func(ctx context.Context, c *proton.Client) error {
return s.t.withAddrKR(ctx, c, username, s.t.getUserAddrID(s.t.getUserID(username), address), func(_ context.Context, addrKR *crypto.KeyRing) error {
if err := c.UnlabelMessages(ctx, []string{draftID}, proton.DraftsLabel); err != nil {
return fmt.Errorf("failed to unlabel draft")
}
if err := c.LabelMessages(ctx, []string{draftID}, proton.TrashLabel); err != nil {
return fmt.Errorf("failed to label draft to trah")
}
return nil
})
})
}
func (s *scenario) userLogsInWithUsernameAndPassword(username, password string) error {
userID, err := s.t.bridge.LoginFull(context.Background(), username, []byte(password), nil, nil)
if err != nil {