From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 26ED66DE0F66 for ; Sun, 24 Feb 2019 18:02:40 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.303 X-Spam-Level: X-Spam-Status: No, score=-0.303 tagged_above=-999 required=5 tests=[AWL=-0.103, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PYvd-JiP8HRR for ; Sun, 24 Feb 2019 18:02:37 -0800 (PST) X-Greylist: delayed 590 seconds by postgrey-1.36 at arlo; Sun, 24 Feb 2019 18:02:36 PST Received: from marcos.anarc.at (marcos.anarc.at [206.248.172.91]) by arlo.cworth.org (Postfix) with ESMTPS id EF46F6DE0EB0 for ; Sun, 24 Feb 2019 18:02:36 -0800 (PST) Received: by marcos.anarc.at (Postfix, from userid 1000) id B9BAA10E051; Sun, 24 Feb 2019 20:52:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=orangeseeds.org; s=marcos; t=1551059560; bh=nJmH1INzH/5sQPhyzWQQg7umrYRHCqmca+g+G7WW+yg=; h=From:To:Subject:Date:From; b=iM/MMN3expUmJgj78vzUFaOumYYWGCvrcnxaPiJ08UCScA2m6KJKLtNNm0fjLMH8G BvQGBpwQcOsCLL63tpdz+5/ivxMiN8aTYqs8O4tKnchjnqTVNze9HsFdFvqIMRjUzd 4mS/SLtJMmjr8ZV6ujCcHadonqww9RdIiApNjM5G6jJhhWzuFDavTCPYL3/N86FQ1v upjjuEgkXYKz1ASf3zIgiZWu5O1MPJHjvtGII7IR8D8DKaZI6HKRcrHFpvkKe8grpy g2txQxjPBMTpDk38UijhJ/2VoG9n0rohIZs8TMd6SekGSihlVXkzxlxD0Jl+v4vjhO MB626l3235Z9A== Received: by curie.anarc.at (Postfix, from userid 1000) id 57A9F12D270; Sun, 24 Feb 2019 20:52:40 -0500 (EST) From: =?utf-8?Q?Antoine_Beaupr=C3=A9?= To: notmuch@notmuchmail.org Subject: [RFC] writing HTML email with notmuch Date: Sun, 24 Feb 2019 20:52:40 -0500 Message-ID: <875zt8zlav.fsf@curie.anarc.at> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Feb 2019 02:02:40 -0000 --=-=-= Content-Type: text/plain 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
    (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 "
--=-=-=
Content-Type: multipart/alternative; boundary="==-=-="

--==-=-=
Content-Type: text/plain

\n")
    (end-of-buffer)
    (insert "
--==-=-=
Content-Type: text/html

\n")
    (insert-buffer output-buffer-name)
    (insert "
--==-=-=--

--=-=-=
Content-Type: text/plain

    ;; remove Markdown 
 markings
    (goto-char signature-position)
    (while (re-search-forward "^```" nil t)
      (replace-match ""))))

For those who can't read elisp for breakfast, this does the following:

 1. parse the current email body as markdown, in a separate buffer
 2. make the current email multipart/alternative
 3. add an HTML part
 4. inject the HTML version in the HTML part

There's some nasty business with formatting the signature correctly by
wrapping it in a 
 that's going on there - I took that from
Thunderbird as well.

(For those who *do* read elisp for breakfast, improvements and comments
on the coding style are very welcome.)

The idea is that you write your email normally, but in markdown. When
you're done writing that email, you launch the above function (carefully
bound to "M-x anarcat/notmuch-html-convert" here) which takes that email
and adds an equivalent HTML part to it. You can then even tweak that
part to screw around with the raw HTML if you feel depressed or
nostalgic.

What do people think? Am I insane? Could this work? Does this belong in
notmuch? Or maybe in the tips section? Should I seek therapy? Do you
hate markdown? Expand on the relationship between your parents and text
editors.

Thanks for any feedback,

A.

PS: the above, naturally, could be adapted to parse the body as RST,
asciidoc, texinfo, latex or whatever insanity you think would be more
appropriate, I don't care. The idea is the same.

PPS: I remember reading about someone wanting to declare a text/markdown
mimetype for email, and remembering it was all backwards and weird and I
can't find the reference anymore. If some lazyweb magic person could
forward the link to me I would be grateful.

 [1]: one of so many: https://www.georgedillon.com/web/html_email_is_evil_still.shtml
 [2]: https://en.wikipedia.org/wiki/Netscape_Communicator
 [3]: yes my age is showing
 [4]: to be fair, this article encouraged me quite a bit:
 https://blog.chaddickerson.com/2019/01/09/replacing-facebook/
 [5]: not the bass guitar one, unfortunately
 [6]: https://en.wikipedia.org/wiki/HTML_email#Adoption
 [7]: https://trey-jackson.blogspot.com/2008/01/emacs-tip-8-markdown.html

--=-=-=--