aboutsummaryrefslogtreecommitdiffstats
path: root/worker/maildir/message.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/maildir/message.go')
-rw-r--r--worker/maildir/message.go36
1 files changed, 11 insertions, 25 deletions
diff --git a/worker/maildir/message.go b/worker/maildir/message.go
index 5c6c9307..55e2613b 100644
--- a/worker/maildir/message.go
+++ b/worker/maildir/message.go
@@ -53,43 +53,29 @@ func (m Message) SetFlags(flags []maildir.Flag) error {
return m.dir.SetFlags(m.key, flags)
}
-// MarkReplied either adds or removes the maildir.FlagReplied flag from the
-// message.
-func (m Message) MarkReplied(answered bool) error {
+// SetOneFlag enables or disables a single message flag on the message.
+func (m Message) SetOneFlag(flag maildir.Flag, enable bool) error {
flags, err := m.Flags()
if err != nil {
return fmt.Errorf("could not read previous flags: %v", err)
}
- if answered {
- flags = append(flags, maildir.FlagReplied)
+ if enable {
+ flags = append(flags, flag)
return m.SetFlags(flags)
}
var newFlags []maildir.Flag
- for _, flag := range flags {
- if flag != maildir.FlagReplied {
- newFlags = append(newFlags, flag)
+ for _, oldFlag := range flags {
+ if oldFlag != flag {
+ newFlags = append(newFlags, oldFlag)
}
}
return m.SetFlags(newFlags)
}
-// MarkRead either adds or removes the maildir.FlagSeen flag from the message.
-func (m Message) MarkRead(seen bool) error {
- flags, err := m.Flags()
- if err != nil {
- return fmt.Errorf("could not read previous flags: %v", err)
- }
- if seen {
- flags = append(flags, maildir.FlagSeen)
- return m.SetFlags(flags)
- }
- var newFlags []maildir.Flag
- for _, flag := range flags {
- if flag != maildir.FlagSeen {
- newFlags = append(newFlags, flag)
- }
- }
- return m.SetFlags(newFlags)
+// MarkReplied either adds or removes the maildir.FlagReplied flag from the
+// message.
+func (m Message) MarkReplied(answered bool) error {
+ return m.SetOneFlag(maildir.FlagReplied, answered)
}
// Remove deletes the email immediately.