From e2fc4deffe20f78d8294b08c41ae2a9a751ef75e Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Wed, 1 Feb 2023 16:09:26 +0100 Subject: [PATCH] fix: Removing from inbox shouldn't remove from trash --- server/backend/message.go | 11 +++++++++-- server/server_test.go | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/backend/message.go b/server/backend/message.go index 569b897..86f07c2 100644 --- a/server/backend/message.go +++ b/server/backend/message.go @@ -17,10 +17,15 @@ type message struct { externalID string addrID string labelIDs []string - sysLabel *string attIDs []string inReplyTo string + // sysLabel is the system label for the message. + // If nil, the message's flags are used to determine the system label (inbox, sent, drafts). + // If "", the message has no system label (e.g. is in a custom folder or all mail). + // If non-nil and non-empty, the message has the system label with the given ID (e.g. spam, trash). + sysLabel *string + subject string sender *mail.Address toList []*mail.Address @@ -334,7 +339,9 @@ func (msg *message) remLabel(labelID string, labels map[string]*label) { } func (msg *message) remFlagLabel(labelID string, labels map[string]*label) { - msg.sysLabel = pointer("") + if msg.sysLabel == nil { + msg.sysLabel = pointer("") + } } func (msg *message) remSystemLabel(labelID string, labels map[string]*label) { diff --git a/server/server_test.go b/server/server_test.go index 830ab2d..87f9e34 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -939,6 +939,12 @@ func TestServer_Labels(t *testing.T) { actions: []any{add(proton.TrashLabel), rem(proton.TrashLabel)}, wantLabelIDs: []string{proton.AllMailLabel, proton.AllSentLabel}, }, + { + name: "received flag, add inbox, add trash, remove inbox", + flags: proton.MessageFlagReceived, + actions: []any{add(proton.InboxLabel), add(proton.TrashLabel), rem(proton.InboxLabel)}, + wantLabelIDs: []string{proton.AllMailLabel, proton.TrashLabel}, + }, } withServer(t, func(ctx context.Context, s *Server, m *proton.Manager) {