From e031448c5911bd58dcf5daacae6c6755648fec5a Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Wed, 14 Dec 2016 13:00:24 -0800 Subject: [PATCH] fix parsing of multiple To: addresses, #73241 --- FS/FS/Misc.pm | 14 ++++++-------- httemplate/search/cust_msg.html | 5 ++++- httemplate/view/cust_msg.html | 4 +++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index eedc736ee..ff5723fd7 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -254,13 +254,11 @@ sub send_email { } push @to, $options{bcc} if defined($options{bcc}); - # make sure - my @env_to = split(/\s*,\s*/, join(', ', @to)); - # strip display-name from envelope addresses - foreach (@env_to) { - s/^\s*//; - s/\s*$//; - s/^(.*)\s*<(.*@.*)>$/$2/; + # fully unpack all addresses found in @to (including Bcc) to make the + # envelope list + my @env_to; + foreach my $dest (@to) { + push @env_to, map { $_->address } Email::Address->parse($dest); } local $@; # just in case @@ -281,7 +279,7 @@ sub send_email { if ( $conf->exists('log_sent_mail') ) { my $cust_msg = FS::cust_msg->new({ 'env_from' => $options{'from'}, - 'env_to' => join(', ', @to), + 'env_to' => join(', ', @env_to), 'header' => $message->header_as_string, 'body' => $message->body_as_string, '_date' => $time, diff --git a/httemplate/search/cust_msg.html b/httemplate/search/cust_msg.html index 2e1f75c81..fdb72a503 100644 --- a/httemplate/search/cust_msg.html +++ b/httemplate/search/cust_msg.html @@ -19,7 +19,10 @@ ucfirst($_[0]->msgtype) || $_[0]->msgname }, sub { - join('
', split(/,\s*/, $_[0]->env_to) ) + join('
', + map { encode_entities($_->format) } + Email::Address->parse($_[0]->env_to) + ) }, 'status', sub { encode_entities($_[0]->error) }, diff --git a/httemplate/view/cust_msg.html b/httemplate/view/cust_msg.html index 91a08ebda..d2b043c92 100755 --- a/httemplate/view/cust_msg.html +++ b/httemplate/view/cust_msg.html @@ -61,7 +61,9 @@ $custmsgnum =~ /^(\d+)$/ or die "illegal custmsgnum"; my $cust_msg = qsearchs('cust_msg', { 'custmsgnum' => $custmsgnum }); my $date = ''; $date = time2str('%Y-%m-%d %T', $cust_msg->_date) if ( $cust_msg->_date ); -my $env_to = join('', split(',', $cust_msg->env_to)); +my @to = map { encode_entities($_->format) } + Email::Address->parse($cust_msg->env_to); +my $env_to = join('', @to); my %label = ( 'sent' => 'Sent:', -- 2.11.0