From ee3b6d7324a8b77621ee4bac8b07a5db039bde6a Mon Sep 17 00:00:00 2001 From: EmilyxFox <48589793+EmilyxFox@users.noreply.github.com> Date: Thu, 30 Apr 2026 18:05:36 +0200 Subject: [PATCH] fix(daemon): notify only when new mail (#1205) ## What? Fixes notifications every 5 minutes whether or not there are new emails ## Why? notifications were sent consistently, when not intended --- daemon/daemon.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 1963df48f0e32dc814070dd2bfa067fe5f0aae20..f4833ea8570f688d90f8b197974bdd1bd13c4c51 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -348,6 +348,14 @@ func (d *Daemon) syncAllAccounts(ctx context.Context) { continue } + oldCached, _ := config.LoadFolderEmailCache("INBOX") + oldUIDs := make(map[uint32]struct{}, len(oldCached)) + for _, e := range oldCached { + if e.AccountID == acct.ID { + oldUIDs[e.UID] = struct{}{} + } + } + // Cache the fetched emails to disk. var cached []config.CachedEmail for _, e := range emails { @@ -372,14 +380,21 @@ func (d *Daemon) syncAllAccounts(ctx context.Context) { EmailCount: len(emails), }) + newCount := 0 + for _, e := range emails { + if _, seen := oldUIDs[e.UID]; !seen { + newCount++ + } + } + // Send desktop notification if TUI not connected. d.mu.RLock() noClients := len(d.clients) == 0 d.mu.RUnlock() - if noClients && len(emails) > 0 { + if noClients && newCount > 0 { if !d.config.DisableNotifications { - go notify.Send("Matcha", fmt.Sprintf("New mail for %s", acct.Email)) + go notify.Send("Matcha", fmt.Sprintf("New mail for %s", acct.FetchEmail)) } } }