From b715061cfee9797aa1b2d0db474e981c5be3afec Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Fri, 27 May 2022 20:53:10 +0100 Subject: [PATCH] Neomutt: adds better support for multipart emails Neomutt now supports sending multipart emails better. See details in my blog: https://jonathanh.co.uk/blog/multipart-emails-in-neomutt/ --- bin/.bin/emails/convert-multipart | 59 +++++++++++++++++++++++++++++++ mutt/.config/mutt/muttrc | 10 ++++++ 2 files changed, 69 insertions(+) create mode 100755 bin/.bin/emails/convert-multipart diff --git a/bin/.bin/emails/convert-multipart b/bin/.bin/emails/convert-multipart new file mode 100755 index 00000000..543f0db7 --- /dev/null +++ b/bin/.bin/emails/convert-multipart @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# https://github.com/anufrievroman/Neomutt-File-Picker/blob/master/filepicker +# https://github.com/neomutt/neomutt/issues/3229 +# https://unix.stackexchange.com/questions/612134/neomutt-run-command-to-attach-file-on-macro-key-press/612194#612194 + +commandsFile="/tmp/neomutt-commands" +markdownFile="/tmp/neomutt-markdown" +htmlFile="/tmp/neomutt.html" + +cat - > "${markdownFile}.orig" +echo -n "push " > "$commandsFile" + +cp "${markdownFile}.orig" "$markdownFile" + +grep -Eo '!\[[^]]*\]\([^)]+' "$markdownFile" | cut -d '(' -f 2 | + grep -Ev '^(cid:|https?://)' | while read file; do + id="cid:$(md5sum "$file" | cut -d ' ' -f 1 )" + sed -i "s#$file#$id#g" "$markdownFile" + done + +if [ "$(grep -Eo '!\[[^]]*\]\([^)]+' "$markdownFile" | cut -d '(' -f 2 | grep '^cid:' | wc -l)" -gt 0 ]; then + echo -n "\"$markdownFile\"" >> "$commandsFile" +fi + + +pandoc -f markdown -t html5 --standalone --template ~/.pandoc/templates/email.html "$markdownFile" > "$htmlFile" + +# Attach the html file +echo -n "\"$htmlFile\"" >> "$commandsFile" + +# Set it as inline +echo -n "" >> "$commandsFile" + +# Tell neomutt to delete it after sending +echo -n "" >> "$commandsFile" + +# Select both the html and markdown files +echo -n "" >> "$commandsFile" + +# Group the selected messages as alternatives +echo -n "" >> "$commandsFile" + + + +grep -Eo '!\[[^]]*\]\([^)]+' "${markdownFile}.orig" | cut -d '(' -f 2 | + grep -Ev '^(cid:|https?://)' | while read file; do + id="$(md5sum "$file" | cut -d ' ' -f 1 )" + echo -n "\"$file\"" >> "$commandsFile" + echo -n "" >> "$commandsFile" + echo -n "^u\"$id\"" >> "$commandsFile" + echo -n "" >> "$commandsFile" +done + + +if [ "$(grep -Eo '!\[[^]]*\]\([^)]+' "$markdownFile" | cut -d '(' -f 2 | grep '^cid:' | + wc -l)" -gt 0 ]; then + echo -n "" >> "$commandsFile" +fi diff --git a/mutt/.config/mutt/muttrc b/mutt/.config/mutt/muttrc index e0dfc58b..7dd877b5 100644 --- a/mutt/.config/mutt/muttrc +++ b/mutt/.config/mutt/muttrc @@ -171,6 +171,16 @@ bind pager gg top bind pager j next-line bind pager k previous-line +###################### +# Compose settings # +###################### + + +macro compose Y "\ +convert-multipart\ +source /tmp/neomutt-commands + + ############## # Contacts # ##############