From 7898def044f3c0deaf2b65f4f1f15bc6254e8027 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Sun, 4 Jan 2026 12:23:39 -0800 Subject: [PATCH] Fix notmuch inbox tag to match IMAP INBOX folder Previously, the notmuch config applied the "inbox" tag to all new messages regardless of which IMAP folder they were in. This caused tag:inbox to return all 22k+ messages instead of just those in INBOX. Changes: - Use temporary "new" tag instead of "inbox" for newly indexed messages - Add post-new hook that applies tags based on maildir folder location - inbox tag now only applies to messages in INBOX folder - Also adds sent, draft, spam, deleted, and archive tags based on folder --- home/roles/email/default.nix | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/home/roles/email/default.nix b/home/roles/email/default.nix index 234aac1..6ba2366 100644 --- a/home/roles/email/default.nix +++ b/home/roles/email/default.nix @@ -62,7 +62,7 @@ in primary_email=john@ogle.fyi [new] - tags=unread;inbox; + tags=unread;new; ignore= [search] @@ -72,6 +72,38 @@ in synchronize_flags=true ''; + # Notmuch post-new hook for folder-based tagging + home.file."Mail/.notmuch/hooks/post-new" = { + executable = true; + text = '' + #!${pkgs.bash}/bin/bash + # Tag messages based on their maildir folder location + # This runs after 'notmuch new' indexes new messages + + # Process only messages with the 'new' tag (just indexed) + # Add inbox tag only for messages in INBOX folder + ${pkgs.notmuch}/bin/notmuch tag +inbox -- tag:new AND folder:INBOX + + # Add sent tag for messages in Sent folder + ${pkgs.notmuch}/bin/notmuch tag +sent -inbox -- tag:new AND folder:Sent + + # Add draft tag for messages in Drafts folder + ${pkgs.notmuch}/bin/notmuch tag +draft -inbox -- tag:new AND folder:Drafts + + # Add spam tag for messages in Spam folder + ${pkgs.notmuch}/bin/notmuch tag +spam -inbox -unread -- tag:new AND folder:Spam + + # Add deleted tag for messages in Trash folder + ${pkgs.notmuch}/bin/notmuch tag +deleted -inbox -unread -- tag:new AND folder:Trash + + # Add archive tag for messages in Archive folder + ${pkgs.notmuch}/bin/notmuch tag +archive -inbox -- tag:new AND folder:Archive + + # Remove the temporary 'new' tag from all messages + ${pkgs.notmuch}/bin/notmuch tag -new -- tag:new + ''; + }; + # msmtp configuration home.file.".msmtprc".text = '' # Default settings