Mon, 06 Jan 2020 15:34:34 -0600
proper multipart!
.muttrc | file | annotate | diff | comparison | revisions | |
bin/mutt-md2multipart | file | annotate | diff | comparison | revisions |
--- a/.muttrc +++ b/.muttrc @@ -97,6 +97,17 @@ macro attach,compose \Cb "<pipe-entry> u # Turn a text/plain markdown part into text/html macro compose \eh "F mutt-md2html \ny^T^Utext/html\n" 'htmlify' +# Turn a text/plain markdown part into proper multipart +macro compose \em \ +"<enter-command>set pipe_decode<enter>\ +<pipe-entry>~/bin/mutt-md2multipart /tmp/$hostname<enter>\ +<enter-command>unset pipe-decode<enter>\ +a^U/tmp/$hostname/msg.txt\n^Da^U/tmp/$hostname/msg.html\n^D^T^Utext/html; charset=utf-8\n\ +=DTT&d^U\n" \ +"multipartify" + +shutdown-hook 'shell-escape rm -rf /tmp/$hostname' + push <first-entry> # Appearance
new file mode 100755 --- /dev/null +++ b/bin/mutt-md2multipart @@ -0,0 +1,37 @@ +#!/bin/sh +set -eu + +output=$1 + +# Output directory is going to be one-per-process. I'd like to have a fully +# random tmpdir but doing that and having it mutt clean up is "hard". Note +# that when these two parts get attached, we can't just clean files inside the +# macro, because they aren't read into memory until send/save. + +mkdir -p $output + +# Store stdin because we're using it twice. +cat - > $output/msg.orig + +# Noting the above, there may be old output here. pandoc likes to confirm +# overwrites so we handle it. +rm -f $output/msg.{txt,html} + +pandoc \ + --quiet \ + -f markdown-blank_before_blockquote+smart \ + -t plain \ + -o $output/msg.txt \ + $output/msg.orig + +pandoc \ + --quiet \ + --standalone \ + -f markdown-blank_before_blockquote+smart \ + -t html5 \ + --self-contained \ + --template=mail \ + --highlight-style=monochrome \ + --email-obfuscation=none \ + -o $output/msg.html \ + $output/msg.orig