Rename $msgs to $emailbody to improve readability

This commit is contained in:
Richard Hansen 2024-05-22 18:15:01 -04:00
parent 66ec57a902
commit f9dafa35a1

View file

@ -125,8 +125,8 @@ if ($program =~ /test/i) {
$savedir = 'URL'; $savedir = 'URL';
} }
my $msgs = ''; my $emailbody = '';
my $last_msgs = ''; my $last_emailbody = '';
## If run as *d (e.g., ddclientd) then daemonize by default (but allow ## If run as *d (e.g., ddclientd) then daemonize by default (but allow
## flags and options to override). ## flags and options to override).
@ -2311,19 +2311,19 @@ sub sendmail {
if (opt('mail-failure') && ($result ne 'OK' && $result ne '0')) { if (opt('mail-failure') && ($result ne 'OK' && $result ne '0')) {
$recipients = opt('mail-failure'); $recipients = opt('mail-failure');
} }
if ($msgs && $recipients && $msgs ne $last_msgs) { if ($emailbody && $recipients && $emailbody ne $last_emailbody) {
pipecmd("sendmail -oi $recipients", pipecmd("sendmail -oi $recipients",
"To: $recipients", "To: $recipients",
"Subject: status report from $program\@$hostname", "Subject: status report from $program\@$hostname",
"\r\n", "\r\n",
$msgs, $emailbody,
"", "",
"regards,", "regards,",
" $program\@$hostname (version $version)" " $program\@$hostname (version $version)"
); );
} }
$last_msgs = $msgs; $last_emailbody = $emailbody;
$msgs = ''; $emailbody = '';
} }
###################################################################### ######################################################################
## split_by_comma ## split_by_comma
@ -2390,7 +2390,7 @@ sub ynu {
my $_in_msg = 0; my $_in_msg = 0;
sub _msg { sub _msg {
my $fh = shift; my $fh = shift;
my $log = shift; my $email = shift;
my $prefix = shift; my $prefix = shift;
my $format = shift; my $format = shift;
my $buffer = sprintf $format, @_; my $buffer = sprintf $format, @_;
@ -2409,12 +2409,14 @@ sub _msg {
$buffer .= "\n"; $buffer .= "\n";
print $fh $buffer; print $fh $buffer;
$msgs .= $buffer if $log; if ($email) {
if ($log && !$_in_msg) { $emailbody .= $buffer;
if (!$_in_msg) {
++$_in_msg; # avoid infinite recursion if logger calls _msg ++$_in_msg; # avoid infinite recursion if logger calls _msg
logger($buffer); logger($buffer);
--$_in_msg; --$_in_msg;
} }
}
} }
sub msg { _msg(*STDOUT, 0, '', @_); } sub msg { _msg(*STDOUT, 0, '', @_); }