diff options
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 125 |
1 files changed, 3 insertions, 122 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index c9286b177..e4c113ea1 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -2,9 +2,6 @@ package FixMyStreet::App; use Moose; use namespace::autoclean; -# Should move away from Email::Send, but until then: -$Return::Value::NO_CLUCK = 1; - use Catalyst::Runtime 5.80; use FixMyStreet; use FixMyStreet::Cobrand; @@ -12,6 +9,7 @@ use Memcached; use mySociety::Email; use mySociety::Random qw(random_bytes); use FixMyStreet::Map; +use FixMyStreet::Email; use Utils; use Path::Class; @@ -319,7 +317,7 @@ sub send_email { ] }; - return if $c->is_abuser($vars->{to}); + return if FixMyStreet::Email::is_abuser($c->model('DB')->schema, $vars->{to}); # render the template my $content = $c->view('Email')->render( $c, $template, $vars ); @@ -347,7 +345,7 @@ sub send_email { ) }; if (my $attachments = $extra_stash_values->{attachments}) { - $email_text = munge_attachments($email_text, $attachments); + $email_text = FixMyStreet::Email::munge_attachments($email_text, $attachments); } # send the email @@ -356,107 +354,6 @@ sub send_email { return $email; } -sub send_email_cron { - my ( $c, $params, $env_from, $nomail, $cobrand, $lang_code ) = @_; - - my $sender = $c->config->{DO_NOT_REPLY_EMAIL}; - $env_from ||= $sender; - if (!$params->{From}) { - my $sender_name = $cobrand->contact_name; - $params->{From} = [ $sender, _($sender_name) ]; - } - - return 1 if $c->is_abuser($params->{To}); - - $params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@%s>', time(), - unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN') - ); - - # This is all to set the path for the templates processor so we can override - # signature and site names in emails using templates in the old style emails. - # It's a bit involved as not everywhere we use it knows about the cobrand so - # we can't assume there will be one. - my $include_path = FixMyStreet->path_to( 'templates', 'email', 'default' )->stringify; - if ( $cobrand ) { - $include_path = - FixMyStreet->path_to( 'templates', 'email', $cobrand->moniker )->stringify . ':' - . $include_path; - if ( $lang_code ) { - $include_path = - FixMyStreet->path_to( 'templates', 'email', $cobrand->moniker, $lang_code )->stringify . ':' - . $include_path; - } - } - my $tt = Template->new({ - INCLUDE_PATH => $include_path - }); - my ($sig, $site_name); - $tt->process( 'signature.txt', $params, \$sig ); - $sig = Encode::decode('utf8', $sig); - $params->{_parameters_}->{signature} = $sig; - - $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 $attachments = delete $params->{attachments}; - - my $email = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email($params) }; - - $email = munge_attachments($email, $attachments) if $attachments; - - 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; - } -} - -sub munge_attachments { - my ($message, $attachments) = @_; - # $attachments should be an array_ref of things that can be parsed to Email::MIME, - # for example - # [ - # body => $binary_data, - # attributes => { - # content_type => 'image/jpeg', - # encoding => 'base64', - # filename => '1234.1.jpeg', - # name => '1234.1.jpeg', - # }, - # ... - # ] - # - # XXX: mySociety::Email::construct_email isn't using a MIME library and - # requires more analysis to refactor, so for now, we'll simply parse the - # generated MIME and add attachments. - # - # (Yes, this means that the email is constructed by Email::Simple, munged - # manually by custom code, turned back into Email::Simple, and then munged - # with Email::MIME. What's your point?) - - require Email::MIME; - my $mime = Email::MIME->new($message); - $mime->parts_add([ map { Email::MIME->create(%$_)} @$attachments ]); - my $data = $mime->as_string; - - # unsure why Email::MIME adds \r\n. Possibly mail client should handle - # gracefully, BUT perhaps as the segment constructed by - # mySociety::Email::construct_email strips to \n, they seem not to. - # So we re-run the same regexp here to the added part. - $data =~ s/\r\n/\n/gs; - - return $data; -} - - =head2 uri_with $uri = $c->uri_with( ... ); @@ -571,22 +468,6 @@ sub get_photo_params { return $photo; } -sub is_abuser { - my ($c, $to) = @_; - my $email; - if (ref($to) eq 'ARRAY') { - if (ref($to->[0]) eq 'ARRAY') { - $email = $to->[0][0]; - } else { - $email = $to->[0]; - } - } else { - $email = $to; - } - my ($domain) = $email =~ m{ @ (.*) \z }x; - return $c->model('DB::Abuse')->search( { email => [ $email, $domain ] } )->first; -} - =head2 get_param $param = $c->get_param('name'); |