aboutsummaryrefslogtreecommitdiffstats
path: root/script/mailin
diff options
context:
space:
mode:
Diffstat (limited to 'script/mailin')
-rwxr-xr-xscript/mailin24
1 files changed, 11 insertions, 13 deletions
diff --git a/script/mailin b/script/mailin
index 733eaff3d..b4d77f7a4 100755
--- a/script/mailin
+++ b/script/mailin
@@ -2,18 +2,18 @@
# Wire this script to receive incoming email for request responses.
-INPUT=/tmp/foi-mailin-mail-$RANDOM$RANDOM$RANDOM$RANDOM.txt
-OUTPUT=/tmp/foi-mailin-output-$RANDOM$RANDOM$RANDOM$RANDOM.txt
+INPUT=$(mktemp -t foi-mailin-mail-XXXXXXXX)
+OUTPUT=$(mktemp -t foi-mailin-output-XXXXXXXX)
-cat >$INPUT
+# Read the email message from stdin, and write it to the file $INPUT
+cat >"$INPUT"
-cd `dirname $0`
-cd ../
+cd "$(dirname "$0")"/..
source commonlib/shlib/deployfns
read_conf config/general
-(cat $INPUT | ./script/runner 'RequestMailer.receive(STDIN.read)') >$OUTPUT 2>&1
+script/runner 'RequestMailer.receive(STDIN.read)' <"$INPUT" >"$OUTPUT" 2>&1
ERROR_CODE=$?
if [ ! "$ERROR_CODE" = "0" ]
then
@@ -21,17 +21,15 @@ then
# send error to administators (use mutt for MIME encoding)
SUBJ="Mail import error for $OPTION_DOMAIN"
- BODY="There was an error code $ERROR_CODE returned by the RequestMailer.receive command in script/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 $INPUT -- $OPTION_CONTACT_EMAIL
+ BODY="There was an error code $ERROR_CODE returned by the RequestMailer.receive command in script/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. We returned the email with an exit code 75, which for Exim at least instructs the MTA to 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."
+ /usr/bin/mutt -s "$SUBJ" -a "$OUTPUT" "$INPUT" -- "$OPTION_CONTACT_EMAIL" <<<"$BODY"
# tell exim error was temporary, so try again later (no point bouncing message to authority)
- rm -f $OUTPUT
- rm -f $INPUT
+ rm -f "$INPUT" "$OUTPUT"
exit 75
fi
-cat $OUTPUT
-rm -f $OUTPUT
-rm -f $INPUT
+cat "$OUTPUT"
+rm -f "$INPUT" "$OUTPUT"
exit 0