mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-16 07:06:45 +00:00
fix(GODT-2588): Always perma-delete from Drafts/Trash
This commit is contained in:
@ -400,32 +400,8 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mailboxID == proton.TrashLabel || mailboxID == proton.DraftsLabel {
|
if mailboxID == proton.TrashLabel || mailboxID == proton.DraftsLabel {
|
||||||
var metadata []proton.MessageMetadata
|
if err := conn.client.DeleteMessage(ctx, xslices.Map(messageIDs, func(m imap.MessageID) string {
|
||||||
|
return string(m)
|
||||||
// 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
|
|
||||||
})...); err != nil {
|
})...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ Feature: IMAP remove messages from Trash
|
|||||||
| mbox | folder |
|
| mbox | folder |
|
||||||
| label | label |
|
| 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":
|
Given the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Trash":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| john.doe@mail.com | [user:user]@[domain] | foo | hello |
|
| john.doe@mail.com | [user:user]@[domain] | foo | hello |
|
||||||
@ -26,8 +26,8 @@ Feature: IMAP remove messages from Trash
|
|||||||
When IMAP client "1" expunges
|
When IMAP client "1" expunges
|
||||||
Then it succeeds
|
Then it succeeds
|
||||||
And IMAP client "1" eventually sees 1 messages in "Trash"
|
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 "All Mail"
|
||||||
And IMAP client "1" eventually sees 1 messages in "Labels/label"
|
And IMAP client "1" eventually sees 0 messages in "Labels/label"
|
||||||
|
|
||||||
Scenario Outline: Message in Trash only is permanently deleted
|
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":
|
Given the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Trash":
|
||||||
|
|||||||
Reference in New Issue
Block a user