diff options
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index e5e483937..769a6bb8f 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -10,9 +10,9 @@ use FixMyStreet; use FixMyStreet::Cobrand; use Memcached; use mySociety::Email; -use mySociety::EmailUtil; use mySociety::Random qw(random_bytes); use FixMyStreet::Map; +use Utils; use Path::Class; use URI; @@ -348,9 +348,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') @@ -379,23 +389,23 @@ sub send_email_cron { $sig = Encode::decode('utf8', $sig); $params->{_parameters_}->{signature} = $sig; - $tt->process( 'site_name.txt', $params, \$site_name ); - $site_name = Encode::decode('utf8', $site_name); - my $site_title = $cobrand ? $cobrand->site_title : ''; - $params->{_parameters_}->{site_name} = $site_name || $site_title; + $tt->process( 'site-name.txt', $params, \$site_name ); + $site_name = Utils::trim_text(Encode::decode('utf8', $site_name)); + $params->{_parameters_}->{site_name} = $site_name; $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; } } |