diff --git a/internal/user/sync.go b/internal/user/sync.go index a46c81f4..76f9b61e 100644 --- a/internal/user/sync.go +++ b/internal/user/sync.go @@ -36,7 +36,6 @@ import ( "github.com/ProtonMail/proton-bridge/v3/internal/vault" "github.com/bradenaw/juniper/parallel" "github.com/bradenaw/juniper/xslices" - "github.com/google/uuid" "github.com/pbnjay/memory" "github.com/sirupsen/logrus" "golang.org/x/exp/maps" @@ -59,6 +58,7 @@ func (user *User) syncSystemLabels(ctx context.Context) error { updates = append(updates, update) } } + if err := waitOnIMAPUpdates(ctx, updates); err != nil { return fmt.Errorf("could not sync system labels: %w", err) } @@ -187,7 +187,7 @@ func (user *User) sync(ctx context.Context) error { func syncLabels(ctx context.Context, apiLabels map[string]proton.Label, updateCh ...*queue.QueuedChannel[imap.Update]) error { var updates []imap.Update - // Create placeholder Folders/Labels mailboxes with a random ID and with the \Noselect attribute. + // Create placeholder Folders/Labels mailboxes with the \Noselect attribute. for _, prefix := range []string{folderPrefix, labelPrefix} { for _, updateCh := range updateCh { update := newPlaceHolderMailboxCreatedUpdate(prefix) @@ -698,7 +698,7 @@ func newSystemMailboxCreatedUpdate(labelID imap.MailboxID, labelName string) *im func newPlaceHolderMailboxCreatedUpdate(labelName string) *imap.MailboxCreated { return imap.NewMailboxCreated(imap.Mailbox{ - ID: imap.MailboxID(uuid.NewString()), + ID: imap.MailboxID(labelName), Name: []string{labelName}, Flags: defaultFlags, PermanentFlags: defaultPermanentFlags, diff --git a/internal/user/user.go b/internal/user/user.go index ae85d7a9..65580dcf 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -191,11 +191,14 @@ func New( user.syncAbort.Do(ctx, func(ctx context.Context) { if user.vault.SyncStatus().IsComplete() { user.log.Info("Sync already complete, only system label will be updated") + if err := user.syncSystemLabels(ctx); err != nil { user.log.WithError(err).Error("Failed to update system labels") return } + user.log.Info("System label update complete, starting API event stream") + return } diff --git a/tests/features/imap/message/move.feature b/tests/features/imap/message/move.feature index b695d36a..33235de5 100644 --- a/tests/features/imap/message/move.feature +++ b/tests/features/imap/message/move.feature @@ -93,23 +93,23 @@ Feature: IMAP move messages Scenario: Move message from system label to system label When IMAP client "1" moves the message with subject "foo" from "INBOX" to "Trash" And it succeeds - And IMAP client "1" sees the following messages in "INBOX": + And IMAP client "1" eventually sees the following messages in "INBOX": | from | to | subject | unread | | jane.doe@mail.com | name@[domain] | bar | true | - And IMAP client "1" sees the following messages in "Trash": + And IMAP client "1" eventually sees the following messages in "Trash": | from | to | subject | unread | | john.doe@mail.com | [user:user]@[domain] | foo | false | Scenario: Move message from folder to system label When IMAP client "1" moves the message with subject "baz" from "Labels/label2" to "Folders/mbox" And it succeeds - And IMAP client "1" sees the following messages in "Folders/mbox": + And IMAP client "1" eventually sees the following messages in "Folders/mbox": | from | to | subject | unread | | john.doe@mail.com | [user:user]@[domain] | baz | false | When IMAP client "1" moves the message with subject "baz" from "Folders/mbox" to "Trash" And it succeeds - And IMAP client "1" sees 0 messages in "Folders/mbox" - And IMAP client "1" sees the following messages in "Trash": + And IMAP client "1" eventually sees 0 messages in "Folders/mbox" + And IMAP client "1" eventually sees the following messages in "Trash": | from | to | subject | unread | | john.doe@mail.com | [user:user]@[domain] | baz | false |