Skip to content

Commit 9fe1c15

Browse files
jameshoulahanLBeernaertProton
authored andcommitted
feat: Silently create missing messages on update
1 parent c1a1f6a commit 9fe1c15

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

internal/backend/connector_updates.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,21 @@ func (user *user) applyMessageDeleted(ctx context.Context, update *imap.MessageD
598598
func (user *user) applyMessageUpdated(ctx context.Context, update *imap.MessageUpdated) error {
599599
log := logrus.WithField("message updated", update.Message.ID.ShortID())
600600

601-
if err := user.db.Write(ctx, func(ctx context.Context, tx *ent.Tx) error {
602-
internalMessageID, err := db.GetMessageIDFromRemoteID(ctx, tx.Client(), update.Message.ID)
603-
if err != nil {
604-
if ent.IsNotFound(err) {
605-
log.Debugf("Message %v no longer exists, skipping", update.Message.ID.ShortID())
606-
return nil
607-
}
608-
return err
609-
}
601+
internalMessageID, err := db.ReadResult(ctx, user.db, func(ctx context.Context, client *ent.Client) (imap.InternalMessageID, error) {
602+
return db.GetMessageIDFromRemoteID(ctx, client, update.Message.ID)
603+
})
604+
if ent.IsNotFound(err) {
605+
return user.applyMessagesCreated(ctx, imap.NewMessagesCreated(true, &imap.MessageCreated{
606+
Message: update.Message,
607+
Literal: update.Literal,
608+
MailboxIDs: update.MailboxIDs,
609+
ParsedMessage: update.ParsedMessage,
610+
}))
611+
} else if err != nil {
612+
return err
613+
}
610614

615+
return user.db.Write(ctx, func(ctx context.Context, tx *ent.Tx) error {
611616
// compare and see if the literal has changed.
612617
onDiskLiteral, err := user.store.Get(internalMessageID)
613618
if err != nil {
@@ -716,11 +721,7 @@ func (user *user) applyMessageUpdated(ctx context.Context, update *imap.MessageU
716721
}
717722

718723
return nil
719-
}); err != nil {
720-
return err
721-
}
722-
723-
return nil
724+
})
724725
}
725726

726727
// applyUIDValidityBumped applies a UIDValidityBumped event to the user.

0 commit comments

Comments
 (0)