diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Hackney.pm | 26 |
2 files changed, 25 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 52306af24..f88ad0051 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -255,7 +255,9 @@ sub update_contact : Private { $email =~ s/\s+//g; my $send_method = $c->get_param('send_method') || $contact->body->send_method || ""; my $email_unchanged = $contact->email && $email && $contact->email eq $email; - unless ( $send_method eq 'Open311' || $email_unchanged ) { + my $cobrand = $contact->body->get_cobrand_handler; + my $cobrand_valid = $cobrand && $cobrand->call_hook(validate_contact_email => $email); + unless ( $send_method eq 'Open311' || $email_unchanged || $cobrand_valid ) { $errors{email} = _('Please enter a valid email') unless is_valid_email_list($email) || $email eq 'REFUSED'; } diff --git a/perllib/FixMyStreet/Cobrand/Hackney.pm b/perllib/FixMyStreet/Cobrand/Hackney.pm index 234573e3e..459cf3e4d 100644 --- a/perllib/FixMyStreet/Cobrand/Hackney.pm +++ b/perllib/FixMyStreet/Cobrand/Hackney.pm @@ -3,7 +3,7 @@ use parent 'FixMyStreet::Cobrand::Whitelabel'; use strict; use warnings; -use mySociety::EmailUtil qw(is_valid_email); +use mySociety::EmailUtil qw(is_valid_email is_valid_email_list); sub council_area_id { return 2508; } sub council_area { return 'Hackney'; } @@ -155,9 +155,7 @@ sub get_body_sender { my $contact = $body->contacts->search( { category => $problem->category } )->first; - my $parts = join '\s*', qw(^ park : (.*?) ; estate : (.*?) ; other : (.*?) $); - my $regex = qr/$parts/i; - if (my ($park, $estate, $other) = $contact->email =~ $regex) { + if (my ($park, $estate, $other) = $self->_split_emails($contact->email)) { my $to = $other; if ($self->problem_is_within_area_type($problem, 'park')) { $to = $park; @@ -184,4 +182,24 @@ sub munge_sendreport_params { } } +sub _split_emails { + my ($self, $email) = @_; + + my $parts = join '\s*', qw(^ park : (.*?) ; estate : (.*?) ; other : (.*?) $); + my $regex = qr/$parts/i; + + my ($park, $estate, $other) = $email =~ $regex; + return ($park, $estate, $other); +} + +sub validate_contact_email { + my ( $self, $email ) = @_; + + return 1 if is_valid_email_list($email); + + my @emails = grep { $_ } $self->_split_emails($email); + return unless @emails; + return 1 if is_valid_email_list(join(",", @emails)); +} + 1; |