aboutsummaryrefslogtreecommitdiffstats
path: root/script/mailin
blob: eeaf0e5aaa4be18d649f8910674433b65ae6b4e0 (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
#!/bin/bash

OUTPUT=/tmp/foi-malin-$RANDOM$RANDOM$RANDOM$RANDOM.txt

cd `dirname $0`
cd ../../
source shlib/deployfns

read_conf foi/config/general

if ! ./foi/script/runner 'RequestMailer.receive(STDIN.read)' >$OUTPUT 2>$OUTPUT
then
    # we should never get an error here, unless the database is down or similar

    # send error to administators (use mutt for MIME encoding)
    SUBJ="Mail import error for $OPTION_DOMAIN"
    BODY="There was an error running the RequestMailer.receive command in script/foi/mailin. See attached for details. This might be quite serious, such as the database was down, or might be an email with corrupt headers that Rails is choking on. The email was returned with an exit code 75, which for Exim at least means the MTA will try again later. A well configured installation of this code will separately have had Exim make a backup copy of the email in a separate mailbox, just in case."
    echo "$BODY" | /usr/bin/mutt -s "$SUBJ" -a $OUTPUT $OPTION_CONTACT_EMAIL

    # tell exim error was temporary, so try again later (no point bouncing message to authority)
    rm -f $OUTPUT
    exit 75 
fi

cat $OUTPUT
rm -f $OUTPUT
exit 0