diff options
Diffstat (limited to 'worker/jmap/set.go')
-rw-r--r-- | worker/jmap/set.go | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/worker/jmap/set.go b/worker/jmap/set.go index d5d4990e..1661f5b1 100644 --- a/worker/jmap/set.go +++ b/worker/jmap/set.go @@ -59,36 +59,50 @@ func (w *JMAPWorker) updateFlags(uids []uint32, flags models.Flags, enable bool) return nil } -func (w *JMAPWorker) moveCopy(uids []uint32, destDir string, move bool) error { +func (w *JMAPWorker) moveCopy(uids []uint32, destDir string, deleteSrc bool) error { var req jmap.Request - var dest jmap.ID + var destMbox jmap.ID + var destroy []jmap.ID var ok bool - update := make(map[jmap.ID]jmap.Patch) + patches := make(map[jmap.ID]jmap.Patch) - dest, ok = w.dir2mbox[destDir] + destMbox, ok = w.dir2mbox[destDir] if !ok && destDir != "" { return fmt.Errorf("unknown destination mailbox") } for _, uid := range uids { + dest := destMbox id, ok := w.uidStore.GetKey(uid) if !ok { return fmt.Errorf("bug: unknown uid %d", uid) } + mail, ok := w.emails[jmap.ID(id)] + if !ok { + return fmt.Errorf("bug: unknown message id %s", id) + } patch := jmap.Patch{} - if dest != "" { + if dest == "" { + dest = w.fallbackMbox(mail) + } + if dest != "" && dest != w.selectedMbox { patch[fmt.Sprintf("mailboxIds/%s", dest)] = true } - if move { + if deleteSrc { + if len(patch) == 0 { + destroy = append(destroy, mail.ID) + continue + } patch[fmt.Sprintf("mailboxIds/%s", w.selectedMbox)] = nil } - update[jmap.ID(id)] = patch + patches[jmap.ID(id)] = patch } req.Invoke(&email.Set{ Account: w.accountId(), - Update: update, + Update: patches, + Destroy: destroy, }) resp, err := w.client.Do(&req) @@ -116,3 +130,15 @@ func (w *JMAPWorker) moveCopy(uids []uint32, destDir string, move bool) error { return nil } + +func (w *JMAPWorker) fallbackMbox(mail *email.Email) jmap.ID { + switch { + case len(mail.MailboxIDs) > 1: + return "" + case w.config.useLabels && w.archiveMbox != "": + return w.archiveMbox + case w.trashMbox != "": + return w.trashMbox + } + return "" +} |