blob: d4c4be25fc66c0de263d68256d572079dfc0de2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#!/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
)
|