From 6ff3c7a1ba680506d77fc1fe8dfbf5b804a3fea7 Mon Sep 17 00:00:00 2001 From: Galen Abell Date: Tue, 3 Mar 2020 08:45:06 -0500 Subject: Mark sent messages as "seen" in maildir - Add maildir flags to complement a messages imap flags - Set the "seen" flag on sent messages when using the maildir backend - Cleanup AppendMessage interface to use models.Flag for both IMAP and maildir --- worker/maildir/message.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'worker/maildir/message.go') diff --git a/worker/maildir/message.go b/worker/maildir/message.go index 45b1ca6..9d622b4 100644 --- a/worker/maildir/message.go +++ b/worker/maildir/message.go @@ -45,7 +45,7 @@ func (m Message) ModelFlags() ([]models.Flag, error) { if err != nil { return nil, err } - return translateFlags(flags), nil + return translateMaildirFlags(flags), nil } // SetFlags replaces the message's flags with a new set. @@ -97,7 +97,7 @@ func (m Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) { return lib.FetchEntityPartReader(msg, requestedParts) } -var flagMap = map[maildir.Flag]models.Flag{ +var maildirToFlag = map[maildir.Flag]models.Flag{ maildir.FlagReplied: models.AnsweredFlag, maildir.FlagSeen: models.SeenFlag, maildir.FlagTrashed: models.DeletedFlag, @@ -106,16 +106,35 @@ var flagMap = map[maildir.Flag]models.Flag{ // maildir.FlagPassed Flag = 'P' } -func translateFlags(maildirFlags []maildir.Flag) []models.Flag { +var flagToMaildir = map[models.Flag]maildir.Flag{ + models.AnsweredFlag: maildir.FlagReplied, + models.SeenFlag: maildir.FlagSeen, + models.DeletedFlag: maildir.FlagTrashed, + models.FlaggedFlag: maildir.FlagFlagged, + // maildir.FlagDraft Flag = 'D' + // maildir.FlagPassed Flag = 'P' +} + +func translateMaildirFlags(maildirFlags []maildir.Flag) []models.Flag { var flags []models.Flag for _, maildirFlag := range maildirFlags { - if flag, ok := flagMap[maildirFlag]; ok { + if flag, ok := maildirToFlag[maildirFlag]; ok { flags = append(flags, flag) } } return flags } +func translateFlags(flags []models.Flag) []maildir.Flag { + var maildirFlags []maildir.Flag + for _, flag := range flags { + if maildirFlag, ok := flagToMaildir[flag]; ok { + maildirFlags = append(maildirFlags, maildirFlag) + } + } + return maildirFlags +} + func (m Message) UID() uint32 { return m.uid } -- cgit 1.4.1-2-gfad0