From 098685ec8b4c713a09e239e1147ad5ae905f0c1a Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Wed, 9 Nov 2022 13:14:08 +0100 Subject: [PATCH] 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. --- internal/user/imap.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/user/imap.go b/internal/user/imap.go index c6f9869b..90b8f73a 100644 --- a/internal/user/imap.go +++ b/internal/user/imap.go @@ -335,18 +335,14 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag return err } - if mailboxID == liteapi.DraftsLabel { - // Also have to check for all drafts label. - m = xslices.Filter(m, func(m liteapi.MessageMetadata) bool { - return len(m.LabelIDs) == 2 && - ((m.LabelIDs[0] == liteapi.AllMailLabel && m.LabelIDs[1] == liteapi.AllDraftsLabel) || - (m.LabelIDs[1] == liteapi.AllMailLabel && m.LabelIDs[0] == liteapi.AllDraftsLabel)) + // 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 liteapi.MessageMetadata) bool { + labelsThatMatter := xslices.Filter(m.LabelIDs, func(id string) bool { + return id != liteapi.AllDraftsLabel && id != liteapi.AllMailLabel && id != liteapi.AllSentLabel }) - } else { - m = xslices.Filter(m, func(m liteapi.MessageMetadata) bool { - return len(m.LabelIDs) == 1 && m.LabelIDs[0] == liteapi.AllMailLabel - }) - } + return len(labelsThatMatter) == 0 + }) metadata = append(metadata, m...) }