From 280884a0583096c36eca9b71ed13fc2e8ca5aa17 Mon Sep 17 00:00:00 2001 From: Gulliver Date: Mon, 26 Apr 2021 17:08:43 +0200 Subject: [PATCH] added first (incomplete)version of pipe script to get at least one mail sent encrypted and signed --- mail2members.sh | 101 ++++++++++++++++++++++++++++++++++++++ test/test-member-data.csv | 3 ++ test/test.erb | 7 +++ 3 files changed, 111 insertions(+) create mode 100755 mail2members.sh create mode 100644 test/test-member-data.csv create mode 100644 test/test.erb diff --git a/mail2members.sh b/mail2members.sh new file mode 100755 index 0000000..3e324fa --- /dev/null +++ b/mail2members.sh @@ -0,0 +1,101 @@ +#!/bin/sh +usage() +{ + echo "usage" + echo "=====" + echo "" + echo "reads a csv-file with member-data and a text-template from template" + echo "uses erb to fill the template with data, encrpyt and sign the mail with the members public pgp key and send it via swaks(swiss army knife for smtp)" + echo "" + echo "./$0" + echo "\t-h --help" + echo "\t--member-data=member-data.csv" + echo "\t--template=template.erb" + echo "\t--subject=subject" + echo "\t--smtphost=smtphost" + echo "\t--smtpuser=smtpuser" + echo "\t--smtppassword=smtppassword" + + echo "" +} + +while [ "$1" != "" ]; do + PARAM=`echo $1 | awk -F= '{print $1}'` + VALUE=`echo $1 | awk -F= '{print $2}'` + case $PARAM in + -h | --help) + usage + exit + ;; + -n) + DRYRUN=1 + ;; + --member-data) + MEMBER_DATA=$VALUE + ;; + --template) + TEMPLATE=$VALUE + ;; + --subject) + SUBJECT=$VALUE + ;; + --smtphost) + SMTPHOST=$VALUE + ;; + --smtpuser) + SMTPUSER=$VALUE + ;; + --smtppassword) + SMTPPASSWORD=$VALUE + ;; + *) + echo "ERROR: unknown parameter \"$PARAM\"" + usage + exit 1 + ;; + esac + shift +done + +if [ -z "$MEMBER_DATA" ] ; then + echo "parameter member-data missing" + echo "" + usage + exit +fi + +if [ -z "$TEMPLATE" ] ; then + echo "parameter template missing" + echo "" + usage + exit +fi + +if [ -z "$SUBJECT" ] ; then + echo "parameter userid missing" + echo "" + exit +fi + +echo "MEMBER_DATA = "$MEMBER_DATA +echo "TEMPLATE = "$TEMPLATE +echo "SUBJECT = "$SUBJECT + +if [ -z "$DRYRUN" ] ; then + echo "real run" + erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE\ + | gpg2 --batch --yes -vvv -u vorstand@wtf-eg.de \ + --no-emit-version -eas -r "42152130EE5C8BED881AB911D65BA8BC7E8B9302" \ + | swaks --to frank.landgraf@web.de \ + --from "vorstand@wtf-eg.de" \ + -tls \ + --auth LOGIN \ + --server $SMTPHOST \ + --auth-user $SMTPUSER \ + --auth-password $SMTPPASSWORD \ + --header "Subject: $SUBJECT" --body - +else + echo "dry run" + erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE + erb column1=Column1 column2=Column2 column3=Column3 $TEMPLATE|gpg2 --batch --yes -vvv -u vorstand@wtf-eg.de --no-emit-version -eas -r "42152130EE5C8BED881AB911D65BA8BC7E8B9302" + fi diff --git a/test/test-member-data.csv b/test/test-member-data.csv new file mode 100644 index 0000000..e4ad7f0 --- /dev/null +++ b/test/test-member-data.csv @@ -0,0 +1,3 @@ +Line,Nick,Email,PGP,Passwort + 110,gulliver,frank.landgraf@web.de,4215 2130 EE5C 8BED 881A B911 D65B A8BC 7E8B 9302,this is not my real password + diff --git a/test/test.erb b/test/test.erb new file mode 100644 index 0000000..738d881 --- /dev/null +++ b/test/test.erb @@ -0,0 +1,7 @@ +Sehr geehrtes Mitglied <%= column1 %>, + +Loginname: <%= column2 %> +Passwort:<%= column3 %> + +Mit freundlichen Grüßen, +Bossman \ No newline at end of file