aboutsummaryrefslogtreecommitdiffstats
path: root/worker/maildir
diff options
context:
space:
mode:
Diffstat (limited to 'worker/maildir')
-rw-r--r--worker/maildir/container.go20
-rw-r--r--worker/maildir/worker.go16
2 files changed, 36 insertions, 0 deletions
diff --git a/worker/maildir/container.go b/worker/maildir/container.go
index a8ac1aca..c5ac04ac 100644
--- a/worker/maildir/container.go
+++ b/worker/maildir/container.go
@@ -205,3 +205,23 @@ func (c *Container) copyMessage(
_, err := src.Copy(dest, key)
return err
}
+
+func (c *Container) MoveAll(dest maildir.Dir, src maildir.Dir, uids []uint32) ([]uint32, error) {
+ var success []uint32
+ for _, uid := range uids {
+ if err := c.moveMessage(dest, src, uid); err != nil {
+ return success, fmt.Errorf("could not move message %d: %w", uid, err)
+ }
+ success = append(success, uid)
+ }
+ return success, nil
+}
+
+func (c *Container) moveMessage(dest maildir.Dir, src maildir.Dir, uid uint32) error {
+ key, ok := c.uids.GetKey(uid)
+ if !ok {
+ return fmt.Errorf("could not find key for message id %d", uid)
+ }
+ err := src.Move(dest, key)
+ return err
+}
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index e482f4e0..e85caacc 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -294,6 +294,8 @@ func (w *Worker) handleMessage(msg types.WorkerMessage) error {
return w.handleAnsweredMessages(msg)
case *types.CopyMessages:
return w.handleCopyMessages(msg)
+ case *types.MoveMessages:
+ return w.handleMoveMessages(msg)
case *types.AppendMessage:
return w.handleAppendMessage(msg)
case *types.SearchDirectory:
@@ -655,6 +657,20 @@ func (w *Worker) handleCopyMessages(msg *types.CopyMessages) error {
return nil
}
+func (w *Worker) handleMoveMessages(msg *types.MoveMessages) error {
+ dest := w.c.Dir(msg.Destination)
+ moved, err := w.c.MoveAll(dest, *w.selected, msg.Uids)
+ destInfo := w.getDirectoryInfo(msg.Destination)
+ w.worker.PostMessage(&types.DirectoryInfo{
+ Info: destInfo,
+ }, nil)
+ w.worker.PostMessage(&types.MessagesDeleted{
+ Message: types.RespondTo(msg),
+ Uids: moved,
+ }, nil)
+ return err
+}
+
func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error {
// since we are the "master" maildir process, we can modify the maildir directly
dest := w.c.Dir(msg.Destination)