GODT-2030: Rework deletion check on expunge

Some messages were not being deleted properly because they were also
present in the All-Sent folder.

The code has now been changed to filter out AllMail, AllDraft and
AllSend. If there are no remaining labels, the message will be deleted
permanently.
This commit is contained in:
Leander Beernaert
2022-11-09 13:14:08 +01:00
committed by James Houlahan
parent 6c9293ec14
commit 098685ec8b

View File

@ -335,18 +335,14 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag
return err return err
} }
if mailboxID == liteapi.DraftsLabel { // If a message is not preset in any other label other than AllMail, AllDrafts and AllSent, it can be
// Also have to check for all drafts label. // permanently deleted.
m = xslices.Filter(m, func(m liteapi.MessageMetadata) bool { m = xslices.Filter(m, func(m liteapi.MessageMetadata) bool {
return len(m.LabelIDs) == 2 && labelsThatMatter := xslices.Filter(m.LabelIDs, func(id string) bool {
((m.LabelIDs[0] == liteapi.AllMailLabel && m.LabelIDs[1] == liteapi.AllDraftsLabel) || return id != liteapi.AllDraftsLabel && id != liteapi.AllMailLabel && id != liteapi.AllSentLabel
(m.LabelIDs[1] == liteapi.AllMailLabel && m.LabelIDs[0] == liteapi.AllDraftsLabel))
}) })
} else { return len(labelsThatMatter) == 0
m = xslices.Filter(m, func(m liteapi.MessageMetadata) bool {
return len(m.LabelIDs) == 1 && m.LabelIDs[0] == liteapi.AllMailLabel
}) })
}
metadata = append(metadata, m...) metadata = append(metadata, m...)
} }