mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00
make code less indented
This commit is contained in:
parent
577944310c
commit
a5c64e4361
@ -2943,63 +2943,63 @@ func (c *conn) cmdRename(tag, cmd string, p *parser) {
|
||||
c.xdbwrite(func(tx *bstore.Tx) {
|
||||
srcMB := c.xmailbox(tx, src, "NONEXISTENT")
|
||||
|
||||
// Handle common/simple case first.
|
||||
if src != "Inbox" {
|
||||
var modseq store.ModSeq
|
||||
var alreadyExists bool
|
||||
var err error
|
||||
changes, _, alreadyExists, err = c.account.MailboxRename(tx, &srcMB, dst, &modseq)
|
||||
if alreadyExists {
|
||||
xusercodeErrorf("ALREADYEXISTS", "%s", err)
|
||||
}
|
||||
xcheckf(err, "renaming mailbox")
|
||||
return
|
||||
}
|
||||
|
||||
// Inbox is very special. Unlike other mailboxes, its children are not moved. And
|
||||
// unlike a regular move, its messages are moved to a newly created mailbox. We do
|
||||
// indeed create a new destination mailbox and actually move the messages.
|
||||
// ../rfc/9051:2101
|
||||
if src == "Inbox" {
|
||||
exists, err := c.account.MailboxExists(tx, dst)
|
||||
xcheckf(err, "checking if destination mailbox exists")
|
||||
if exists {
|
||||
xusercodeErrorf("ALREADYEXISTS", "destination mailbox %q already exists", dst)
|
||||
}
|
||||
if dst == src {
|
||||
xuserErrorf("cannot move inbox to itself")
|
||||
}
|
||||
|
||||
var modseq store.ModSeq
|
||||
dstMB, chl, err := c.account.MailboxEnsure(tx, dst, false, store.SpecialUse{}, &modseq)
|
||||
xcheckf(err, "creating destination mailbox")
|
||||
changes = chl
|
||||
|
||||
// Copy mailbox annotations. ../rfc/5464:368
|
||||
qa := bstore.QueryTx[store.Annotation](tx)
|
||||
qa.FilterNonzero(store.Annotation{MailboxID: srcMB.ID})
|
||||
qa.FilterEqual("Expunged", false)
|
||||
annotations, err := qa.List()
|
||||
xcheckf(err, "get annotations to copy for inbox")
|
||||
for _, a := range annotations {
|
||||
a.ID = 0
|
||||
a.MailboxID = dstMB.ID
|
||||
a.ModSeq = modseq
|
||||
a.CreateSeq = modseq
|
||||
err := tx.Insert(&a)
|
||||
xcheckf(err, "copy annotation to destination mailbox")
|
||||
changes = append(changes, a.Change(dstMB.Name))
|
||||
}
|
||||
c.xcheckMetadataSize(tx)
|
||||
|
||||
// Build query that selects messages to move.
|
||||
q := bstore.QueryTx[store.Message](tx)
|
||||
q.FilterNonzero(store.Message{MailboxID: srcMB.ID})
|
||||
q.FilterEqual("Expunged", false)
|
||||
q.SortAsc("UID")
|
||||
|
||||
newIDs, chl := c.xmoveMessages(tx, q, 0, modseq, &srcMB, &dstMB)
|
||||
changes = append(changes, chl...)
|
||||
cleanupIDs = newIDs
|
||||
|
||||
return
|
||||
exists, err := c.account.MailboxExists(tx, dst)
|
||||
xcheckf(err, "checking if destination mailbox exists")
|
||||
if exists {
|
||||
xusercodeErrorf("ALREADYEXISTS", "destination mailbox %q already exists", dst)
|
||||
}
|
||||
if dst == src {
|
||||
xuserErrorf("cannot move inbox to itself")
|
||||
}
|
||||
|
||||
var modseq store.ModSeq
|
||||
var alreadyExists bool
|
||||
var err error
|
||||
changes, _, alreadyExists, err = c.account.MailboxRename(tx, &srcMB, dst, &modseq)
|
||||
if alreadyExists {
|
||||
xusercodeErrorf("ALREADYEXISTS", "%s", err)
|
||||
dstMB, chl, err := c.account.MailboxEnsure(tx, dst, false, store.SpecialUse{}, &modseq)
|
||||
xcheckf(err, "creating destination mailbox")
|
||||
changes = chl
|
||||
|
||||
// Copy mailbox annotations. ../rfc/5464:368
|
||||
qa := bstore.QueryTx[store.Annotation](tx)
|
||||
qa.FilterNonzero(store.Annotation{MailboxID: srcMB.ID})
|
||||
qa.FilterEqual("Expunged", false)
|
||||
annotations, err := qa.List()
|
||||
xcheckf(err, "get annotations to copy for inbox")
|
||||
for _, a := range annotations {
|
||||
a.ID = 0
|
||||
a.MailboxID = dstMB.ID
|
||||
a.ModSeq = modseq
|
||||
a.CreateSeq = modseq
|
||||
err := tx.Insert(&a)
|
||||
xcheckf(err, "copy annotation to destination mailbox")
|
||||
changes = append(changes, a.Change(dstMB.Name))
|
||||
}
|
||||
xcheckf(err, "renaming mailbox")
|
||||
c.xcheckMetadataSize(tx)
|
||||
|
||||
// Build query that selects messages to move.
|
||||
q := bstore.QueryTx[store.Message](tx)
|
||||
q.FilterNonzero(store.Message{MailboxID: srcMB.ID})
|
||||
q.FilterEqual("Expunged", false)
|
||||
q.SortAsc("UID")
|
||||
|
||||
newIDs, chl := c.xmoveMessages(tx, q, 0, modseq, &srcMB, &dstMB)
|
||||
changes = append(changes, chl...)
|
||||
cleanupIDs = newIDs
|
||||
})
|
||||
|
||||
cleanupIDs = nil
|
||||
|
@ -713,61 +713,64 @@ func importMessages(ctx context.Context, log mlog.Log, token string, acc *store.
|
||||
case "new", "cur", "tmp":
|
||||
mailbox := path.Dir(dir)
|
||||
ximportMaildir(mailbox, origName, r)
|
||||
default:
|
||||
if path.Base(name) == "dovecot-keywords" {
|
||||
mailbox := path.Dir(name)
|
||||
dovecotKeywords := map[rune]string{}
|
||||
words, err := store.ParseDovecotKeywordsFlags(r, log)
|
||||
log.Check(err, "parsing dovecot keywords for mailbox", slog.String("mailbox", mailbox))
|
||||
for i, kw := range words {
|
||||
dovecotKeywords['a'+rune(i)] = kw
|
||||
}
|
||||
mailboxKeywords[mailbox] = dovecotKeywords
|
||||
|
||||
for id, chars := range mailboxMissingKeywordMessages[mailbox] {
|
||||
var flags, zeroflags store.Flags
|
||||
keywords := map[string]bool{}
|
||||
for _, c := range chars {
|
||||
kw, ok := dovecotKeywords[c]
|
||||
if !ok {
|
||||
problemf("unspecified dovecot message flag %c for message id %d (continuing)", c, id)
|
||||
continue
|
||||
}
|
||||
flagSet(&flags, keywords, kw)
|
||||
}
|
||||
if flags == zeroflags && len(keywords) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
m := store.Message{ID: id}
|
||||
err := tx.Get(&m)
|
||||
ximportcheckf(err, "get imported message for flag update")
|
||||
|
||||
mb := mailboxIDs[m.MailboxID]
|
||||
mb.Sub(m.MailboxCounts())
|
||||
|
||||
oflags := m.Flags
|
||||
m.Flags = m.Flags.Set(flags, flags)
|
||||
m.Keywords = maps.Keys(keywords)
|
||||
sort.Strings(m.Keywords)
|
||||
|
||||
mb.Add(m.MailboxCounts())
|
||||
|
||||
mb.Keywords, _ = store.MergeKeywords(mb.Keywords, m.Keywords)
|
||||
|
||||
// We train before updating, training may set m.TrainedJunk.
|
||||
if jf != nil && m.NeedsTraining() {
|
||||
openTrainMessage(&m)
|
||||
}
|
||||
err = tx.Update(&m)
|
||||
ximportcheckf(err, "updating message after flag update")
|
||||
changes = append(changes, m.ChangeFlags(oflags))
|
||||
}
|
||||
delete(mailboxMissingKeywordMessages, mailbox)
|
||||
} else {
|
||||
problemf("unrecognized file %s (skipping)", origName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if path.Base(name) != "dovecot-keywords" {
|
||||
problemf("unrecognized file %s (skipping)", origName)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle dovecot-keywords.
|
||||
mailbox := path.Dir(name)
|
||||
dovecotKeywords := map[rune]string{}
|
||||
words, err := store.ParseDovecotKeywordsFlags(r, log)
|
||||
log.Check(err, "parsing dovecot keywords for mailbox", slog.String("mailbox", mailbox))
|
||||
for i, kw := range words {
|
||||
dovecotKeywords['a'+rune(i)] = kw
|
||||
}
|
||||
mailboxKeywords[mailbox] = dovecotKeywords
|
||||
|
||||
for id, chars := range mailboxMissingKeywordMessages[mailbox] {
|
||||
var flags, zeroflags store.Flags
|
||||
keywords := map[string]bool{}
|
||||
for _, c := range chars {
|
||||
kw, ok := dovecotKeywords[c]
|
||||
if !ok {
|
||||
problemf("unspecified dovecot message flag %c for message id %d (continuing)", c, id)
|
||||
continue
|
||||
}
|
||||
flagSet(&flags, keywords, kw)
|
||||
}
|
||||
if flags == zeroflags && len(keywords) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
m := store.Message{ID: id}
|
||||
err := tx.Get(&m)
|
||||
ximportcheckf(err, "get imported message for flag update")
|
||||
|
||||
mb := mailboxIDs[m.MailboxID]
|
||||
mb.Sub(m.MailboxCounts())
|
||||
|
||||
oflags := m.Flags
|
||||
m.Flags = m.Flags.Set(flags, flags)
|
||||
m.Keywords = maps.Keys(keywords)
|
||||
sort.Strings(m.Keywords)
|
||||
|
||||
mb.Add(m.MailboxCounts())
|
||||
|
||||
mb.Keywords, _ = store.MergeKeywords(mb.Keywords, m.Keywords)
|
||||
|
||||
// We train before updating, training may set m.TrainedJunk.
|
||||
if jf != nil && m.NeedsTraining() {
|
||||
openTrainMessage(&m)
|
||||
}
|
||||
err = tx.Update(&m)
|
||||
ximportcheckf(err, "updating message after flag update")
|
||||
changes = append(changes, m.ChangeFlags(oflags))
|
||||
}
|
||||
delete(mailboxMissingKeywordMessages, mailbox)
|
||||
}
|
||||
|
||||
if zr != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user