1 | #!/bin/bash |
---|
2 | |
---|
3 | USER="$1" |
---|
4 | SENDER="$2" |
---|
5 | INMAIL=/tmp/syn3-dagent.$$ |
---|
6 | SCANMAIL=/tmp/syn3-dagent-scanned.$$ |
---|
7 | |
---|
8 | |
---|
9 | #cleanup and exit |
---|
10 | end() |
---|
11 | { |
---|
12 | rm $INMAIL 2>/dev/null |
---|
13 | rm $SCANMAIL 2>/dev/null |
---|
14 | exit $1 |
---|
15 | } |
---|
16 | |
---|
17 | # some kind of ldap problem, try again later |
---|
18 | id "Administrator" >/dev/null || end 111 |
---|
19 | |
---|
20 | #does the user exists? |
---|
21 | if ! id "$USER" >/dev/null; then |
---|
22 | #we're sure theres no ldap problem? |
---|
23 | id "Administrator" >/dev/null || end 111 |
---|
24 | #probably a bounce spammer, drop mail silently |
---|
25 | echo "User does not exist, dropping mail." |
---|
26 | end 0 |
---|
27 | fi |
---|
28 | |
---|
29 | #store mail temporary |
---|
30 | cat > $INMAIL || end 1 |
---|
31 | |
---|
32 | #pipe trough personal spamfilter of this user |
---|
33 | if ! grep "VIRUS.*IN MAIL TO YOU" $INMAIL >/dev/null && /usr/bin/dspamc --user "$USER" --deliver=innocent,spam --mail-from="$SENDER" --stdout >$SCANMAIL <$INMAIL; then |
---|
34 | #it worked |
---|
35 | if grep "^X-DSPAM-Result: Spam" $SCANMAIL >/dev/null; then |
---|
36 | SPAM=1 |
---|
37 | else |
---|
38 | SPAM= |
---|
39 | fi |
---|
40 | MAIL=$SCANMAIL |
---|
41 | else |
---|
42 | #spam filter is broken, or it was just a virus notification |
---|
43 | MAIL=$INMAIL |
---|
44 | SPAM= |
---|
45 | fi |
---|
46 | |
---|
47 | # #check cyrus is up, and deliver it there: |
---|
48 | # if /usr/bin/pgrep -f -x /usr/cyrus/bin/master ; then |
---|
49 | # if [ "$SPAM" ]; then |
---|
50 | # /usr/cyrus/bin/deliver -a "$USER" -m Spam "$USER" < $MAIL |
---|
51 | # end $? |
---|
52 | # else |
---|
53 | # /usr/cyrus/bin/deliver -a "$USER" "$USER" < $MAIL |
---|
54 | # end $? |
---|
55 | # fi |
---|
56 | # fi |
---|
57 | |
---|
58 | #check zarafa is up, and deliver it there: |
---|
59 | if pidof zarafa-server >/dev/null; then |
---|
60 | if [ "$SPAM" ]; then |
---|
61 | /usr/bin/zarafa-dagent "$USER" -q -j < $MAIL |
---|
62 | end $? |
---|
63 | else |
---|
64 | /usr/bin/zarafa-dagent "$USER" -q < $MAIL |
---|
65 | end $? |
---|
66 | fi |
---|
67 | fi |
---|
68 | |
---|
69 | #check kopano is up, and deliver it there: |
---|
70 | if pidof kopano-server >/dev/null; then |
---|
71 | if [ "$SPAM" ]; then |
---|
72 | /usr/bin/kopano-dagent "$USER" -q -j < $MAIL |
---|
73 | end $? |
---|
74 | else |
---|
75 | /usr/bin/kopano-dagent "$USER" -q < $MAIL |
---|
76 | end $? |
---|
77 | fi |
---|
78 | fi |
---|
79 | |
---|
80 | #no backend mailstorage up, so fail temporary |
---|
81 | echo "All mailbackends are down, retry again later..." |
---|
82 | end 111 |
---|