Bcc address for impending recur notices, RT#8953
authormark <mark>
Mon, 16 Aug 2010 17:49:03 +0000 (17:49 +0000)
committermark <mark>
Mon, 16 Aug 2010 17:49:03 +0000 (17:49 +0000)
FS/FS/Misc.pm
FS/FS/Schema.pm
FS/FS/msg_template.pm
httemplate/edit/msg_template.html

index 3b0616a..0e8d92b 100644 (file)
@@ -113,7 +113,7 @@ sub send_email {
 #         join("\n", map { "  $_: ". $options{$_} } keys %options ). "\n"
   }
 
-  my $to = ref($options{to}) ? join(', ', @{ $options{to} } ) : $options{to};
+  my @to = ref($options{to}) ? @{ $options{to} } : ( $options{to} );
 
   my @mimeargs = ();
   my @mimeparts = ();
@@ -172,7 +172,7 @@ sub send_email {
 
   my $message = MIME::Entity->build(
     'From'       => $options{'from'},
-    'To'         => $to,
+    'To'         => join(', ', @to),
     'Sender'     => $options{'from'},
     'Reply-To'   => $options{'from'},
     'Date'       => time2str("%a, %d %b %Y %X %z", time),
@@ -232,8 +232,11 @@ sub send_email {
     $transport = Email::Sender::Transport::SMTP->new( %smtp_opt );
   }
   
+  push @to, $options{bcc} if defined($options{bcc});
   local $@; # just in case
-  eval { sendmail($message, { transport => $transport }) };
+  eval { sendmail($message, { transport => $transport,
+                              from      => $options{from},
+                              to        => \@to }) };
  
   if(ref($@) and $@->isa('Email::Sender::Failure')) {
     return ($@->code ? $@->code.' ' : '').$@->message
@@ -257,6 +260,10 @@ Sender address, required
 
 Recipient address, required
 
+=item bcc
+
+Blind copy address, optional
+
 =item subject
 
 email subject, required
@@ -290,6 +297,7 @@ sub generate_email {
   my %return = (
     'from'    => $args{'from'},
     'to'      => $args{'to'},
+    'bcc'     => $args{'bcc'},
     'subject' => $args{'subject'},
   );
 
index dc8f2f3..076be7e 100644 (file)
@@ -2946,6 +2946,7 @@ sub tables_hashref {
         'body',         'blob', 'NULL',      '', '', '',
         'disabled',     'char', 'NULL',       1, '', '', 
         'from_addr', 'varchar', 'NULL',     255, '', '',
+        'bcc_addr',  'varchar', 'NULL',     255, '', '',
       ],
       'primary_key' => 'msgnum',
       'unique'      => [ ['msgname', 'mime_type'] ],
index d1db17d..1217421 100644 (file)
@@ -255,9 +255,10 @@ sub prepare {
   my $conf = new FS::Conf;
 
   (
-    'from' => $self->from || 
+    'from' => $self->from_addr || 
               scalar( $conf->config('invoice_from', $cust_main->agentnum) ),
     'to'   => \@to,
+    'bcc'  => $self->bcc_addr || undef,
     'subject'   => $subject,
     'html_body' => $body,
     'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70
@@ -398,26 +399,27 @@ sub _upgrade_data {
   my ($self, %opts) = @_;
 
   my @fixes = (
-    [ 'alerter_msgnum',  'alerter_template',   '',               '' ],
-    [ 'cancel_msgnum',   'cancelmessage',      'cancelsubject',  '' ],
-    [ 'decline_msgnum',  'declinetemplate',    '',               '' ],
-    [ 'impending_recur_msgnum', 'impending_recur_template', '',  '' ],
-    [ 'payment_receipt_msgnum', 'payment_receipt_email', '',     '' ],
-    [ 'welcome_msgnum',  'welcome_email',      'welcome_email-subject', 'welcome_email-from' ],
-    [ 'warning_msgnum',  'warning_email',      'warning_email-subject', 'warning_email-from' ],
+    [ 'alerter_msgnum',  'alerter_template',   '',               '', '' ],
+    [ 'cancel_msgnum',   'cancelmessage',      'cancelsubject',  '', '' ],
+    [ 'decline_msgnum',  'declinetemplate',    '',               '', '' ],
+    [ 'impending_recur_msgnum', 'impending_recur_template', '',  '', 'impending_recur_bcc' ],
+    [ 'payment_receipt_msgnum', 'payment_receipt_email', '',     '', '' ],
+    [ 'welcome_msgnum',  'welcome_email',      'welcome_email-subject', 'welcome_email-from', '' ],
+    [ 'warning_msgnum',  'warning_email',      'warning_email-subject', 'warning_email-from', '' ],
   );
  
   my $conf = new FS::Conf;
   my @agentnums = ('', map {$_->agentnum} qsearch('agent', {}));
   foreach my $agentnum (@agentnums) {
     foreach (@fixes) {
-      my ($newname, $oldname, $subject, $from) = @$_;
+      my ($newname, $oldname, $subject, $from, $bcc) = @$_;
       if ($conf->exists($oldname, $agentnum)) {
         my $new = new FS::msg_template({
            'msgname'   => $oldname,
            'agentnum'  => $agentnum,
            'from_addr' => ($from && $conf->config($from, $agentnum)) || 
                           $conf->config('invoice_from', $agentnum),
+           'bcc_addr'  => ($bcc && $conf->config($from, $agentnum)) || '',
            'subject'   => ($subject && $conf->config($subject, $agentnum)) || '',
            'mime_type' => 'text/html',
            'body'      => join('<BR>',$conf->config($oldname, $agentnum)),
index c38c40e..460f4dc 100644 (file)
               'fields' => [ 'msgname',
                             'subject',
                             'from_addr',
+                            'bcc_addr',
                             { field=>'body', type=>'htmlarea', width=>763 },
                           ],
               'labels' => { 'msgnum'    => 'Template',
                             'msgname'   => 'Template name',
                             'from_addr' => 'Return address',
+                            'bcc_addr'  => 'Bcc address (optional)',
                             'subject'   => 'Message subject',
                             'body'      => 'Message template',
                           },