diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-08-16 16:23:39 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-22 15:46:53 +0200 |
commit | 64e1a7ca933b404d3556e776d0373069c1a0b763 (patch) | |
tree | 46a53da095c96952cd2478e1b3e7fe962adde7d4 /worker | |
parent | 57933f65ab456fc4ac81423422b6686801e08c9e (diff) | |
download | aerc-64e1a7ca933b404d3556e776d0373069c1a0b763.tar.gz |
imap: implement MoveMessages handling
Implement MoveMessages in the imap backend. go-imap includes the MOVE
Imap extension by default, and if a server does not support it the
command fallsback to a copy-and-delete operation. Servers with the MOVE
extension will see a slight performance increase when moving messages
due to fewer round trips. The IMAP implementation uses a MessagesMoved
worker message to avoid polling the destination mailbox.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/movecopy.go | 17 | ||||
-rw-r--r-- | worker/imap/worker.go | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/worker/imap/movecopy.go b/worker/imap/movecopy.go index 1d25c08c..d3df133a 100644 --- a/worker/imap/movecopy.go +++ b/worker/imap/movecopy.go @@ -46,3 +46,20 @@ func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) { imapw.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) } } + +func (imapw *IMAPWorker) handleMoveMessages(msg *types.MoveMessages) { + uids := toSeqSet(msg.Uids) + if err := imapw.client.UidMove(uids, msg.Destination); err != nil { + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + } else { + imapw.worker.PostMessage(&types.MessagesMoved{ + Message: types.RespondTo(msg), + Destination: msg.Destination, + Uids: msg.Uids, + }, nil) + imapw.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil) + } +} diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 6b6c9261..66e4cdf6 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -205,6 +205,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.handleAnsweredMessages(msg) case *types.CopyMessages: w.handleCopyMessages(msg) + case *types.MoveMessages: + w.handleMoveMessages(msg) case *types.AppendMessage: w.handleAppendMessage(msg) case *types.SearchDirectory: |