From 64e1a7ca933b404d3556e776d0373069c1a0b763 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 16 Aug 2022 16:23:39 -0500 Subject: 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 Acked-by: Robin Jarry --- worker/imap/movecopy.go | 17 +++++++++++++++++ worker/imap/worker.go | 2 ++ 2 files changed, 19 insertions(+) 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: -- cgit