From 6271d455eb7d72ca2942e3721721be54fed27779 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 9 Jun 2019 14:55:34 -0400 Subject: Add :read and :unread commands --- worker/imap/flags.go | 17 +++++++++++++++++ worker/imap/worker.go | 2 ++ worker/types/messages.go | 7 +++++++ 3 files changed, 26 insertions(+) (limited to 'worker') diff --git a/worker/imap/flags.go b/worker/imap/flags.go index bd368c1..0122d8e 100644 --- a/worker/imap/flags.go +++ b/worker/imap/flags.go @@ -41,3 +41,20 @@ func (imapw *IMAPWorker) handleDeleteMessages(msg *types.DeleteMessages) { imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) } } + +func (imapw *IMAPWorker) handleReadMessages(msg *types.ReadMessages) { + item := imap.FormatFlagsOp(imap.AddFlags, true) + flags := []interface{}{imap.SeenFlag} + if !msg.Read { + item = imap.FormatFlagsOp(imap.RemoveFlags, true) + flags = []interface{}{imap.SeenFlag} + } + if err := imapw.client.UidStore(&msg.Uids, item, flags, nil); err != nil { + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + return + } + imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) +} diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 373072b..d978755 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -137,6 +137,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { w.handleFetchFullMessages(msg) case *types.DeleteMessages: w.handleDeleteMessages(msg) + case *types.ReadMessages: + w.handleReadMessages(msg) case *types.CopyMessages: w.handleCopyMessages(msg) case *types.AppendMessage: diff --git a/worker/types/messages.go b/worker/types/messages.go index 0d81c4f..fa4b4e4 100644 --- a/worker/types/messages.go +++ b/worker/types/messages.go @@ -108,6 +108,13 @@ type DeleteMessages struct { Uids imap.SeqSet } +// Marks messages as read or unread +type ReadMessages struct { + Message + Read bool + Uids imap.SeqSet +} + type CopyMessages struct { Message Destination string -- cgit 1.4.1-2-gfad0