summaryrefslogtreecommitdiff
path: root/sendmailadvanced/sendmailadvanced
blob: 7b5e7fe541724025e497c4d2e1fe984b236fe4f4 (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
#!/bin/bash

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 [ "${MAILER}" == "cantfind" ]
then
  >&2 echo "ERROR: Can't find suitable mailer."
  exit 1
fi

(
  . /etc/sendmailadvanced.conf

  tos=""
  while read s
  do
    echo "${s}"
    if [ "${s:0:3}" == "To:" ] || [ "${s:0:3}" == "Cc:" ]
    then
      tos="${tos} ${s:4}"
    fi
    if [ "${s:0:8}" == "Subject:" ]
    then
      break
    fi
  done
  hashcash -b ${hashcash_bits} -Xm ${tos}
  while read s
  do
    echo "${s}"
    if [ "${s}" == "" ]
    then
      break
    fi
  done
  (
    body_header_hook $@
    cat
    body_footer_hook $@
  ) | gpg -e -a -s -r ${gpg_recipient}
) | ${MAILER} -t