From 93207b733046f7fde645b68f4bafd1cab51b3dff Mon Sep 17 00:00:00 2001 From: inwit Date: Sat, 29 Jun 2024 17:14:27 +0200 Subject: maildir: set the forwarded flag when forwarding msgs The maildir backend was ignoring the passed/forwarded flag. Allow for this flag to be set and synced to the server (if the server admits it). Changelog-added: The maildir backend now honors the forwarded/passed flag. Signed-off-by: inwit Acked-by: Robin Jarry --- worker/lib/maildir.go | 14 +++++++------- worker/maildir/message.go | 6 ++++++ worker/maildir/worker.go | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) (limited to 'worker') diff --git a/worker/lib/maildir.go b/worker/lib/maildir.go index a4a0ecd5..aada524f 100644 --- a/worker/lib/maildir.go +++ b/worker/lib/maildir.go @@ -119,16 +119,16 @@ var MaildirToFlag = map[maildir.Flag]models.Flags{ maildir.FlagTrashed: models.DeletedFlag, maildir.FlagFlagged: models.FlaggedFlag, maildir.FlagDraft: models.DraftFlag, - // maildir.FlagPassed Flag = 'P' + maildir.FlagPassed: models.ForwardedFlag, } var FlagToMaildir = map[models.Flags]maildir.Flag{ - models.AnsweredFlag: maildir.FlagReplied, - models.SeenFlag: maildir.FlagSeen, - models.DeletedFlag: maildir.FlagTrashed, - models.FlaggedFlag: maildir.FlagFlagged, - models.DraftFlag: maildir.FlagDraft, - // maildir.FlagPassed Flag = 'P' + models.AnsweredFlag: maildir.FlagReplied, + models.SeenFlag: maildir.FlagSeen, + models.DeletedFlag: maildir.FlagTrashed, + models.FlaggedFlag: maildir.FlagFlagged, + models.DraftFlag: maildir.FlagDraft, + models.ForwardedFlag: maildir.FlagPassed, } func FromMaildirFlags(maildirFlags []maildir.Flag) models.Flags { diff --git a/worker/maildir/message.go b/worker/maildir/message.go index 6bc54cac..1d8d26b9 100644 --- a/worker/maildir/message.go +++ b/worker/maildir/message.go @@ -62,6 +62,12 @@ func (m Message) SetOneFlag(flag maildir.Flag, enable bool) error { return m.SetFlags(newFlags) } +// MarkForwarded either adds or removes the maildir.FlagForwarded flag +// from the message. +func (m Message) MarkForwarded(forwarded bool) error { + return m.SetOneFlag(maildir.FlagPassed, forwarded) +} + // MarkReplied either adds or removes the maildir.FlagReplied flag from the // message. func (m Message) MarkReplied(answered bool) error { diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 7ff5093d..2c5bc893 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -317,6 +317,8 @@ func (w *Worker) handleMessage(msg types.WorkerMessage) error { return w.handleFlagMessages(msg) case *types.AnsweredMessages: return w.handleAnsweredMessages(msg) + case *types.ForwardedMessages: + return w.handleForwardedMessages(msg) case *types.CopyMessages: return w.handleCopyMessages(msg) case *types.MoveMessages: @@ -782,6 +784,27 @@ func (w *Worker) handleAnsweredMessages(msg *types.AnsweredMessages) error { return nil } +func (w *Worker) handleForwardedMessages(msg *types.ForwardedMessages) error { + for _, uid := range msg.Uids { + m, err := w.c.Message(*w.selected, uid) + if err != nil { + w.worker.Errorf("could not get message: %v", err) + w.err(msg, err) + continue + } + if err := m.MarkForwarded(msg.Forwarded); err != nil { + w.worker.Errorf("could not mark message as answered: %v", err) + w.err(msg, err) + continue + } + + w.worker.PostMessage(&types.DirectoryInfo{ + Info: w.getDirectoryInfo(w.selectedName), + }, nil) + } + return nil +} + func (w *Worker) handleFlagMessages(msg *types.FlagMessages) error { for _, uid := range msg.Uids { m, err := w.c.Message(*w.selected, uid) -- cgit