fix(GODT-2588): Always perma-delete from Drafts/Trash

This commit is contained in:
Leander Beernaert
2023-04-25 13:46:40 +02:00
parent e9629aca47
commit f9a0c35daa
2 changed files with 5 additions and 29 deletions

View File

@ -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
}

View File

@ -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":