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 99CCF6DE0F32 for ; Mon, 25 Feb 2019 10:56:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.1 X-Spam-Level: X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5 tests=[AWL=0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, MIME_QP_LONG_LINE=0.001, 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 T6g-KdCMkOtp for ; Mon, 25 Feb 2019 10:56:35 -0800 (PST) Received: from istari.evenmere.org (istari.evenmere.org [136.248.125.194]) by arlo.cworth.org (Postfix) with ESMTP id 3EFD26DE0EA5 for ; Mon, 25 Feb 2019 10:56:35 -0800 (PST) Received: by istari.evenmere.org (Postfix, from userid 113) id DD8141F7DA8; Mon, 25 Feb 2019 13:56:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=evenmere.org; s=default; t=1551120993; bh=ECjU9MHAYv+jFg4NvzcydhG06UvM/Z4FmjOXixFy+DM=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=u5Y4HiRJz1XtHkKkPgD21jPKcadTsQOJrzZo+kfd2163I/Sm/+NbsUDlZn7K6trCb tiXcuBAWe8M5QCrLkoq+uN+Y8FRi8cSx4q3FDtaZTpM7DgklG8qDR8N6gNWELXlknE GnvjVOBH7UksNIHZrwuf4/Twuc44+w0KwSuURvx8= Received: from [30.91.103.186] (unknown [172.56.3.219]) by istari.evenmere.org (Postfix) with ESMTPSA id 4B92A1F7DA8; Mon, 25 Feb 2019 13:56:31 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=evenmere.org; s=default; t=1551120991; bh=ECjU9MHAYv+jFg4NvzcydhG06UvM/Z4FmjOXixFy+DM=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=i1kqufVBv2fvKhakJAQcJsodK5azobQi2yzIzmYbDBTxoBR0snvkUB96t6dWQA0WB 1fWSSx7iIbXg425gL6Hk2X1uJbOsZpN7kWz8tES/o54nhedigIHcjRAmrVPytqcEdU +pqFyPMWlzKC5tLHsuHpadWKYstmVamoGXr2KRvc= Content-Type: multipart/alternative; boundary=Apple-Mail-2536889F-C31B-4E5B-80B5-553DC25AB01C Mime-Version: 1.0 (1.0) Subject: Re: [RFC] writing HTML email with notmuch From: Brian Sniffen X-Mailer: iPhone Mail (16D57) In-Reply-To: <875zt8zlav.fsf@curie.anarc.at> Date: Mon, 25 Feb 2019 13:56:31 -0500 Cc: notmuch@notmuchmail.org Content-Transfer-Encoding: 7bit Message-Id: <4F9915CD-E51F-4CF7-83B4-63D6DC653B1C@evenmere.org> References: <875zt8zlav.fsf@curie.anarc.at> To: =?utf-8?Q?Antoine_Beaupr=C3=A9?= 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 18:56:36 -0000 --Apple-Mail-2536889F-C31B-4E5B-80B5-553DC25AB01C Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I appreciate the signature handling. But perhaps you used it on this message= and it ate part of this line? > (insert " > ;; remove Markdown
 markings

--=20
Brian Sniffen

> On Feb 24, 2019, at 8:52 PM, Antoine Beaupr=C3=A9  wrote:
>=20
> Hi,
>=20
> TL;DR: magic recipe to include an HTML version when writing plaintext.
>=20
> 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.
>=20
> 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.
>=20
> 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.
>=20
> 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!).
>=20
> 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:
>=20
> (defun anarcat/notmuch-html-convert ()
>  """create an HTML part from a Markdown body
>=20
> This will not work if there are *any* attachments of any form, those shoul=
d 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 "
> \n") (insert-buffer output-buffer-name) (insert "
>    ;; remove Markdown 
 markings
>    (goto-char signature-position)
>    (while (re-search-forward "^```" nil t)
>      (replace-match ""))))
>=20
> For those who can't read elisp for breakfast, this does the following:
>=20
> 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
>=20
> 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.
>=20
> (For those who *do* read elisp for breakfast, improvements and comments
> on the coding style are very welcome.)
>=20
> 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.
>=20
> 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.
>=20
> Thanks for any feedback,
>=20
> A.
>=20
> 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.
>=20
> 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.
>=20
> [1]: one of so many: https://www.georgedillon.com/web/html_email_is_evil_s=
till.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
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

--Apple-Mail-2536889F-C31B-4E5B-80B5-553DC25AB01C
Content-Type: text/html;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

I appreciate the signature handling. But pe=
rhaps you used it on this message and it ate part of this line?

(insert "
<= div dir=3D"ltr">   ;; remove= Markdown <pre> markings

-- 
Brian Sniffen

On Feb 24, 2019, at 8:52 PM, Antoine Beaupr=C3=A9 <anarcat@orangeseeds.org> wrote:
Hi,
<= span>
TL;DR: magic recipe to include an HTML version when wr= iting plaintext.

I know, I know, HTML email= is "evil"[1]. I mostly never ever use it, in
fact, I don't r= emember the last time I consciously sent HTML. Maybe I
did s= o 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 phot= ographs with families and friends. I
have tried creating a g= allery website with an RSS feed but I'm sure no
one here wil= l be surprised that the uptake is minimal, if
non-existent. P= eople expect to have stuff *pushed* to them, like
Instagram,= Facebook, Twitter or Spam does.

So I thoug= ht[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 f= irst
email, I realized it was pretty silly to not include im= ages, or at least
*links* to images in the email.
=
I'm sure you can see where this is going. A link in t= he email: who's
going to click that. Who clicks now anyways,= with all the tapping[5]
going on. So the answer comes natur= ally: just write frigging HTML
email. Don't be a rms^Wreligi= ous zealot and do the right thing, what
works basically ever= ywhere[6] (even notmuch!).

So I started Thu= nderbird and thought "what the heck am I doing! there
must b= e 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 b= y
trying to come up with a pure elisp solution, which goes a= little like
this:

(defun a= narcat/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)
 &= nbsp; (setq signature-position (point))
  &n= bsp;(forward-line -1)
   ;; GFM markers for p= re, used because easier to undo than the
   = ;; "prefix by 4 characters" standard
   (ins= ert "```")
   (end-of-buffer)
   (insert "```")

   ;; se= t region to top of body then end of buffer
  &nbs= p;(end-of-buffer)
   (message-goto-body)

   (narrow-to-region (point) (mark))
=    ;; run markdown on region
 &n= bsp; (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 "
\n") (insert-buffer output-buffer-name) (insert "
<= span>    ;; remove Markdown <pre> 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/a= lternative
3. add an HTML part
4. inject t= he HTML version in the HTML part

There's so= me nasty business with formatting the signature correctly by
wrapping it in a <pre> that's going on there - I took that from
Thunderbird as well.

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

The i= dea is that you write your email normally, but in markdown. When
<= span>you're done writing that email, you launch the above function (carefull= y
bound to "M-x anarcat/notmuch-html-convert" here) which ta= kes that email
and adds an equivalent HTML part to it. You c= an then even tweak that
part to screw around with the raw HT= ML if you feel depressed or
nostalgic.

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

Thanks for any feedback,

A.

PS: the above, naturally, could be adapted to p= arse the body as RST,
asciidoc, texinfo, latex or whatever i= nsanity you think would be more
appropriate, I don't care. T= he idea is the same.

PPS: I remember readin= g about someone wanting to declare a text/markdown
mimetype f= or 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_ema= il_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:

<= a href=3D"https://blog.chaddickerson.com/2019/01/09/replacing-facebook/">htt= ps://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-jac= kson.blogspot.com/2008/01/emacs-tip-8-markdown.html
__________________= _____________________________
notmuch mailing listnotmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch
= --Apple-Mail-2536889F-C31B-4E5B-80B5-553DC25AB01C--