From f9a0c35daa7217d4bebd8d8d93a8720336eeec04 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Tue, 25 Apr 2023 13:46:40 +0200 Subject: [PATCH] fix(GODT-2588): Always perma-delete from Drafts/Trash --- internal/user/imap.go | 28 ++----------------- .../imap/message/delete_from_trash.feature | 6 ++-- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/internal/user/imap.go b/internal/user/imap.go index 86a4cf5b..6d329e95 100644 --- a/internal/user/imap.go +++ b/internal/user/imap.go @@ -400,32 +400,8 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag } if mailboxID == proton.TrashLabel || mailboxID == proton.DraftsLabel { - var metadata []proton.MessageMetadata - - // There's currently no limit on how many IDs we can filter on, - // but to be nice to API, let's chunk it by 150. - for _, messageIDs := range xslices.Chunk(messageIDs, 150) { - m, err := conn.client.GetMessageMetadata(ctx, proton.MessageFilter{ - ID: mapTo[imap.MessageID, string](messageIDs), - }) - if err != nil { - return err - } - - // If a message is not preset in any other label other than AllMail, AllDrafts and AllSent, it can be - // permanently deleted. - m = xslices.Filter(m, func(m proton.MessageMetadata) bool { - labelsThatMatter := xslices.Filter(m.LabelIDs, func(id string) bool { - return id != proton.AllDraftsLabel && id != proton.AllMailLabel && id != proton.AllSentLabel - }) - return len(labelsThatMatter) == 0 - }) - - metadata = append(metadata, m...) - } - - if err := conn.client.DeleteMessage(ctx, xslices.Map(metadata, func(m proton.MessageMetadata) string { - return m.ID + if err := conn.client.DeleteMessage(ctx, xslices.Map(messageIDs, func(m imap.MessageID) string { + return string(m) })...); err != nil { return err } diff --git a/tests/features/imap/message/delete_from_trash.feature b/tests/features/imap/message/delete_from_trash.feature index fdc5105e..7d80ece4 100644 --- a/tests/features/imap/message/delete_from_trash.feature +++ b/tests/features/imap/message/delete_from_trash.feature @@ -6,7 +6,7 @@ Feature: IMAP remove messages from Trash | mbox | folder | | label | label | - Scenario Outline: Message in Trash and some other label is not permanently deleted + Scenario Outline: Message in Trash and some other label is permanently deleted Given the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Trash": | from | to | subject | body | | john.doe@mail.com | [user:user]@[domain] | foo | hello | @@ -26,8 +26,8 @@ Feature: IMAP remove messages from Trash When IMAP client "1" expunges Then it succeeds And IMAP client "1" eventually sees 1 messages in "Trash" - And IMAP client "1" eventually sees 2 messages in "All Mail" - And IMAP client "1" eventually sees 1 messages in "Labels/label" + And IMAP client "1" eventually sees 1 messages in "All Mail" + And IMAP client "1" eventually sees 0 messages in "Labels/label" Scenario Outline: Message in Trash only is permanently deleted Given the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Trash":