[freeside-commits] branch FREESIDE_4_BRANCH updated. c75a8d44ee34ed7cddf92d658322d095a90c0465
Ivan Kohler
ivan at freeside.biz
Sat Feb 13 16:09:15 PST 2021
The branch, FREESIDE_4_BRANCH has been updated
via c75a8d44ee34ed7cddf92d658322d095a90c0465 (commit)
from ef2d6c8f9174b7aa31b22fead1a9d9b558edf29f (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 c75a8d44ee34ed7cddf92d658322d095a90c0465
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sat Feb 13 16:09:14 2021 -0800
eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_prepared :/
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index 1c100eacd..139f05ddf 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -15,8 +15,7 @@ use Encode;
#instead
@ISA = qw( Exporter );
- at EXPORT_OK = qw( send_email generate_email send_fax
- email_sender_transport_or_error
+ at EXPORT_OK = qw( send_email generate_email send_fax _sendmail
states_hash counties cities state_label
card_types
pkg_freqs
@@ -281,27 +280,11 @@ sub send_email {
push @env_to, map { $_->address } Email::Address->parse($dest);
}
- my $transport = email_sender_transport_or_error($domain);
-
- my $error = '';
- if ( ref($transport) ) {
-
- local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
- local $@; # just in case
- eval { sendmail($message, { transport => $transport,
- from => $from,
- to => \@env_to }) };
-
- if (ref($@) and $@->isa('Email::Sender::Failure')) {
- $error = $@->code.' ' if $@->code;
- $error .= $@->message;
- } else {
- $error = $@;
- }
-
- } else {
- $error = $transport;
- }
+ my $error = _sendmail( $message, { 'from' => $from,
+ 'to' => \@env_to,
+ 'domain' => $domain,
+ }
+ );
# Logging
if ( $conf->exists('log_sent_mail') ) {
@@ -325,8 +308,9 @@ sub send_email {
}
-sub email_sender_transport_or_error {
- my $domain = shift;
+sub _sendmail {
+ my($message, $options) = @_;
+ my $domain = delete $options->{'domain'};
my %smtp_opt = ( 'host' => $conf->config('smtpmachine'),
'helo' => $domain,
@@ -347,7 +331,22 @@ sub email_sender_transport_or_error {
$smtp_opt{'ssl'} = 1 if $enc eq 'tls';
}
- Email::Sender::Transport::SMTP->new( %smtp_opt );
+ $options->{'transport'} = Email::Sender::Transport::SMTP->new( %smtp_opt );
+
+ my $error = '';
+
+ local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
+ local $@; # just in case
+ eval { sendmail($message, $options) };
+
+ if (ref($@) and $@->isa('Email::Sender::Failure')) {
+ $error = $@->code.' ' if $@->code;
+ $error .= $@->message;
+ } else {
+ $error = $@;
+ }
+
+ $error;
}
diff --git a/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm
index aebac74b7..8fb81f677 100644
--- a/FS/FS/msg_template/email.pm
+++ b/FS/FS/msg_template/email.pm
@@ -16,7 +16,7 @@ use HTML::TreeBuilder;
use Encode;
# needed to send email
-use FS::Misc qw( generate_email email_sender_transport_or_error );
+use FS::Misc qw( generate_email _sendmail );
use FS::Conf;
use Email::Sender::Simple qw( sendmail );
@@ -543,29 +543,13 @@ sub send_prepared {
# through Email::Address to make sure
my @env_to = map { $_->address } Email::Address->parse($cust_msg->env_to);
- my $transport = email_sender_transport_or_error($domain);
+ my $message = join("\n", $cust_msg->header, $cust_msg->body);
- my $error = '';
- if ( ref($transport) ) {
-
- warn "$me sending message\n" if $DEBUG;
- my $message = join("\n", $cust_msg->header, $cust_msg->body);
-
- local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
- local $@;
- eval { sendmail( $message, { transport => $transport,
- from => $cust_msg->env_from,
- to => \@env_to })
- };
- if (ref($@) and $@->isa('Email::Sender::Failure')) {
- $error = $@->code.' ' if $@->code;
- $error .= $@->message;
- } else {
- $error = $@;
- }
- } else {
- $error = $transport;
- }
+ my $error = _sendmail( $message, { 'from' => $cust_msg->env_from,
+ 'to' => \@env_to,
+ 'domain' => $domain,
+ }
+ );
$cust_msg->set('error', $error);
$cust_msg->set('status', $error ? 'failed' : 'sent');
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Misc.pm | 51 ++++++++++++++++++++++-----------------------
FS/FS/msg_template/email.pm | 30 +++++++-------------------
2 files changed, 32 insertions(+), 49 deletions(-)
More information about the freeside-commits
mailing list