- $_ = encode_entities($_ || '') foreach values(%hash);
-
- ###
- # clean up template
- ###
- my $subject_tmpl = new Text::Template (
- TYPE => 'STRING',
- SOURCE => $content->subject,
- );
- my $subject = $subject_tmpl->fill_in( HASH => \%hash );
-
- my $body = $content->body;
- my ($skin, $guts) = eviscerate($body);
- @$guts = map {
- $_ = decode_entities($_); # turn all punctuation back into itself
- s/\r//gs; # remove \r's
- s/<br[^>]*>/\n/gsi; # and <br /> tags
- s/<p>/\n/gsi; # and <p>
- s/<\/p>//gsi; # and </p>
- s/\240/ /gs; # and
- $_
- } @$guts;
-
- $body = '{ use Date::Format qw(time2str); "" }';
- while(@$skin || @$guts) {
- $body .= shift(@$skin) || '';
- $body .= shift(@$guts) || '';
- }
-
- ###
- # fill-in
- ###
-
- my $body_tmpl = new Text::Template (
- TYPE => 'STRING',
- SOURCE => $body,
- );
-
- $body = $body_tmpl->fill_in( HASH => \%hash );
-
- ###
- # and email
- ###
-
- my @to;
- if ( exists($opt{'to'}) ) {
- @to = split(/\s*,\s*/, $opt{'to'});
- }
- else {
- @to = $cust_main->invoicing_list_emailonly;
- }
- # no warning when preparing with no destination
-
- my $from_addr = $self->from_addr;
-
- if ( !$from_addr ) {
- if ( $opt{'from_config'} ) {
- $from_addr = scalar( $conf->config($opt{'from_config'},
- $cust_main->agentnum) );
- }
- $from_addr ||= scalar( $conf->config('invoice_from',
- $cust_main->agentnum) );
- }
-# my @cust_msg = ();
-# if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) {
-# my $cust_msg = FS::cust_msg->new({
-# 'custnum' => $cust_main->custnum,
-# 'msgnum' => $self->msgnum,
-# 'status' => 'prepared',
-# });
-# $cust_msg->insert;
-# @cust_msg = ('cust_msg' => $cust_msg);
-# }
-
- (
- 'custnum' => $cust_main->custnum,
- 'msgnum' => $self->msgnum,
- 'from' => $from_addr,
- 'to' => \@to,
- 'bcc' => $self->bcc_addr || undef,
- 'subject' => $subject,
- 'html_body' => $body,
- 'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70
- )->format( HTML::TreeBuilder->new_from_content($body) ),
- );
-