Sending multipart/alternative with mutt

I'd like the option for certain emails and/or recipients to have a script run before sending (whether automatically or by pressing a keybinding) which takes my text/plain, runs a script over it, and then attaches the output of that script with the text/html type, setting the whole message to multipart/alternative.

Side ramble: It might be nice if this happened automatically immediately before sending but only if the body type was currently set to text/markdown, as this would mean the pending email is never in a state where I edit the source again but forget to regenerate the HTML, and I still have the option to send only text/plain. Then I'd have another binding to set the content type of the body to text/markdown, so that this would be picked up. But then I also have the issue that a lot of mail clients (Gmail included) refuse to render text/markdown (even as plain text), instead offering it as a download, so I'd need to have the content type of the source part switched back to text/plain.

Is such a thing possible with mutt?

Sadly as far as I can tell mutt doesn't support sending multipart/alternative messages, refusing to send anything but multipart/mixed, but I'd love to be shown I'm wrong.

The best solution I've been able to come up with is this macro:

macro compose M "<filter-entry>commonmark<return>y<edit-type><kill-line>text/html<return>" "convert message to HTML with Commonmark"

There are a few issues with this:

  • It entirely replaces the original plain text, so it's then much harder to edit
  • I don't like that there's the y in the macro to say yes to the dialog asking whether it's okay to overwrite the file
  • I have to press return after this runs
  • And of course the main thing: it doesn't send the plain text alternative

Is there a better solution?

I'm potentially open to another text-mode mail client, as long as it

  • is usable with Google Apps, and syncs flags etc in both directions
  • supports GPG
  • has vim-like bindings, or I can configure them
  • lets me use vim as a message editor
  • has a threaded message view
  • allows me to filter/search mail in a somewhat sophisticated way (sender, recipient, presence of attachments, subject and body text search)
  • handles attachment types a bit like mutt, i.e. mailcap or equivalent so I can run incoming HTML mail through lynx, or press something to open it in the graphical browser if need be, I can launch image viewers at a button press, and so on

Solution 1:

I forgot about NeoMutt supports multipart. https://neomutt.org/guide/mimesupport.