aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-08-16 16:23:39 -0500
committerRobin Jarry <robin@jarry.cc>2022-08-22 15:46:53 +0200
commit64e1a7ca933b404d3556e776d0373069c1a0b763 (patch)
tree46a53da095c96952cd2478e1b3e7fe962adde7d4 /worker
parent57933f65ab456fc4ac81423422b6686801e08c9e (diff)
downloadaerc-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.go17
-rw-r--r--worker/imap/worker.go2
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: