diff options
-rw-r--r-- | perllib/FixMyStreet/App.pm | 25 | ||||
-rw-r--r-- | t/app/helpers/send_email.t | 24 | ||||
-rw-r--r-- | t/app/helpers/send_email_sample.txt | 29 |
3 files changed, 58 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 3e3c9c8a8..44f85aa9f 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -7,6 +7,7 @@ use FixMyStreet; use FixMyStreet::Cobrand; use Memcached; use Problems; +use mySociety::Email; use Catalyst ( 'Static::Simple', # @@ -58,6 +59,16 @@ __PACKAGE__->config( user_model => 'DB::User', }, }, + no_password => { # use post confirm etc + credential => { # Catalyst::Authentication::Credential::Password + class => 'Password', + password_type => 'none', + }, + store => { # Catalyst::Authentication::Store::DBIx::Class + class => 'DBIx::Class', + user_model => 'DB::User', + }, + }, }, ); @@ -179,16 +190,22 @@ sub send_email { # render the template my $content = $c->view('Email')->render( $c, $template, $vars ); - # create an email + # create an email - will parse headers out of content my $email = Email::Simple->new($content); $email->header_set( ucfirst($_), $vars->{$_} ) for grep { $vars->{$_} } qw( to from subject); - # always send utf8 emails - $email->header_set( 'Content-Type' => 'text/plain; charset="utf-8"' ); + # pass the email into mySociety::Email to construct the on the wire 7bit + # format - this should probably happen in the transport instead but hohum. + my $email_text = mySociety::Email::construct_email( + { + _unwrapped_body_ => $email->body, # will get line wrapped + $email->header_pairs + } + ); # send the email - $c->model('EmailSend')->send($email); + $c->model('EmailSend')->send($email_text); return $email; } diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t index a44ddb01c..16e85b4ce 100644 --- a/t/app/helpers/send_email.t +++ b/t/app/helpers/send_email.t @@ -9,9 +9,10 @@ BEGIN { FixMyStreet->test_mode(1); } -use Test::More tests => 4; +use Test::More tests => 5; use Email::Send::Test; +use Path::Class; use_ok 'FixMyStreet::App'; my $c = FixMyStreet::App->new; @@ -20,7 +21,6 @@ my $c = FixMyStreet::App->new; $c->req->uri( URI->new('http://localhost/') ); $c->req->base( $c->req->uri ); - # set some values in the stash $c->stash->{foo} = 'bar'; @@ -34,19 +34,11 @@ ok $c->send_email( 'test', { to => 'test@recipient.com' } ), "sent an email"; my @emails = Email::Send::Test->emails; is scalar(@emails), 1, "caught one email"; -is $emails[0]->as_string, << 'END_OF_BODY', "email is as expected"; -Subject: test email -From: evdb@ecclestoad.co.uk -To: test@recipient.com -Content-Type: text/plain; charset="utf-8" - -Hello, - -This is a test email where foo: bar. - -utf8: 我们应该能够无缝处理UTF8编码 +# Get the email, check it has a date and then strip it out +my $email_as_string = $emails[0]->as_string; +ok $email_as_string =~ s{\s+Date:\s+\S.*?$}{}xms, "Found and stripped out date"; -Yours, - FixMyStreet. -END_OF_BODY +is $email_as_string, + file(__FILE__)->dir->file('send_email_sample.txt')->slurp, + "email is as expected"; diff --git a/t/app/helpers/send_email_sample.txt b/t/app/helpers/send_email_sample.txt new file mode 100644 index 000000000..c6bdac74f --- /dev/null +++ b/t/app/helpers/send_email_sample.txt @@ -0,0 +1,29 @@ +MIME-Version: 1.0 +Subject: test email =?utf-8?Q?=E2=98=BA?= +Content-Type: text/plain; charset="utf-8" +To: test@recipient.com +Content-Transfer-Encoding: quoted-printable +From: evdb@ecclestoad.co.uk + + Hello, + + This is a test email where foo: bar. + + utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0= +=E7=BC=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81 + + indented_text + + long line: Lorem ipsum dolor sit amet, consectetur adipisicing + elit, sed do eiusmod tempor incididunt ut labore et dolore + magna aliqua. Ut enim ad minim veniam, quis nostrud + exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat. Duis aute irure dolor in reprehenderit in voluptate + velit esse cillum dolore eu fugiat nulla pariatur. Excepteur + sint occaecat cupidatat non proident, sunt in culpa qui officia + deserunt mollit anim id est laborum. + + Yours, + FixMyStreet. + + |