[freeside-commits] branch FREESIDE_4_BRANCH updated. 5c59bb1d95ae3f0def9981a087f09ab0a687015b

Mark Wells mark at 420.am
Wed Dec 14 13:42:18 PST 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  5c59bb1d95ae3f0def9981a087f09ab0a687015b (commit)
       via  2e6c36147f13355a4f17afc1ff2a30642acf089e (commit)
      from  63bef94c6f244d4569d969fd03e0a32e680d563e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5c59bb1d95ae3f0def9981a087f09ab0a687015b
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Dec 14 13:00:24 2016 -0800

    fix parsing of multiple To: addresses, #73241

diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index 9a43180..a2d1b3e 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -256,10 +256,17 @@ sub send_email {
   }
   
   push @to, $options{bcc} if defined($options{bcc});
+  # 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
   eval { sendmail($message, { transport => $transport,
                               from      => $from,
-                              to        => \@to }) };
+                              to        => \@env_to }) };
 
   my $error = '';
   if(ref($@) and $@->isa('Email::Sender::Failure')) {
@@ -274,7 +281,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/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm
index 5abbaca..63c860f 100644
--- a/FS/FS/msg_template/email.pm
+++ b/FS/FS/msg_template/email.pm
@@ -290,7 +290,7 @@ sub prepare {
   my @to;
   if ( exists($opt{'to'}) ) {
 
-    @to = split(/\s*,\s*/, $opt{'to'});
+    @to = map { $_->format } Email::Address->parse($opt{'to'});
 
   } elsif ( $cust_main ) {
 
@@ -393,14 +393,17 @@ sub prepare {
 
   # effective To: address (not in headers)
   push @to, $self->bcc_addr if $self->bcc_addr;
-  my $env_to = join(', ', @to);
+  my @env_to;
+  foreach my $dest (@to) {
+    push @env_to, map { $_->address } Email::Address->parse($dest);
+  }
 
   my $cust_msg = FS::cust_msg->new({
       'custnum'   => $cust_main ? $cust_main->custnum : '',
       'msgnum'    => $self->msgnum,
       '_date'     => $time,
       'env_from'  => $env_from,
-      'env_to'    => $env_to,
+      'env_to'    => join(',', @env_to),
       'header'    => $message->header_as_string,
       'body'      => $message->body_as_string,
       'error'     => '',
@@ -507,7 +510,9 @@ sub send_prepared {
     $domain = $1;
   }
 
-  my @to = split(/\s*,\s*/, $cust_msg->env_to);
+  # in principle should already be a list of bare addresses, but run it
+  # through Email::Address to make sure
+  my @env_to = map { $_->address } Email::Address->parse($cust_msg->env_to);
 
   my %smtp_opt = ( 'host' => $conf->config('smtpmachine'),
                    'helo' => $domain );
@@ -533,7 +538,7 @@ sub send_prepared {
   eval {
     sendmail( $message, { transport => $transport,
                           from      => $cust_msg->env_from,
-                          to        => \@to })
+                          to        => \@env_to })
   };
   my $error = '';
   if(ref($@) and $@->isa('Email::Sender::Failure')) {
diff --git a/httemplate/search/cust_msg.html b/httemplate/search/cust_msg.html
index 33e1815..65460f7 100644
--- a/httemplate/search/cust_msg.html
+++ b/httemplate/search/cust_msg.html
@@ -19,7 +19,10 @@
                               ucfirst($_[0]->msgtype) || $_[0]->msgname
                             },
                             sub {
-                              join('<BR>', split(/,\s*/, $_[0]->env_to) )
+                              join('<BR>',
+                                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 91a08eb..d2b043c 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('</TD></TR><TR><TD></TD><TD>', split(',', $cust_msg->env_to));
+my @to = map { encode_entities($_->format) }
+          Email::Address->parse($cust_msg->env_to);
+my $env_to = join('</TD></TR><TR><TD></TD><TD>', @to);
 
 my %label = (
   'sent'   => 'Sent:',

commit 2e6c36147f13355a4f17afc1ff2a30642acf089e
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Dec 14 13:07:57 2016 -0800

    Un-revert "Format email addresses w/Email::Address ... RT#73241"
    
    This reverts commit 018cafeda5005d9b7832194a7b6ad311e4d31238.

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 2b91156..e1f73bf 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -20,16 +20,17 @@ use base qw( FS::cust_main::Packages
 require 5.006;
 use strict;
 use Carp;
+use Try::Tiny;
 use Scalar::Util qw( blessed );
-use Time::Local qw(timelocal);
-use Data::Dumper;
+use List::Util qw(min);
 use Tie::IxHash;
+use File::Temp; #qw( tempfile );
+use Data::Dumper;
+use Time::Local qw(timelocal);
 use Date::Format;
 #use Date::Manip;
-use File::Temp; #qw( tempfile );
+use Email::Address;
 use Business::CreditCard 0.28;
-use List::Util qw(min);
-use Try::Tiny;
 use FS::UID qw( dbh driver_name );
 use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
 use FS::Cursor;
@@ -3277,8 +3278,9 @@ sub contact_list_email {
   my @emails;
   foreach my $contact (@contacts) {
     foreach my $contact_email ($contact->contact_email) {
-      push @emails,
-        $contact->firstlast . ' <' . $contact_email->emailaddress . '>';
+      push @emails,  Email::Address->new( $contact->firstlast,
+                                          $contact_email->emailaddress
+                     )->format;
     }
   }
   @emails;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Misc.pm                   |   11 +++++++++--
 FS/FS/cust_main.pm              |   16 +++++++++-------
 FS/FS/msg_template/email.pm     |   15 ++++++++++-----
 httemplate/search/cust_msg.html |    5 ++++-
 httemplate/view/cust_msg.html   |    4 +++-
 5 files changed, 35 insertions(+), 16 deletions(-)




More information about the freeside-commits mailing list