diff --git a/http/import.go b/http/import.go index a6d7880..b3be525 100644 --- a/http/import.go +++ b/http/import.go @@ -450,8 +450,8 @@ func importMessages(ctx context.Context, log *mlog.Log, token string, acc *store err = tx.Insert(&mb) ximportcheckf(err, "inserting mailbox in database") - err = tx.Insert(&store.Subscription{Name: p}) - if err != nil && !errors.Is(err, bstore.ErrUnique) { + if tx.Get(&store.Subscription{Name: p}) != nil { + err := tx.Insert(&store.Subscription{Name: p}) ximportcheckf(err, "subscribing to imported mailbox") } changes = append(changes, store.ChangeAddMailbox{Name: p, Flags: []string{`\Subscribed`}}) diff --git a/imapserver/server.go b/imapserver/server.go index 690a3cf..290d9b9 100644 --- a/imapserver/server.go +++ b/imapserver/server.go @@ -2470,8 +2470,9 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) { } err = tx.Insert(&mb) xcheckf(err, "creating parent mailbox") - err = tx.Insert(&store.Subscription{Name: parent}) - if err != nil && !errors.Is(err, bstore.ErrUnique) { + + if tx.Get(&store.Subscription{Name: parent}) != nil { + err := tx.Insert(&store.Subscription{Name: parent}) xcheckf(err, "creating subscription") } changes = append(changes, store.ChangeAddMailbox{Name: parent, Flags: []string{`\Subscribed`}}) diff --git a/store/account.go b/store/account.go index ce025fc..22a759c 100644 --- a/store/account.go +++ b/store/account.go @@ -970,9 +970,11 @@ func (a *Account) MailboxEnsure(tx *bstore.Tx, name string, subscribe bool) (mb change := ChangeAddMailbox{Name: p} if subscribe { - err := tx.Insert(&Subscription{p}) - if err != nil && !errors.Is(err, bstore.ErrUnique) { - return Mailbox{}, nil, fmt.Errorf("subscribing to mailbox: %v", err) + if tx.Get(&Subscription{p}) != nil { + err := tx.Insert(&Subscription{p}) + if err != nil { + return Mailbox{}, nil, fmt.Errorf("subscribing to mailbox: %v", err) + } } change.Flags = []string{`\Subscribed`} }