From fa9557ea594346ae1ab64a609869532be185f467 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 12 Jan 2017 09:49:18 +0100 Subject: encrypt to recipients, if key available --- sendmailadvanced.in | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/sendmailadvanced.in b/sendmailadvanced.in index c1aef2e..547d9a0 100755 --- a/sendmailadvanced.in +++ b/sendmailadvanced.in @@ -17,7 +17,7 @@ verwendung() { exit 1 } -stempeln() { +neueAdressaten() { oldIFS="${IFS}" IFS=',' @@ -33,7 +33,7 @@ stempeln() { tr -d "[:space:]" )" echo "${adressat}" | grep -q "\S" || continue - hashcash -b ${hashcash_bits} -Xm "${adressat}" + adressaten["${adressat}"]=1 done adressatenString="" @@ -41,6 +41,34 @@ stempeln() { IFS="${oldIFS}" } +stempeln() { + hashcash -b ${hashcash_bits} -Xm "${!adressaten[@]}" +} + +gpgAdressaten() { + local kenneAlle + for adressat in "${!adressaten[@]}" + do + if \ + ( + gpg --with-colons --list-public-keys "${adressat}" | \ + grep '^uid:[mfuw]:' | \ + cut -d: -f10 | \ + tr '<>' '\n' | \ + sort -u + echo "${adressat}" + ) | \ + sort | \ + uniq -d | \ + grep -q '\S' + then + echo -n "-r ${adressat} " + else + echo -n "-r ${gpg_recipient} " + fi + done +} + datei="" encrypt=true stamp=true @@ -147,6 +175,8 @@ fi ( IFS='' adressatenString="" + unset adressaten + declare -A adressaten adressatenSammeln=false while read -r zeile do @@ -159,7 +189,7 @@ fi fi if [ ! "${s:0:1}" == " " ] then - ${adressatenSammeln} && ${stamp} && stempeln + ${adressatenSammeln} && neueAdressaten adressatenSammeln=false fi ${adressatenSammeln} && adressatenString="${adressatenString}${s}" @@ -181,7 +211,7 @@ fi done ) | \ ( - ${encrypt} && gpg -e -a -s -r ${gpg_recipient} || cat + ${encrypt} && gpg -e -a -s -r $(gpgAdressaten) || cat ) ) | \ ( -- cgit v1.2.3-70-g09d2