You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
2.0 KiB

#!/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 "<attach-file>\"$markdownFile\"<enter><toggle-disposition><toggle-unlink><first-entry><detach-file>" >> "$commandsFile"
fi
pandoc -f markdown -t html5 --standalone --template ~/.pandoc/templates/email.html "$markdownFile" > "$htmlFile"
# Attach the html file
echo -n "<attach-file>\"$htmlFile\"<enter>" >> "$commandsFile"
# Set it as inline
echo -n "<toggle-disposition>" >> "$commandsFile"
# Tell neomutt to delete it after sending
echo -n "<toggle-unlink>" >> "$commandsFile"
# Select both the html and markdown files
echo -n "<tag-entry><previous-entry><tag-entry>" >> "$commandsFile"
# Group the selected messages as alternatives
echo -n "<group-alternatives>" >> "$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 "<attach-file>\"$file\"<enter>" >> "$commandsFile"
echo -n "<toggle-disposition>" >> "$commandsFile"
echo -n "<edit-content-id>^u\"$id\"<enter>" >> "$commandsFile"
echo -n "<tag-entry>" >> "$commandsFile"
done
if [ "$(grep -Eo '!\[[^]]*\]\([^)]+' "$markdownFile" | cut -d '(' -f 2 | grep '^cid:' |
wc -l)" -gt 0 ]; then
echo -n "<first-entry><tag-entry><group-related>" >> "$commandsFile"
fi