diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-15 18:31:52 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-08-01 11:52:22 +0100 |
commit | 1820db45188fd62699223f63167c5f7250d1b7a6 (patch) | |
tree | 116814d9bb6ebd7f6fa015d3e492993b620ac6b1 /perllib/FixMyStreet/TestMech.pm | |
parent | 0271c3fa016178f8c72b1192f1d0ed57437ec4c4 (diff) |
Add HTML email templates.
Design is all Zarino. This adds the ability to send HTML emails,
including attached inline images. When included, this is done as a
multipart/related email containing a multipart/alternative (of plain and
HTML) and any attached images, so that the images are available even if
HTML mail is not.
The alert emails list data has been improved so it can be constructed in
the templates rather than the code. Various templates have been tidied.
Various workarounds for email clients have been made, including:
* <th> is used so that the Android 4.x mail client can give them
`block` styling in the small screen media query.
* Font settings defined on every table cell (<th>) so that sans-serif
fonts are used in Outlook, rather than Times New Roman.
* A three-column wrapper table to create a 620px centred content area
that also shrinks down on narrow screens. (Outlook doesn’t like
max-width, so this is the simplest alternative.)
* Enforcing a sensible (500px) min-width for the main content area,
on clients that don’t support media queries (eg: native Gmail app).
* Giant borders on buttons so Outlook displays them
* Image alignment with align rather than float.
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 937780a31..5f4a6ceed 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -221,6 +221,48 @@ sub get_email { return $emails[0]; } +sub get_text_body_from_email { + my ($mech, $email, $obj) = @_; + unless ($email) { + $email = $mech->get_email; + $mech->clear_emails_ok; + } + + my $body; + $email->walk_parts(sub { + my $part = shift; + return if $part->subparts; + return if $part->content_type !~ m{text/plain}; + $body = $obj ? $part : $part->body; + ok $body, "Found text body"; + }); + return $body; +} + +sub get_link_from_email { + my ($mech, $email, $multiple) = @_; + unless ($email) { + $email = $mech->get_email; + $mech->clear_emails_ok; + } + + my @links; + $email->walk_parts(sub { + my $part = shift; + return if $part->subparts; + return if $part->content_type !~ m{text/}; + if (@links) { + # Must be an HTML part now, first two links are in header + my @html_links = $part->body =~ m{https?://[^"]+}g; + is $links[0], $html_links[2], 'HTML link matches text link'; + } else { + @links = $part->body =~ m{https?://\S+}g; + ok @links, "Found links in email '@links'"; + } + }); + return $multiple ? @links : $links[0]; +} + =head2 get_first_email $email = $mech->get_first_email(@emails); |