maildir: implement MoveMessages handling
Implement MoveMessages in the maildir worker. go-maildir supports Move operations by default, and is functionally equivalent to a OS-level rename. Creation date of the file is preserved by using Move, which is used by at least one maildir-to-IMAP synchronizer (isync/mbsync). The previous move method of copy-and-delete would reset the creation date of the message, and potentially cause sorting issues in other email clients. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
64e1a7ca93
commit
af72ca3607
2 changed files with 36 additions and 0 deletions
worker/maildir
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue