* Re: [RFC] writing HTML email with notmuch
[not found] <mailman.1.1551124801.2659.notmuch@notmuchmail.org>
@ 2019-02-28 7:23 ` Jayanth R Varma
0 siblings, 0 replies; 8+ messages in thread
From: Jayanth R Varma @ 2019-02-28 7:23 UTC (permalink / raw)
To: notmuch
Antoine Beaupr? <anarcat@orangeseeds.org> writes:
> 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.
I do something similar routinely. I have bound the C-c C-c key to
a function that presents me with four choices:
1. Send as plain text
2. Send as HTML
3. Preview HTML in emacs (with w3m)
4. Preview HTML with external browser
For a few weeks, I suggest religiously previewing HTML in external
browser before sending any HTML mail because there are a lot of
things that can go wrong (more on this below). After most of the
wrinkles are ironed out, you can switch to previewing in
emacs-w3m. When you are really sure that everything is working,
you can send most simple mails as HTML without preview, but I
would still suggest previewing complex mails (for example with
tables, embedded code and so on).
What can go wrong:
1. Lazy blockquote in markdown means that you must leave a blank
line between a quoted message and your response, or else your
response will also be part of the blockquote. It is so easy to
slip up on this in email. In fact, I am considering adding some
code to insert this blank line automatically.
2. Signatures: Since you know your own signature, it is best to
search for an exact match for it rather than rely on some
heuristics.
3. Attachments. In plain text mail, attachments can be
anywhere. Many years ago, I once inserted an attachment by mistake
mid-sentence, but the email was sent and received perfectly (apart
from an extra line break). So you have to be careful while
converting to HTML. My method is to use a regex search to find all
attachments and move them to the end of the email. So the
converted message begins with a multi-part/alternative with plain
text and html alternatives at the top. This is followed by the
signature and the attachments. Since these are now all plain text
parts (the email default), there is no need for any <pre> tags for
the signature.
Conversion to HTML
1. I use pandoc for the conversion because it gives complete
ability to customize the exact flavour of markdown that you want
(for example, table formats).
2. Although everything can surely be done in elisp, I prefer to
delegate most of the pre-processing and previewing to a external
(python) script which orchestrates everything: creating temp
files, invoking pandoc, running external browsers and cleaning up
at the end.
3. I ensure that previewing the HTML does not change the message
buffer at all (everything happens in other buffers or in temp
files). So you can keep tweaking the markdown till you get
everything right, and there is no need to tweak the raw HTML.
PS: I am also a plain text guy. But in email, plain text does not
mean plain text (as in unicode), it actually means 7-bit ASCII. So
if you want a euro or yen symbol, Greek letters or mathematical
symbols, you need HTML just as a wrapper to provide UTF encoding.
PPS: If you are writing markdown and sending both plain text and
HTML alternatives, you are not really a sinner. Only the recipient
who chooses to view the HTML part is sinning (and even that sin
can be condoned if the recipient uses notmuch/emacs to render the
HTML).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC] writing HTML email with notmuch
@ 2019-02-25 1:52 Antoine Beaupré
2019-02-25 18:22 ` Istvan Marko
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Antoine Beaupré @ 2019-02-25 1:52 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 2619 bytes --]
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 "
[-- Attachment #2.1: Type: text/plain, Size: 38 bytes --]
\n")
(end-of-buffer)
(insert "
[-- Attachment #2.2: Type: text/html, Size: 57 bytes --]
[-- Attachment #3: Type: text/plain, Size: 2201 bytes --]
;; 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/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 <pre> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC] writing HTML email with notmuch
2019-02-25 1:52 Antoine Beaupré
@ 2019-02-25 18:22 ` Istvan Marko
2019-02-25 18:56 ` Brian Sniffen
2019-02-25 21:18 ` Daniel Kahn Gillmor
2 siblings, 0 replies; 8+ messages in thread
From: Istvan Marko @ 2019-02-25 18:22 UTC (permalink / raw)
To: Antoine Beaupré, notmuch
Antoine Beaupré <anarcat@orangeseeds.org> writes:
> (defun anarcat/notmuch-html-convert ()
> """create an HTML part from a Markdown body
Nice. There is also https://github.com/org-mime/org-mime (in melpa as
"org-mime") which does something similar but with Org instead of
Markdown.
--
Istvan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC] writing HTML email with notmuch
2019-02-25 1:52 Antoine Beaupré
2019-02-25 18:22 ` Istvan Marko
@ 2019-02-25 18:56 ` Brian Sniffen
2019-02-25 22:58 ` Antoine Beaupré
2019-02-25 21:18 ` Daniel Kahn Gillmor
2 siblings, 1 reply; 8+ messages in thread
From: Brian Sniffen @ 2019-02-25 18:56 UTC (permalink / raw)
To: Antoine Beaupré; +Cc: notmuch
[-- Attachment #1: Type: text/plain, Size: 5603 bytes --]
I appreciate the signature handling. But perhaps you used it on this message and it ate part of this line?
> (insert "
> ;; remove Markdown <pre> markings
--
Brian Sniffen
> On Feb 24, 2019, at 8:52 PM, Antoine Beaupré <anarcat@orangeseeds.org> wrote:
>
> 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 "
> \n") (insert-buffer output-buffer-name) (insert "
> ;; 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/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 <pre> 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
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
[-- Attachment #2: Type: text/html, Size: 8962 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC] writing HTML email with notmuch
2019-02-25 1:52 Antoine Beaupré
2019-02-25 18:22 ` Istvan Marko
2019-02-25 18:56 ` Brian Sniffen
@ 2019-02-25 21:18 ` Daniel Kahn Gillmor
[not found] ` <87lg23ldrl.fsf@curie.anarc.at>
2 siblings, 1 reply; 8+ messages in thread
From: Daniel Kahn Gillmor @ 2019-02-25 21:18 UTC (permalink / raw)
To: Antoine Beaupré, notmuch
[-- Attachment #1: Type: text/plain, Size: 1670 bytes --]
Hi Antoine--
thanks for an entertaining and thoughtful read.
Your elisp rendered really strangely for me in notmuch mode in emacs:
(widen)
(save-excursion
(set-buffer output-buffer-name)
(markdown-add-xhtml-header-and-footer ""))
(insert "
[ multipart/alternative ]
[ text/plain ]
\n")
(end-of-buffer)
(insert "
[ text/html (hidden) ]
\n") (insert-buffer output-buffer-name) (insert "
[ text/plain ]
;; remove Markdown <pre> markings
(goto-char signature-position)
(note the []-delimited emacs buttons above)
The issue here appears to be that the MIME boundaries in your message (i
won't repeat them here because i don't want to break my own message) are
getting mixed up/confused somehow with the mime boundaries you include
in the elisp.
I'd be happy to compare raw files with you at some point if you want to
try to make sense of this. I'm hoping that the error is in the message
generation (that your sending MUA garbled your elisp) rather than in the
receipt, because if the receiving side is at fault it's a much worse
security risk.
On Sun 2019-02-24 20:52:40 -0500, Antoine Beaupré wrote:
> 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.
https://tools.ietf.org/html/rfc7763 -- I'm sure Sean Leonard (the author
of this informational RFC) would be open to discussion about what's
missing or what could be improved.
--dkg
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-02-28 7:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1.1551124801.2659.notmuch@notmuchmail.org>
2019-02-28 7:23 ` [RFC] writing HTML email with notmuch Jayanth R Varma
2019-02-25 1:52 Antoine Beaupré
2019-02-25 18:22 ` Istvan Marko
2019-02-25 18:56 ` Brian Sniffen
2019-02-25 22:58 ` Antoine Beaupré
2019-02-25 21:18 ` Daniel Kahn Gillmor
[not found] ` <87lg23ldrl.fsf@curie.anarc.at>
2019-02-25 23:01 ` Antoine Beaupré
2019-02-25 23:15 ` Daniel Kahn Gillmor
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).