From fbddb86b7bbdedafbc20b4655c3a1de03564e12c Mon Sep 17 00:00:00 2001 From: arclayto Date: Tue, 3 Mar 2026 23:09:45 -0600 Subject: [PATCH] fix: mark emails as read when opened (#233) Add MarkEmailAsRead() that sets the IMAP \Seen flag via UidStore. Called from FetchEmailBodyFromMailbox() after successfully fetching the email body. Uses the existing BODY.PEEK[] fetch to keep fetch and flag-setting separate. Fixes #232 --- fetcher/fetcher.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index 35fd10373da0350c9f02d7191ff248feb90fcf6b..6f076a9405d59637c744d2086adafc55a3b4b040 100644 --- a/fetcher/fetcher.go +++ b/fetcher/fetcher.go @@ -791,9 +791,29 @@ func FetchEmailBodyFromMailbox(account *config.Account, mailbox string, uid uint } } + MarkEmailAsRead(account, mailbox, uid) + return body, attachments, nil } +func MarkEmailAsRead(account *config.Account, mailbox string, uid uint32) error { + c, err := connect(account) + if err != nil { + return err + } + defer c.Logout() + + if _, err := c.Select(mailbox, false); err != nil { + return err + } + + seqSet := new(imap.SeqSet) + seqSet.AddNum(uid) + item := imap.FormatFlagsOp(imap.AddFlags, true) + flags := []interface{}{imap.SeenFlag} + return c.UidStore(seqSet, item, flags, nil) +} + func FetchAttachmentFromMailbox(account *config.Account, mailbox string, uid uint32, partID string, encoding string) ([]byte, error) { c, err := connect(account) if err != nil {