From e4d418eed15858d6dcae70e73b8a6c3e4439b5bc Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 3 Oct 2022 23:56:06 +0200 Subject: [PATCH] viewer: option to not mark message as seen Add option to open a message in the message viewer without setting the seen flag. Enables the message viewer to be used as a preview pane without changing the message flags unintentionally. Before, the message viewer would set the seen flag by default. The IMAP backend will now always fetch the message body with the peek option enabled (same as we fetch the headers). An "auto-mark-read" option is added to the ui config which is set to true by default. If set the false, the seen flag is not set by the message viewer. Co-authored-by: "James Cook" Signed-off-by: Koni Marti Acked-by: Robin Jarry --- commands/account/view.go | 3 ++- commands/msg/archive.go | 3 ++- commands/msg/delete.go | 3 ++- commands/msg/recall.go | 3 ++- commands/msgview/next.go | 3 ++- config/aerc.conf | 6 ++++++ config/config.go | 2 ++ doc/aerc-config.5.scd | 5 +++++ lib/messageview.go | 6 ++++-- widgets/msglist.go | 4 ++-- worker/imap/fetch.go | 5 ++++- 11 files changed, 33 insertions(+), 10 deletions(-) diff --git a/commands/account/view.go b/commands/account/view.go index 8537d33..be8b45e 100644 --- a/commands/account/view.go +++ b/commands/account/view.go @@ -45,7 +45,8 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error { aerc.PushError(msg.Error.Error()) return nil } - lib.NewMessageStoreView(msg, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(msg, acct.UiConfig().AutoMarkRead, + store, aerc.Crypto, aerc.DecryptKeys, func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) diff --git a/commands/msg/archive.go b/commands/msg/archive.go index f7baff0..2935991 100644 --- a/commands/msg/archive.go +++ b/commands/msg/archive.go @@ -120,7 +120,8 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error { acct.Messages().Invalidate() return } - lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(next, acct.UiConfig().AutoMarkRead, + store, aerc.Crypto, aerc.DecryptKeys, func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) diff --git a/commands/msg/delete.go b/commands/msg/delete.go index ee682a4..57cef34 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -63,7 +63,8 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { acct.Messages().Invalidate() return } - lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(next, acct.UiConfig().AutoMarkRead, + store, aerc.Crypto, aerc.DecryptKeys, func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) diff --git a/commands/msg/recall.go b/commands/msg/recall.go index 5fc3a26..4ef505e 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -137,7 +137,8 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { }) } - lib.NewMessageStoreView(msgInfo, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(msgInfo, acct.UiConfig().AutoMarkRead, + store, aerc.Crypto, aerc.DecryptKeys, func(msg lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) diff --git a/commands/msgview/next.go b/commands/msgview/next.go index c80e0ab..b9e5dbd 100644 --- a/commands/msgview/next.go +++ b/commands/msgview/next.go @@ -42,7 +42,8 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { aerc.RemoveTab(mv) return nil } - lib.NewMessageStoreView(nextMsg, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(nextMsg, acct.UiConfig().AutoMarkRead, + store, aerc.Crypto, aerc.DecryptKeys, func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) diff --git a/config/aerc.conf b/config/aerc.conf index 0bd96fb..1f9c802 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -130,6 +130,12 @@ sort= # Default: true next-message-on-delete=true +# Automatically set the "seen" flag when a message is opened in the message +# viewer. +# +# Default: true +auto-mark-read=true + # The directories where the stylesets are stored. It takes a colon-separated # list of directories. If this is unset or if a styleset cannot be found, the # following paths will be used as a fallback in that order: diff --git a/config/config.go b/config/config.go index e31d1a1..faaab61 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,7 @@ type GeneralConfig struct { } type UIConfig struct { + AutoMarkRead bool `ini:"auto-mark-read"` IndexFormat string `ini:"index-format"` TimestampFormat string `ini:"timestamp-format"` ThisDayTimeFormat string `ini:"this-day-time-format"` @@ -746,6 +747,7 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) { }, Ui: UIConfig{ + AutoMarkRead: true, IndexFormat: "%-20.20D %-17.17n %Z %s", TimestampFormat: "2006-01-02 03:04 PM", ThisDayTimeFormat: "", diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index 9eb8790..78a39e3 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -218,6 +218,11 @@ These options are configured in the *[ui]* section of aerc.conf. Default: true +*auto-mark-read* + Set the "seen" flag when a message is opened in the message viewer. + + Default: true + *completion-popovers* Shows potential auto-completions for text inputs in popovers. diff --git a/lib/messageview.go b/lib/messageview.go index ff754a4..d774f4f 100644 --- a/lib/messageview.go +++ b/lib/messageview.go @@ -58,7 +58,7 @@ type MessageStoreView struct { bodyStructure *models.BodyStructure } -func NewMessageStoreView(messageInfo *models.MessageInfo, +func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool, store *MessageStore, pgp crypto.Provider, decryptKeys openpgp.PromptFunction, cb func(MessageView, error), ) { @@ -97,7 +97,9 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, } else { cb(msv, nil) } - store.Flag([]uint32{messageInfo.Uid}, models.SeenFlag, true, nil) + if setSeen { + store.Flag([]uint32{messageInfo.Uid}, models.SeenFlag, true, nil) + } } func (msv *MessageStoreView) MessageInfo() *models.MessageInfo { diff --git a/widgets/msglist.go b/widgets/msglist.go index ba09a8e..74308cc 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -308,8 +308,8 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) { if msg == nil { return } - lib.NewMessageStoreView(msg, store, ml.aerc.Crypto, - ml.aerc.DecryptKeys, + lib.NewMessageStoreView(msg, acct.UiConfig().AutoMarkRead, + store, ml.aerc.Crypto, ml.aerc.DecryptKeys, func(view lib.MessageView, err error) { if err != nil { ml.aerc.PushError(err.Error()) diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 79c9148..3b9c786 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -94,6 +94,7 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( partBodySection.Specifier = imap.TextSpecifier } partBodySection.Path = msg.Part + partBodySection.Peek = true items := []imap.FetchItem{ imap.FetchEnvelope, @@ -150,7 +151,9 @@ func (imapw *IMAPWorker) handleFetchFullMessages( msg *types.FetchFullMessages, ) { logging.Infof("Fetching full messages: %v", msg.Uids) - section := &imap.BodySectionName{} + section := &imap.BodySectionName{ + Peek: true, + } items := []imap.FetchItem{ imap.FetchEnvelope, imap.FetchFlags,