aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands/msg/read.go38
-rw-r--r--lib/msgstore.go14
-rw-r--r--worker/imap/flags.go17
-rw-r--r--worker/imap/worker.go2
-rw-r--r--worker/types/messages.go7
5 files changed, 78 insertions, 0 deletions
diff --git a/commands/msg/read.go b/commands/msg/read.go
new file mode 100644
index 0000000..9844797
--- /dev/null
+++ b/commands/msg/read.go
@@ -0,0 +1,38 @@
+package msg
+
+import (
+ "errors"
+ "time"
+
+ "github.com/gdamore/tcell"
+
+ "git.sr.ht/~sircmpwn/aerc/widgets"
+ "git.sr.ht/~sircmpwn/aerc/worker/types"
+)
+
+func init() {
+ register("read", Read)
+ register("unread", Read)
+}
+
+func Read(aerc *widgets.Aerc, args []string) error {
+ if len(args) != 1 {
+ return errors.New("Usage: " + args[0])
+ }
+
+ widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+ msg := widget.SelectedMessage()
+ store := widget.Store()
+ store.Read([]uint32{msg.Uid}, args[0] == "read", func(
+ msg types.WorkerMessage) {
+
+ switch msg := msg.(type) {
+ case *types.Done:
+ aerc.PushStatus("Messages updated.", 10*time.Second)
+ case *types.Error:
+ aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
+ Color(tcell.ColorDefault, tcell.ColorRed)
+ }
+ })
+ return nil
+}
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 56725e3..5b4d540 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -265,3 +265,17 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
store.update()
}
+
+func (store *MessageStore) Read(uids []uint32, read bool,
+ cb func(msg types.WorkerMessage)) {
+
+ var set imap.SeqSet
+ for _, uid := range uids {
+ set.AddNum(uid)
+ }
+
+ store.worker.PostAction(&types.ReadMessages{
+ Read: read,
+ Uids: set,
+ }, cb)
+}
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