diff options
author | Erich Eckner <git@eckner.net> | 2017-01-12 09:49:18 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-01-12 09:49:18 +0100 |
commit | fa9557ea594346ae1ab64a609869532be185f467 (patch) | |
tree | 0d0389dd83406a4dfa41acd6762e6453a5998cd2 | |
parent | 969779b4fde915bf9297f5ea8c21de81b751ba75 (diff) | |
download | sendmailadvanced-fa9557ea594346ae1ab64a609869532be185f467.tar.xz |
encrypt to recipients, if key available
-rwxr-xr-x | sendmailadvanced.in | 38 |
1 files 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 ) ) | \ ( |