summaryrefslogtreecommitdiff
path: root/FS/FS/msg_template
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-04-30 18:07:50 -0700
committerMark Wells <mark@freeside.biz>2016-04-30 18:08:03 -0700
commitf13259886f97a172b13c963b6d70a41c25228beb (patch)
treea313bc6c33a6ba6fa1523b299d3b7212fcd07118 /FS/FS/msg_template
parentd66fbc1d7e47e4356cedf92a397d38aa6b8cb7a4 (diff)
allow sending email to specific contact classes, #33316
Diffstat (limited to 'FS/FS/msg_template')
-rw-r--r--FS/FS/msg_template/email.pm33
1 files changed, 26 insertions, 7 deletions
diff --git a/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm
index 4ed582b..47df4db 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;