Authentication-Results: mail-b.sr.ht; dkim=pass header.d=falsifian.org header.i=@falsifian.org Received: from exoco.falsifian.org (exoco.falsifian.org [168.235.109.198]) by mail-b.sr.ht (Postfix) with ESMTPS id E832411EEF7 for <~rjarry/aerc-devel@lists.sr.ht>; Sat, 20 Aug 2022 00:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=2020-07-31; bh=osLzpbwBF 3bXOb5uJn3JrAIeCxYMS73YzzHOnio+EJE=; h=references:in-reply-to:date: subject:cc:to:from; d=falsifian.org; b=xfcnnI4g8fHMqZeKBqiNU8F4HPdGwHo A+4FoMfBwC7N5eUl3Bl1ao18cIIWYr/l/y9mZDEIAphT2gaP8FUslAORiDKPSxSFtqivoN KJ1yq9Civ3rNrWDKww3oiBCO5kE4GPCy4k+rpUS0xjjHHaoPCs8QdxU3Lf4D7LjxK8apDa +pObJ7mUf+tsaR7HQZ4K8tKjMAswoZpxfCCRRxT9PFhsNMysHsXOEDD20i3sjvGWotYwAy 1FwdujkD2G+kDD4Ou+pIjzBOy32HRFRSrbHGGckG11fm6YsGefF0xNzzmHP1Xt2SPC6sO6 D6ZfLVtllNbGJLVskr2AXNj9+hjoHOw== Received: from moth.falsifian.org (cpef81d0f9cb2f3-cmf81d0f9cb2f0.cpe.net.fido.ca [72.140.58.252]) by exoco.falsifian.org (OpenSMTPD) with ESMTPSA id 5993fd4c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 20 Aug 2022 00:22:38 +0000 (UTC) Received: from localhost (moth.falsifian.org [local]) by moth.falsifian.org (OpenSMTPD) with ESMTPA id 099394c3; Sat, 20 Aug 2022 00:22:36 +0000 (UTC) From: James Cook To: ~rjarry/aerc-devel@lists.sr.ht Cc: James Cook Subject: [PATCH aerc] Use IMAP PEEK and allow not marking messages read. Date: Sat, 20 Aug 2022 00:22:18 +0000 Message-Id: <20220820002218.43914-1-falsifian@falsifian.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This commit adds a new configuration option, auto-mark-read, which defaults to true. When set to false, emails are not marked as seen when viewed. We also fetch BODY.PEEK[...] instead of BODY when fetching messages with IMAP. This means messages are only marked as read when we deliberately set the flag (which we automatically anyway, as long as auto-mark-read=true). I imagine before this change the export-mbox command caused all messages in an IMAP folder to be marked as seen. Fixes: https://todo.sr.ht/~rjarry/aerc/48 Signed-off-by: James Cook Squashed commit of the following: commit 9ca6eda82438c0ee0836afb91ec2be9cdce2b393 Author: James Cook Date: Fri Aug 19 23:51:26 2022 +0000 Use PEEK with IMAP. commit a49578363c989825fd2e1af1e404adcc8cf60d5a Author: James Cook Date: Fri Aug 19 22:55:48 2022 +0000 Post-merge fix: Pass UI config. commit b13b7be79c85a408dcb6c509fb7b6284e29ff9ee Merge: 8bfe752 1b91b68 Author: James Cook Date: Fri Aug 19 22:50:05 2022 +0000 Merge branch 'master' into unread commit 8bfe752c2807efaf37507c87fe00a568239e23b7 Author: James Cook Date: Tue Jul 5 05:38:38 2022 +0000 --- commands/account/view.go | 2 +- commands/msg/delete.go | 1 + commands/msg/recall.go | 2 +- commands/msgview/next.go | 2 +- config/aerc.conf | 6 ++++++ config/config.go | 2 ++ doc/aerc-config.5.scd | 5 +++++ lib/messageview.go | 7 +++++-- widgets/msglist.go | 2 +- worker/imap/fetch.go | 5 ++++- 10 files changed, 27 insertions(+), 7 deletions(-) diff --git a/commands/account/view.go b/commands/account/view.go index 8537d33..04a1687 100644 --- a/commands/account/view.go +++ b/commands/account/view.go @@ -46,7 +46,7 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error { return nil } lib.NewMessageStoreView(msg, store, aerc.Crypto, aerc.DecryptKeys, - func(view lib.MessageView, err error) { + acct.UiConfig(), func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) return diff --git a/commands/msg/delete.go b/commands/msg/delete.go index ceb570b..4c3b7f0 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -63,6 +63,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { return } lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys, + acct.UiConfig(), 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..578f910 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -137,7 +137,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { }) } - lib.NewMessageStoreView(msgInfo, store, aerc.Crypto, aerc.DecryptKeys, + lib.NewMessageStoreView(msgInfo, store, aerc.Crypto, aerc.DecryptKeys, acct.UiConfig(), 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..5114031 100644 --- a/commands/msgview/next.go +++ b/commands/msgview/next.go @@ -43,7 +43,7 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { return nil } lib.NewMessageStoreView(nextMsg, store, aerc.Crypto, aerc.DecryptKeys, - func(view lib.MessageView, err error) { + acct.UiConfig(), func(view lib.MessageView, err error) { if err != nil { aerc.PushError(err.Error()) return diff --git a/config/aerc.conf b/config/aerc.conf index fc6479a..0f03aa0 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -18,6 +18,12 @@ pgp-provider=internal unsafe-accounts-conf=false [ui] +# +# Set the "seen" flag when a message is viewed. +# +# Default: true +auto-mark-read=true + # # Describes the format for each row in a mailbox view. This field is compatible # with mutt's printf-like syntax. diff --git a/config/config.go b/config/config.go index 66c6dd1..cfabc44 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"` @@ -710,6 +711,7 @@ func LoadConfigFromFile(root *string) (*AercConfig, error) { }, Ui: UIConfig{ + AutoMarkRead: true, IndexFormat: "%D %-17.17n %s", TimestampFormat: "2006-01-02 03:04 PM", ThisDayTimeFormat: "", diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index aaf15b8..fe825de 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -97,6 +97,11 @@ These options are configured in the *[ui]* section of aerc.conf. | %Z : flags (O=old, N=new, r=answered, D=deleted, !=flagged, \*=marked) +*auto-mark-read* + Set the "seen" flag when a message is viewed. + + Default: true + *timestamp-format* See time.Time#Format at https://godoc.org/time#Time.Format diff --git a/lib/messageview.go b/lib/messageview.go index e0e86ea..597e58d 100644 --- a/lib/messageview.go +++ b/lib/messageview.go @@ -9,6 +9,7 @@ import ( "github.com/emersion/go-message" _ "github.com/emersion/go-message/charset" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/crypto" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/lib" @@ -62,7 +63,7 @@ type MessageStoreView struct { func NewMessageStoreView(messageInfo *models.MessageInfo, store *MessageStore, pgp crypto.Provider, decryptKeys openpgp.PromptFunction, - cb func(MessageView, error), + uiConfig *config.UIConfig, cb func(MessageView, error), ) { msv := &MessageStoreView{ messageInfo, store, @@ -99,7 +100,9 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, } else { cb(msv, nil) } - store.Flag([]uint32{messageInfo.Uid}, models.SeenFlag, true, nil) + if uiConfig.AutoMarkRead { + 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 e431c2e..dfd6f34 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -307,7 +307,7 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) { return } lib.NewMessageStoreView(msg, store, ml.aerc.Crypto, - ml.aerc.DecryptKeys, + ml.aerc.DecryptKeys, acct.UiConfig(), 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 f21c6e9..0d2bb16 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -91,6 +91,7 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( partHeaderSection.Path = msg.Part var partBodySection imap.BodySectionName + partBodySection.Peek = true if len(msg.Part) > 0 { partBodySection.Specifier = imap.EntireSpecifier } else { @@ -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, -- 2.37.2