aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-01-09 22:55:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-01-13 16:28:50 +0000
commit676181084d88b0ec94d42521162b4571cb0c0552 (patch)
tree744979e676295aa7daf2de3aa03818b1f6419fb6 /perllib/FixMyStreet/App.pm
parent4ae8d597a80d91084dcdcd999d480f41a57c70d1 (diff)
Use same handling for cron and non-cron email.
This means that e.g. SMTP authentication is used when set up by all emails, not just non-cron ones. Fixes #988.
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r--perllib/FixMyStreet/App.pm32
1 files changed, 21 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index e5e483937..fd70ffda8 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -10,7 +10,6 @@ use FixMyStreet;
use FixMyStreet::Cobrand;
use Memcached;
use mySociety::Email;
-use mySociety::EmailUtil;
use mySociety::Random qw(random_bytes);
use FixMyStreet::Map;
@@ -348,9 +347,19 @@ sub send_email {
}
sub send_email_cron {
- my ( $c, $params, $env_from, $env_to, $nomail, $cobrand, $lang_code ) = @_;
-
- return 1 if $c->is_abuser( $env_to );
+ my ( $c, $params, $env_from, $nomail, $cobrand, $lang_code ) = @_;
+
+ my $first_to;
+ if (ref($params->{To}) eq 'ARRAY') {
+ if (ref($params->{To}[0]) eq 'ARRAY') {
+ $first_to = $params->{To}[0][0];
+ } else {
+ $first_to = $params->{To}[0];
+ }
+ } else {
+ $first_to = $params->{To};
+ }
+ return 1 if $c->is_abuser($first_to);
$params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@%s>', time(),
unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN')
@@ -387,15 +396,16 @@ sub send_email_cron {
$params->{_line_indent} = '';
my $email = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email($params) };
- if ( FixMyStreet->test_mode ) {
- my $sender = Email::Send->new({ mailer => 'Test' });
- $sender->send( $email );
- return 0;
- } elsif (!$nomail) {
- return mySociety::EmailUtil::send_email( $email, $env_from, @$env_to );
- } else {
+ if ($nomail) {
print $email;
return 1; # Failure
+ } else {
+ my %model_args;
+ if (!FixMyStreet->test_mode && $env_from eq FixMyStreet->config('CONTACT_EMAIL')) {
+ $model_args{mailer} = 'FixMyStreet::EmailSend::ContactEmail';
+ }
+ my $result = $c->model('EmailSend', %model_args)->send($email);
+ return $result ? 0 : 1;
}
}