#!/bin/bash verwendung() { >&2 echo 'sendmailadvanced [-h|--hook param-for-hooks] [-i|--inline file] [-e|--encrypt] [-s|--stamp] [-t] [--no-hooks]' exit 1 } datei="" encrypt=false stamp=false applyHooks=true if [ -x /etc/sendmailadvanced.conf ] then . /etc/sendmailadvanced.conf else for konfig in $(readlink -f "$0").conf $(find . -name sendmailadvanced.conf 2> /dev/null) do [ -x "${konfig}" ] || continue . "${konfig}" break done fi eval set -- "$(getopt -o eh:i:st --long encrypt,hook:,inline:,no-hooks,stamp -n "$(basename "$0")" -- "$@")" while true do case "$1" in -h|--hook) shift hooks[${#hooks[@]}]="$1" ;; -i|--inline) echo "inline erkannt" shift datei="$1" ;; -e|--encrypt) encrypt=true ;; -s|--stamp) stamp=true ;; --no-hooks) applyHooks=false ;; -t) encrypt=true stamp=true ;; --) shift break ;; *) >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende." verwendung ;; esac shift done [ $# -ne 0 ] && verwendung MAILER="cantfind" for executable in sendmail msmtp do for prefix in /usr/bin /usr/sbin /bin /sbin do [ "${MAILER}" == "cantfind" ] && [ -x ${prefix}/${executable} ] && MAILER="${prefix}/${executable}" done done if [ -z "${datei}" ] && [ "${MAILER}" == "cantfind" ] then >&2 echo "ERROR: Can't find suitable mailer." exit 1 fi ( [ -z "${datei}" ] && cat || cat "${datei}" ) | \ ( IFS='' adressatenString="" adressatenSammeln=false while read -r zeile do echo "${zeile}" | grep -q "\S" || break s="${zeile}" if [ "${s:0:3}" == "To:" ] || [ "${s:0:3}" == "Cc:" ] then adressatenSammeln=true s=" ,${s:4}" fi [ "${s:0:1}" == " " ] || adressatenSammeln=false ${adressatenSammeln} && adressatenString="${adressatenString}${s}" echo "${zeile}" done if ${stamp} then IFS=',' for adressat in ${adressatenString} do if [[ "${adressat}" == *"<"*">"* ]] then adressat="${adressat#*<}" adressat="${adressat%>*}" fi adressat="$( echo "${adressat}" | \ tr -d "[:space:]" )" echo "${adressat}" | grep -q "\S" || continue hashcash -b ${hashcash_bits} -Xm "${adressat}" done fi echo "${zeile}" ( ${applyHooks} && body_header_hook "${hooks[@]}" cat ${applyHooks} && body_footer_hook "${hooks[@]}" ) | \ ( ${encrypt} && gpg -e -a -s -r ${gpg_recipient} || cat ) ) | \ ( if [ -z "${datei}" ] then ${MAILER} -t else tmpFile="$(mktemp)" cat > "${tmpFile}" cat "${tmpFile}" > "${datei}" rm -f "${tmpFile}" fi )