From 0cb1ff9b167d02324625cdeec8d85a454c8962da Mon Sep 17 00:00:00 2001 From: Michal Horejsek Date: Thu, 16 Apr 2020 13:47:01 +0200 Subject: [PATCH] Do not send an EXISTS reposnse after EXPUNGE or when nothing changed --- Changelog.md | 1 + internal/imap/uidplus/extension.go | 2 +- internal/store/mailbox_message.go | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index c2a83c7b..769f461d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * IMAP extension Unselect ### Changed +* GODT-225 Do not send an EXISTS reposnse after EXPUNGE or when nothing changed (fixes rebuild of mailboxes in Outlook for Mac) * GODT-165 Optimization of RebuildMailboxes * Adding DSN Sentry as build time parameter diff --git a/internal/imap/uidplus/extension.go b/internal/imap/uidplus/extension.go index 679531dc..ff86a70d 100644 --- a/internal/imap/uidplus/extension.go +++ b/internal/imap/uidplus/extension.go @@ -42,7 +42,7 @@ const ( appendSucess = "APPEND successful" ) -var log = logrus.WithField("pkg", "impa/uidplus") //nolint[gochecknoglobals] +var log = logrus.WithField("pkg", "imap/uidplus") //nolint[gochecknoglobals] // OrderedSeq to remember Seq in order they are added. // We didn't find any restriction in RFC that server must respond with ranges diff --git a/internal/store/mailbox_message.go b/internal/store/mailbox_message.go index 4718f742..4e13c88c 100644 --- a/internal/store/mailbox_message.go +++ b/internal/store/mailbox_message.go @@ -249,6 +249,8 @@ func (storeMailbox *Mailbox) txSkipAndRemoveFromMailbox(tx *bolt.Tx, msg *pmapi. // txCreateOrUpdateMessages will delete, create or update message from mailbox. func (storeMailbox *Mailbox) txCreateOrUpdateMessages(tx *bolt.Tx, msgs []*pmapi.Message) error { //nolint[funlen] + shouldSendMailboxUpdate := false + // Buckets are not initialized right away because it's a heavy operation. // The best option is to get the same bucket only once and only when needed. var apiBucket, imapBucket *bolt.Bucket @@ -284,6 +286,7 @@ func (storeMailbox *Mailbox) txCreateOrUpdateMessages(tx *bolt.Tx, msgs []*pmapi seqNum, msg, ) + shouldSendMailboxUpdate = true } continue } @@ -317,9 +320,16 @@ func (storeMailbox *Mailbox) txCreateOrUpdateMessages(tx *bolt.Tx, msgs []*pmapi seqNum, msg, ) + shouldSendMailboxUpdate = true } - return storeMailbox.txMailboxStatusUpdate(tx) + if shouldSendMailboxUpdate { + if err := storeMailbox.txMailboxStatusUpdate(tx); err != nil { + return err + } + } + + return nil } // txDeleteMessage deletes the message from the mailbox bucket. @@ -353,9 +363,10 @@ func (storeMailbox *Mailbox) txDeleteMessage(tx *bolt.Tx, apiID string) error { storeMailbox.labelName, seqNum, ) - if err := storeMailbox.txMailboxStatusUpdate(tx); err != nil { - return err - } + // Outlook for Mac has problems with sending an EXISTS after deleting + // messages, mostly after moving message to other folder. It causes + // Outlook to rebuild the whole mailbox. [RFC-3501] says it's not + // necessary to send an EXISTS response with the new value. } return nil }