<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">I appreciate the signature handling. But perhaps you used it on this message and it ate part of this line?<div><br></div><div><blockquote type="cite"><div dir="ltr"><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);">(insert "</span></font></div></blockquote><blockquote type="cite"><div dir="ltr"><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);"> ;; remove Markdown <pre> markings</span></font></div></blockquote><br><div id="AppleMailSignature" dir="ltr">-- <div>Brian Sniffen</div></div><div dir="ltr"><br>On Feb 24, 2019, at 8:52 PM, Antoine Beaupré <<a href="mailto:anarcat@orangeseeds.org">anarcat@orangeseeds.org</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><span>Hi,</span><br><span></span><br><span>TL;DR: magic recipe to include an HTML version when writing plaintext.</span><br><span></span><br><span>I know, I know, HTML email is "evil"[1]. I mostly never ever use it, in</span><br><span>fact, I don't remember the last time I consciously sent HTML. Maybe I</span><br><span>did so back when I was using Netscape Communicator[2][3], but whatever.</span><br><span></span><br><span>The reason I thought about this again is I have been doing more</span><br><span>photography these days and, well, being allergic to social media, I have</span><br><span>very few ways of sharing those photographs with families and friends. I</span><br><span>have tried creating a gallery website with an RSS feed but I'm sure no</span><br><span>one here will be surprised that the uptake is minimal, if</span><br><span>non-existent. People expect to have stuff *pushed* to them, like</span><br><span>Instagram, Facebook, Twitter or Spam does.</span><br><span></span><br><span>So I thought[4] of Email again: the original social network! I figured I</span><br><span>would just make a mailing list, and write to my people once in a while</span><br><span>to let them new about my new pictures. And while writing the first</span><br><span>email, I realized it was pretty silly to not include images, or at least</span><br><span>*links* to images in the email.</span><br><span></span><br><span>I'm sure you can see where this is going. A link in the email: who's</span><br><span>going to click that. Who clicks now anyways, with all the tapping[5]</span><br><span>going on. So the answer comes naturally: just write frigging HTML</span><br><span>email. Don't be a rms^Wreligious zealot and do the right thing, what</span><br><span>works basically everywhere[6] (even notmuch!).</span><br><span></span><br><span>So I started Thunderbird and thought "what the heck am I doing! there</span><br><span>must be a better way!" After searching for "message mode emacs html</span><br><span>email ktxbye", I found some people already thought about this problem</span><br><span>and came up with somewhat elegant solutions[7]. I built on that by</span><br><span>trying to come up with a pure elisp solution, which goes a little like</span><br><span>this:</span><br><span></span><br><span>(defun anarcat/notmuch-html-convert ()</span><br><span> """create an HTML part from a Markdown body</span><br><span></span><br><span>This will not work if there are *any* attachments of any form, those should be added after."""</span><br><span> (interactive)</span><br><span> (save-excursion</span><br><span> ;; wrap signature in a <pre></span><br><span> (message-goto-signature)</span><br><span> (setq signature-position (point))</span><br><span> (forward-line -1)</span><br><span> ;; GFM markers for pre, used because easier to undo than the</span><br><span> ;; "prefix by 4 characters" standard</span><br><span> (insert "```")</span><br><span> (end-of-buffer)</span><br><span> (insert "```")</span><br><span> ;; set region to top of body then end of buffer</span><br><span> (end-of-buffer)</span><br><span> (message-goto-body)</span><br><span> (narrow-to-region (point) (mark))</span><br><span> ;; run markdown on region</span><br><span> (setq output-buffer-name "*notmuch-markdown-output*")</span><br><span> (markdown output-buffer-name)</span><br><span> (widen)</span><br><span> (save-excursion</span><br><span> (set-buffer output-buffer-name)</span><br><span> (markdown-add-xhtml-header-and-footer ""))</span><br><span> (insert "</span></div></blockquote><blockquote type="cite"><div dir="ltr">\n")
(insert-buffer output-buffer-name)
(insert "</div></blockquote><blockquote type="cite"><div dir="ltr"><span> ;; remove Markdown <pre> markings</span><br><span> (goto-char signature-position)</span><br><span> (while (re-search-forward "^```" nil t)</span><br><span> (replace-match ""))))</span><br><span></span><br><span>For those who can't read elisp for breakfast, this does the following:</span><br><span></span><br><span> 1. parse the current email body as markdown, in a separate buffer</span><br><span> 2. make the current email multipart/alternative</span><br><span> 3. add an HTML part</span><br><span> 4. inject the HTML version in the HTML part</span><br><span></span><br><span>There's some nasty business with formatting the signature correctly by</span><br><span>wrapping it in a <pre> that's going on there - I took that from</span><br><span>Thunderbird as well.</span><br><span></span><br><span>(For those who *do* read elisp for breakfast, improvements and comments</span><br><span>on the coding style are very welcome.)</span><br><span></span><br><span>The idea is that you write your email normally, but in markdown. When</span><br><span>you're done writing that email, you launch the above function (carefully</span><br><span>bound to "M-x anarcat/notmuch-html-convert" here) which takes that email</span><br><span>and adds an equivalent HTML part to it. You can then even tweak that</span><br><span>part to screw around with the raw HTML if you feel depressed or</span><br><span>nostalgic.</span><br><span></span><br><span>What do people think? Am I insane? Could this work? Does this belong in</span><br><span>notmuch? Or maybe in the tips section? Should I seek therapy? Do you</span><br><span>hate markdown? Expand on the relationship between your parents and text</span><br><span>editors.</span><br><span></span><br><span>Thanks for any feedback,</span><br><span></span><br><span>A.</span><br><span></span><br><span>PS: the above, naturally, could be adapted to parse the body as RST,</span><br><span>asciidoc, texinfo, latex or whatever insanity you think would be more</span><br><span>appropriate, I don't care. The idea is the same.</span><br><span></span><br><span>PPS: I remember reading about someone wanting to declare a text/markdown</span><br><span>mimetype for email, and remembering it was all backwards and weird and I</span><br><span>can't find the reference anymore. If some lazyweb magic person could</span><br><span>forward the link to me I would be grateful.</span><br><span></span><br><span> [1]: one of so many: <a href="https://www.georgedillon.com/web/html_email_is_evil_still.shtml">https://www.georgedillon.com/web/html_email_is_evil_still.shtml</a></span><br><span> [2]: <a href="https://en.wikipedia.org/wiki/Netscape_Communicator">https://en.wikipedia.org/wiki/Netscape_Communicator</a></span><br><span> [3]: yes my age is showing</span><br><span> [4]: to be fair, this article encouraged me quite a bit:</span><br><span> <a href="https://blog.chaddickerson.com/2019/01/09/replacing-facebook/">https://blog.chaddickerson.com/2019/01/09/replacing-facebook/</a></span><br><span> [5]: not the bass guitar one, unfortunately</span><br><span> [6]: <a href="https://en.wikipedia.org/wiki/HTML_email#Adoption">https://en.wikipedia.org/wiki/HTML_email#Adoption</a></span><br><span> [7]: <a href="https://trey-jackson.blogspot.com/2008/01/emacs-tip-8-markdown.html">https://trey-jackson.blogspot.com/2008/01/emacs-tip-8-markdown.html</a></span><br></div></blockquote><blockquote type="cite"><div dir="ltr"><span>_______________________________________________</span><br><span>notmuch mailing list</span><br><span><a href="mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a></span><br><span><a href="https://notmuchmail.org/mailman/listinfo/notmuch">https://notmuchmail.org/mailman/listinfo/notmuch</a></span><br></div></blockquote></div></body></html>