X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fmsg_template%2Femail.pm;fp=FS%2FFS%2Fmsg_template%2Femail.pm;h=d1df5d61c7e141230f223bcc91a5b6757774efbd;hp=07a1fa0934d304916e3f7b05ee587572ee746407;hb=770d8237cda1b6459962d31f6ae86997ad5843be;hpb=8ff31f04ed1e2da3e09c56e72ab0f879d0b7ab75 diff --git a/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm index 07a1fa093..d1df5d61c 100644 --- a/FS/FS/msg_template/email.pm +++ b/FS/FS/msg_template/email.pm @@ -289,9 +289,25 @@ sub prepare { my @to; if ( exists($opt{'to'}) ) { + @to = split(/\s*,\s*/, $opt{'to'}); + } elsif ( $cust_main ) { - @to = $cust_main->invoicing_list_emailonly; + + if ( $opt{'to_contact_classnum'} ) { + + my $classnum = $opt{'to_contact_classnum'}; + my @classes = ref($classnum) ? @$classnum : split(',', $classnum); + if ( !@classes ) { + # traditional behavior: send to invoice email destinations (only) + @classes = ( 'invoice' ); + } + @to = $cust_main->contact_list_email(@classes); + # not guaranteed to produce contacts, but then customers aren't + # guaranteed to have email addresses on file. in that case, env_to + # will be null and sending this message will fail. + } + } else { die 'no To: address or cust_main object specified'; } @@ -324,13 +340,16 @@ sub prepare { ); warn "$me creating message headers\n" if $DEBUG; + # strip display-name from envelope addresses + # (use Email::Address for this? it chokes on non-ASCII characters in + # the display-name, which is not great for us) my $env_from = $from_addr; - $env_from =~ s/^\s*//; $env_from =~ s/\s*$//; - if ( $env_from =~ /^(.*)\s*<(.*@.*)>$/ ) { - # a common idiom - $env_from = $2; - } - + foreach ($env_from, @to) { + s/^\s*//; + s/\s*$//; + s/^(.*)\s*<(.*@.*)>$/$2/; + } + my $domain; if ( $env_from =~ /\@([\w\.\-]+)/ ) { $domain = $1;