From b5a04808a0f7b41d9e7543384ee9b5496683d234 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sun, 3 May 2020 17:31:12 +0100 Subject: [PATCH] Work on mutt scripts --- .../{MIMEmbellish => convertToHtmlMultipart} | 0 bin/.bin/emails/send-from-mutt | 27 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) rename bin/.bin/emails/{MIMEmbellish => convertToHtmlMultipart} (100%) diff --git a/bin/.bin/emails/MIMEmbellish b/bin/.bin/emails/convertToHtmlMultipart similarity index 100% rename from bin/.bin/emails/MIMEmbellish rename to bin/.bin/emails/convertToHtmlMultipart diff --git a/bin/.bin/emails/send-from-mutt b/bin/.bin/emails/send-from-mutt index e80ff034..145d09b4 100755 --- a/bin/.bin/emails/send-from-mutt +++ b/bin/.bin/emails/send-from-mutt @@ -1,4 +1,27 @@ #!/bin/sh -EMAIL=$(pass Email/protonmail | grep BridgeUsername | cut -d':' -f2) -~/.bin/emails/MIMEmbellish | msmtp --user "$EMAIL" "$@" + +#EMAIL=$(pass Email/protonmail | grep BridgeUsername | cut -d':' -f2) +#~/.bin/emails/MIMEmbellish | msmtp --user "$EMAIL" "$@" + +# Put the message, send to stdin, in a variable +message="$(cat -)" +config="$HOME/.config/msmtp/config.secret" +# Look at the first argument, +# Use it to determine the account to use +# If not set, assume work +# All remaining arguments should be recipient addresses which should be passed to msmtp +case "$(echo "$1" | tr '[A-Z]' '[a-z]')" in + "work") account="work"; shift ;; + "home") account="home"; shift ;; + *) account="work"; ;; +esac + +cleanHeaders(){ + # In the headers, delete any lines starting with markdown + cat - | sed '0,/^$/{/^markdown/Id;}' +} + +echo "$message" | sed '/^$/q' | grep -q -i 'markdown: true' \ + && echo "$message" | cleanHeaders | convertToHtmlMultipart | msmtp --file="$config" --account="$account" "$@" \ + || echo "$message" | cleanHeaders | msmtp --file="$config" --account="$account" "$@"