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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env perl
#
# handlemail:
# Handle an individual incoming mail message.
#
# This script should be invoked through the .forward mechanism. It processes
# replies to non-reply emails and auto-replies accordingly. Could deal with
# bounces at some point too.
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
my $rcsid = ''; $rcsid .= '$Id: handlemail,v 1.2 2009-02-11 11:04:48 matthew Exp $';
use strict;
use warnings;
require 5.8.0;
BEGIN {
use File::Basename qw(dirname);
use File::Spec;
my $d = dirname(File::Spec->rel2abs($0));
require "$d/../setenv.pl";
}
use FixMyStreet;
use mySociety::Email;
use mySociety::EmailUtil;
use mySociety::HandleMail;
use mySociety::SystemMisc;
# Don't print diagnostics to standard error, as this can result in bounce
# messages being generated (only in response to non-bounce input, obviously).
mySociety::SystemMisc::log_to_stderr(0);
my %data = mySociety::HandleMail::get_message();
if ($data{is_bounce_message}) {
#my $a = mySociety::HandleMail::get_bounce_recipient($data{message});
#my $token = mySociety::HandleMail::get_token($a,
# 'fms-', FixMyStreet->config('EMAILDOMAIN')
#);
#exit(0) if $token eq 'DO-NOT-REPLY'; # A bounce we don't care about
exit(0); # drop all other bounces currently
}
# Not a bounce, send an automatic response
my $template = 'reply-autoresponse';
my $fp = FixMyStreet->path_to("templates", "email", "default", $template)->open or exit 75;
$template = join('', <$fp>);
$fp->close;
# We generate this as a bounce.
my $mail = mySociety::Email::construct_email({
From => [ FixMyStreet->config('CONTACT_EMAIL'), 'FixMyStreet' ],
To => $data{return_path},
_template_ => $template,
_parameters_ => { },
_line_indent => '',
});
if (mySociety::EmailUtil::EMAIL_SUCCESS
!= mySociety::EmailUtil::send_email($mail, '<>', $data{return_path})) {
exit(75);
}
exit(0);
|