Notmuch Save Mail as .eml

Short intro

Is there still a need to present an excellent productivity tool like NomuchMail?

Notmuch is a small program that indexes emails, tags and allows to search the different Maildir folders in a very fast way.

Personally, I don’t use much the tags, except the standard IMAP’s ones, like Sent, Passed, Replied, flagged…, which are automatically synced by mbsync/isync to the mailbox and across all the mail clients. For such reason, Notmuchmail is for me a search tool engine with a powerful query syntax to quickly filter and narrow down the information I am looking for.

The problem

Recently I wanted to archive a specific email and save it as part of the project information. My first reflex was to look at the online manual available in my Emacs.

So my muscle memory quickly entered the key-chords C-h m to get the list of available functions. Filtering with the save keyword, none of the descriptions matched what I was looking for:

4 matches in 3 lines for "save" in buffer: *Help*
     88:w               notmuch-show-save-attachments
    107:. s             notmuch-show-save-part
    712:<remap> <kill-ring-save>        ivy-kill-ring-save

I thought it could have been an undocumented function, so I used swiper to filter on the interactive ones, even though nothing relevant came out:

( 1/3 ) M-x ^notmuch sav 
notmuch-show-save-attachments       Save all attachments from the current message.
notmuch-show-save-part              Save the MIME part containing point to a file.
notmuch-draft-save                  Save the current draft message in the notmuch database.

I quickly went to the Notmuch Emacs Interface tips on the official website, but unfortunately I couldn’t find anything relevant.

The solution

It is only after searching on the web that I ended up on the thread from the Notmuch mailing list where the suggestion was to pipe the email with the function:

|      notmuch-show-pipe-message

notmuch-show-pipe-message

So, applied to the specific email:

| cat > /tmp/my-email.eml

And there is was! I could have the exact content of my Maildir email saved-as to a specific filename which could then be archived alongside the project and ready to be opened by any other mail client.

Although there is nothing complicated in this action, it would be interesting to understand the reason why there is no such thing as notmuch-show-save-as available out of the box.

It is also true that in all the years I have been using the Notmuch engine and front-end I almost never came across the necessity to export an email.

External references

  1. https://notmuchmail.org/
  2. https://isync.sourceforge.io/