From 3447296be3f44674e5628796c24ec3e7d433d29f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 24 Nov 2014 16:14:58 +0100 Subject: [PATCH] Bug 12802: Fix if AutoEmailOpacUser is enabled Test plan: Verify that the behavior of AutoEmailOpacUser still works as before. Note that now the email can receive several emails if AutoEmailPrimaryAddress has several values. Signed-off-by: Brendan Gallagher --- members/memberentry.pl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/members/memberentry.pl b/members/memberentry.pl index c58b2a9bff..1b34c91209 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -418,19 +418,15 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) { #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead - my $emailaddr; - if (C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' && - $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) { - $emailaddr = $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} - } - elsif ($newdata{email} =~ /\w\@\w/) { - $emailaddr = $newdata{email} + my @email_addresses; + for my $field ( split /,/, C4::Context->preference("AutoEmailPrimaryAddress") ) { + push @email_addresses, $_ if $newdata{$_} =~ /\w@\w/ } - elsif ($newdata{emailpro} =~ /\w\@\w/) { - $emailaddr = $newdata{emailpro} - } - elsif ($newdata{B_email} =~ /\w\@\w/) { - $emailaddr = $newdata{B_email} + my $emailaddr = join ", ", @email_addresses; + unless ( $emailaddr ) { + for my $field ( qw( email emailpro B_email ) ) { + $emailaddr = $newdata{$field} if $newdata{$field} =~ m|\w\@\w|; + } } # if we manage to find a valid email address, send notice if ($emailaddr) { -- 2.11.0