From 0b35b275d3622202026c287fe1d82186caa43836 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Thu, 2 Feb 2023 15:57:25 +0100 Subject: [PATCH] fix(GODT-2333): Do not allow modifications to All Mail label Rather than waiting for API to reply, prevent these operations from taking place in the first place. --- internal/user/imap.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/user/imap.go b/internal/user/imap.go index 35d3fecc..96e9c306 100644 --- a/internal/user/imap.go +++ b/internal/user/imap.go @@ -275,6 +275,10 @@ func (conn *imapConnector) CreateMessage( ) (imap.Message, []byte, error) { defer conn.goPollAPIEvents(false) + if mailboxID == proton.AllMailLabel { + return imap.Message{}, nil, fmt.Errorf("not allowed") + } + // Compute the hash of the message (to match it against SMTP messages). hash, err := getMessageHash(literal) if err != nil { @@ -378,6 +382,10 @@ func (conn *imapConnector) GetMessageLiteral(ctx context.Context, id imap.Messag func (conn *imapConnector) AddMessagesToMailbox(ctx context.Context, messageIDs []imap.MessageID, mailboxID imap.MailboxID) error { defer conn.goPollAPIEvents(false) + if mailboxID == proton.AllMailLabel { + return fmt.Errorf("not allowed") + } + return conn.client.LabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID)) } @@ -385,6 +393,10 @@ func (conn *imapConnector) AddMessagesToMailbox(ctx context.Context, messageIDs func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messageIDs []imap.MessageID, mailboxID imap.MailboxID) error { defer conn.goPollAPIEvents(false) + if mailboxID == proton.AllMailLabel { + return fmt.Errorf("not allowed") + } + if err := conn.client.UnlabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID)); err != nil { return err } @@ -429,7 +441,9 @@ func (conn *imapConnector) MoveMessages(ctx context.Context, messageIDs []imap.M defer conn.goPollAPIEvents(false) if (labelFromID == proton.InboxLabel && labelToID == proton.SentLabel) || - (labelFromID == proton.SentLabel && labelToID == proton.InboxLabel) { + (labelFromID == proton.SentLabel && labelToID == proton.InboxLabel) || + labelFromID == proton.AllMailLabel || + labelToID == proton.AllMailLabel { return false, fmt.Errorf("not allowed") }