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>
This commit is contained in:
Tim Culverhouse 2022-08-16 16:23:39 -05:00 committed by Robin Jarry
parent 57933f65ab
commit 64e1a7ca93
2 changed files with 19 additions and 0 deletions

View file

@ -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)
}
}

View file

@ -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: