#!/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) 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='' while read -r s do echo "${s}" if [ "${s:0:3}" == "To:" ] || [ "${s:0:3}" == "Cc:" ] then s="${s:4}" if [[ "${s}" == *"<"*">"* ]] then s="${s#*<}" s="${s%>*}" fi tos[${#tos[@]}]="${s}" elif [ "${s:0:8}" == "Subject:" ] then break fi done ${stamp} && hashcash -b ${hashcash_bits} -Xm "${tos[@]}" while read s do echo "${s}" if [ "${s}" == "" ] then break fi done ( ${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 )