Use trust-model always
[misc/asterisk-openpgp-mailsend.git] / asterisk-mailsend
1 #!/bin/bash
2
3 # Configuration
4 SENDER_DOMAIN="sumptuouscapital.com"
5 GNUPG_HOMEDIR="/var/lib/asterisk/.gnupg"
6 GNUPG_BIN="/usr/bin/gpg2"
7 SUBJECT="$(date '+%Y-%m-%d %H:%M:%S'): You have a new VoiceMail message"
8 LOGFILE="/tmp/asterisk-voicemail-error.txt"
9
10 # Edit should not be necessary below this line
11 LOCALTEMP=$(/bin/mktemp)
12 cat > ${LOCALTEMP}
13
14 TO=$(grep -E "^To:" ${LOCALTEMP} | sed -e 's/[^<]*<\([^>]*\)>/\1/')
15
16 BOUNDARY="-----=${RANDOM}"
17 TMP=$(mktemp)
18
19 echo "To: ${TO}" >> ${TMP}
20 echo "Subject: ${SUBJECT}" >> ${TMP}
21 echo "Precedence: bulk" >> ${TMP}
22 echo "Message-ID: ${RANDOM}@${SENDER_DOMAIN}"
23 echo "MIME-Version: 1.0" >> ${TMP}
24 echo "Content-Type: multipart/encrypted; protocol=\"application/pgp-encrypted\"; boundary=\"${BOUNDARY}\"" >> ${TMP}
25
26 echo "" >> ${TMP}
27 echo "This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)" >> ${TMP}
28 echo "" >> ${TMP}
29 echo "--${BOUNDARY}" >> ${TMP}
30 echo "Content-Type: application/pgp-encrypted" >> ${TMP}
31 echo "Content-Description: PGP/MIME version identification" >> ${TMP}
32 echo "" >> ${TMP}
33 echo "Version: 1" >> ${TMP}
34 echo "" >> ${TMP}
35 echo "--${BOUNDARY}" >> ${TMP}
36 echo 'Content-Type: application/octet-stream; name="encrypted.asc"' >> ${TMP}
37 echo 'Content-Description: OpenPGP encrypted message' >> ${TMP}
38 echo 'Content-Disposition: inline; filename="encrypted.asc"' >> ${TMP}
39 echo "" >> ${TMP}
40
41 ${GNUPG_BIN} --batch --trust-model always --homedir ${GNUPG_HOMEDIR} -aer ${TO} --encrypt ${LOCALTEMP}
42 if [[ $? != "0" ]]; then
43 echo "Error encrypting ${LOCALTEMP} to ${TO}" >> ${LOGFILE}
44 exit 1;
45 fi
46
47 cat ${LOCALTEMP}.asc >> ${TMP}
48
49 echo "--${BOUNDARY}--" >> ${TMP}
50
51 cat ${TMP} | /usr/bin/sendmail -t