Short Post: Notmuch and NeoMutt - Issue When Sending Mail to Self

2024/10/28

Tags: Notmuch Neomutt Short Post

Short Post

Recently, I decided to dive into setting up Neomutt as my new email client. I quickly noticed that there are very few resources available when encountering issues related to those softwares. You know it when ChatGPT constantly provides configuration variables that don’t even exist in Neomutt when I seek help…

Anyway, I’ve decided to write a short post in hope it might help others. I might even plan to create more of these kinds of posts in the future - I have many small notes laying around in my Obsidian vault.

Notmuch Setup

Let’s get back to the main topic. If you use Neomutt, you’ve probably heard of Notmuch, an excellent tagging system that helps manage your emails.

I previously configured Notmuch to tag new emails for notifications and categorize them based on the recipient address. Here’s a snippet of my configuration:

notmuch tag +inbox +unread +fresh 'tag:new and folder:/INBOX.*/'
MAIL="[email protected]"
notmuch tag +me      "tag:new and (to:$MAIL or from:$MAIL or cc:$MAIL.com)"

All new emails in my inbox are tagged with +fresh. This allows my notification script to identify and notify me of fresh emails. Emails are further tagged based on the address, this helps me view emails in specific virtual boxes.

Fantastics!

Issue with Mail to Self

While testing some other feature with Neomutt, I sent myself an email for testing purposes. I noticed that the email I sent to myself never triggered notifications and wasn’t tagged correctly to my virtual box.

The issue stems from how Notmuch handles outgoing emails and new incoming emails. Notmuch treats emails with the same Message-ID as identical and refuses to process duplicates, causing them to bypass my notification filters.

Here’s what’s happening:

  1. I send an email to myself using Neomutt. Neomutt tags the email as sent and stores it in my record box (configured via nm_record="sent")

  2. goimapnotify detects the new email arriving on the IMAP server and invokes mbsync (or isync).

  3. mbsync fetches the email and places it in my inbox. Now, I have two identical copies of the email: one in record and one in inbox.

  4. When my processing script runs, Notmuch sees both emails but recognizes them as duplicates based on the Message-ID. As a result, it refuses to process the inbox copy since the copy in record already has a tag.

This behavior is rooted in Notmuch’s design, where tags are associated with Message-IDs rather than individual email instances. I learnt about this on a discussion here in the mailing list.

Fix

I realized that the solution was simple: add a +new tag to all my outgoing emails, which ensure that outgoing emails that arriving again in my inbox will still be processed by my script.