#!/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