chiark / gitweb /
More error handling: set -e, set -o pipefail
[modbot-ulm.git] / stump / bin / processRejected
1 #!/bin/bash
2 #
3 # This script takes a raw article that is already rejected, creates a 
4 # reply message, signs it with PGP and sends back to the author.
5 #
6
7 set -e
8
9 # echo $0 invoked with arguments $@ 1>&2
10
11 MESSAGE=$TMP/rejected.$$
12
13 shift; REASON="$1"; export REASON; shift 
14 #EXPLANATION="$@"; export EXPLANATION
15
16 echo Action: processRejected, reason=$REASON 1>&2
17
18 cat  > $MESSAGE
19
20 #save() { 
21 #  procmail -p -f- $MNG_ROOT/etc/procmail/save-rejected < $MESSAGE
22 #}
23
24 reply() {
25
26   if [ "x$REASON" = xdiscard ]; then return; fi
27   (
28     cat $MESSAGE | formail -rt -I "Reply-To: $BOARD"    \
29                                -I "Errors-To: $MUNGED_ADDRESS"   \
30         -I "X-Webstump-Event: reject $REASON" \
31         $MAILOUT_REJECT_FORMAIL_ARGS
32     (
33       echo "$EXPLANATION"
34       echo
35
36       if [ "x$REASON" != "xcustom" ] ; then
37         cat $MNG_ROOT/etc/messages/$REASON
38       fi
39
40       echo ""
41       echo ============================================ Full text of your message follows
42       sanitise_and_quote_email \
43          < $MESSAGE
44     ) | gpg --clearsign --textmode --armor --batch --user "$PMUSER_APPROVAL" \
45          --passphrase "$PMPASSWORD" 2>/dev/null \
46   ) | sendmail -oi -t -f $MUNGED_ADDRESS
47 }
48
49 update_rejection_count() {
50   # don't count forgeries and signature mismatches against the victim
51   # also don't count thread rejections or duplicates
52   if [ "x$REASON" != "xforgery" -a "x$REASON" != "xsignature" -a "x$REASON" != "xthread" -a "x$REASON" != "xduplicate" -a "x$REASON" != "xcrosspost" -a "x$REASON" != "xempty" ]; then
53     cat $MESSAGE | updateActionCount.pl -r
54   fi
55 }
56
57 #save
58 reply $1
59 #update_rejection_count
60 rm $MESSAGE
61
62 #    ) | stump-pgp -staf -z "$PMPASSWORD"       \
63 #            -u "$ROBOMOD_APPROVAL" +clearsig=on  2>/dev/null   \