27 lines
973 B
Bash
Executable File
27 lines
973 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Based on https://paste.sr.ht/~nihil/3a930baa56efba7d56fe03833386ba8b27a23989
|
|
# Originally by Samuel Fadel
|
|
# For a discussion, see
|
|
# https://lists.sr.ht/~rjarry/aerc-devel/%3C93983e01d0226c34394702886ca748b9cca6a046.camel%40posteo.de%3E
|
|
set -euo pipefail
|
|
|
|
EMAIL="$(mktemp -u --suffix=.eml)"
|
|
clean_email() {
|
|
rm -f "$EMAIL"
|
|
}
|
|
|
|
account="$1"
|
|
shift
|
|
|
|
# <stdin> of script gets the email, we save temporarily for using it twice
|
|
# ensure clean_email() is called when we exit abnormally
|
|
trap 'clean_email' 0 1 2 3 15
|
|
cat > "$EMAIL"
|
|
|
|
# assumes all maildir accounts are configured with a 'Sent' directory
|
|
# make sure to tag it correctly
|
|
notmuch insert --folder="$account/Sent" -inbox -unread +sent < "$EMAIL"
|
|
# assumes all accounts are configured with the same name as dir name above in msmtprc
|
|
# msmtp could be called with args from aerc, but --read-recipients already does the job
|
|
msmtp --account="$account" --read-recipients --read-envelope-from < "$EMAIL"
|