Hi,
TL;DR: magic recipe to include an HTML version when writing plaintext.
I know, I know, HTML email is "evil"[1]. I mostly never ever use it, in
fact, I don't remember the last time I consciously sent HTML. Maybe I
did so back when I was using Netscape Communicator[2][3], but whatever.
The reason I thought about this again is I have been doing more
photography these days and, well, being allergic to social media, I have
very few ways of sharing those photographs with families and friends. I
have tried creating a gallery website with an RSS feed but I'm sure no
one here will be surprised that the uptake is minimal, if
non-existent. People expect to have stuff *pushed* to them, like
Instagram, Facebook, Twitter or Spam does.
So I thought[4] of Email again: the original social network! I figured I
would just make a mailing list, and write to my people once in a while
to let them new about my new pictures. And while writing the first
email, I realized it was pretty silly to not include images, or at least
*links* to images in the email.
I'm sure you can see where this is going. A link in the email: who's
going to click that. Who clicks now anyways, with all the tapping[5]
going on. So the answer comes naturally: just write frigging HTML
email. Don't be a rms^Wreligious zealot and do the right thing, what
works basically everywhere[6] (even notmuch!).
So I started Thunderbird and thought "what the heck am I doing! there
must be a better way!" After searching for "message mode emacs html
email ktxbye", I found some people already thought about this problem
and came up with somewhat elegant solutions[7]. I built on that by
trying to come up with a pure elisp solution, which goes a little like
this:
(defun anarcat/notmuch-html-convert ()
"""create an HTML part from a Markdown body
This will not work if there are *any* attachments of any form, those should be added after."""
(interactive)
(save-excursion
;; wrap signature in a <pre>
(message-goto-signature)
(setq signature-position (point))
(forward-line -1)
;; GFM markers for pre, used because easier to undo than the
;; "prefix by 4 characters" standard
(insert "```")
(end-of-buffer)
(insert "```")
;; set region to top of body then end of buffer
(end-of-buffer)
(message-goto-body)
(narrow-to-region (point) (mark))
;; run markdown on region
(setq output-buffer-name "*notmuch-markdown-output*")
(markdown output-buffer-name)
(widen)
(save-excursion
(set-buffer output-buffer-name)
(markdown-add-xhtml-header-and-footer ""))
(insert "