"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bin/BackupPC_sendEmail" between
BackupPC-4.3.2.tar.gz and BackupPC-4.4.0.tar.gz

About: BackupPC is a high-performance, enterprise-grade system for backing up Linux and WinXX PCs and laptops to a server’s disk (http/cgi user interface).

BackupPC_sendEmail  (BackupPC-4.3.2):BackupPC_sendEmail  (BackupPC-4.4.0)
skipping to change at line 33 skipping to change at line 33
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
#======================================================================== #========================================================================
# #
# Version 4.3.2, released 17 Feb 2020. # Version 4.4.0, released 20 Jun 2020.
# #
# See http://backuppc.sourceforge.net. # See http://backuppc.sourceforge.net.
# #
#======================================================================== #========================================================================
use strict; use strict;
no utf8; no utf8;
use lib "__INSTALLDIR__/lib"; use lib "__INSTALLDIR__/lib";
use BackupPC::Lib; use BackupPC::Lib;
use BackupPC::XS; use BackupPC::XS;
use BackupPC::DirOps; use BackupPC::DirOps;
use Encode; use Encode;
use Data::Dumper; use Data::Dumper;
use Getopt::Std; use Getopt::Std;
use vars qw($Lang $TopDir $BinDir $LogDir %Conf %HostConf $Hosts); use vars qw($Lang $TopDir $BinDir $LogDir %Conf %HostConf $Hosts);
skipping to change at line 97 skipping to change at line 98
# #
# However, if a user had multiple hosts, then an email about one # However, if a user had multiple hosts, then an email about one
# host prevents mail delivery about other hosts. Starting in 3.2.0 # host prevents mail delivery about other hosts. Starting in 3.2.0
# the hash is: # the hash is:
# #
# $UserEmailInfo{$user}{$host}{lastTime} # $UserEmailInfo{$user}{$host}{lastTime}
# $UserEmailInfo{$user}{$host}{lastSubj} # $UserEmailInfo{$user}{$host}{lastSubj}
# #
my $oldFormat = 0; my $oldFormat = 0;
foreach my $user ( keys(%UserEmailInfo) ) { foreach my $user ( keys(%UserEmailInfo) ) {
if ( defined($UserEmailInfo{$user}{lastTime}) if ( defined($UserEmailInfo{$user}{lastTime}) && ref($UserEmailInfo{$user}{l
&& ref($UserEmailInfo{$user}{lastTime}) ne 'HASH' ) { astTime}) ne 'HASH' ) {
$oldFormat = 1; $oldFormat = 1;
last; last;
} }
} }
if ( $oldFormat ) { if ( $oldFormat ) {
# #
# Convert to the new format # Convert to the new format
# #
my %UserEmailInfoOld = %UserEmailInfo; my %UserEmailInfoOld = %UserEmailInfo;
%UserEmailInfo = (); %UserEmailInfo = ();
skipping to change at line 135 skipping to change at line 135
} }
next if ( $UserEmailInfo{$user} ); next if ( $UserEmailInfo{$user} );
delete($UserEmailInfo{$user}); delete($UserEmailInfo{$user});
} }
my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}); my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
if ( $err ) { if ( $err ) {
if ( $opts{c} && $Conf{EMailAdminUserName} ne "" ) { if ( $opts{c} && $Conf{EMailAdminUserName} ne "" ) {
my $headers = $Conf{EMailHeaders}; my $headers = $Conf{EMailHeaders};
$headers .= "\n" if ( $headers !~ /\n$/ ); $headers .= "\n" if ( $headers !~ /\n$/ );
my $subject = $Conf{EMailAdminSubject} ne "" ? $Conf{EMailAdminSubject} my $subject =
: "BackupPC: can't connect $Conf{EMailAdminSubject} ne ""
to server"; ? $Conf{EMailAdminSubject}
: "BackupPC: can't connect to server";
my $mesg = <<EOF; my $mesg = <<EOF;
To: $Conf{EMailAdminUserName} To: $Conf{EMailAdminUserName}
Subject: $subject Subject: $subject
$headers $headers
Error: cannot connect to BackupPC server. Error: cannot connect to BackupPC server.
Regards, Regards,
PC Backup Genie PC Backup Genie
EOF EOF
SendMail($mesg); SendMail($mesg);
skipping to change at line 164 skipping to change at line 166
$reply = $1 if ( $reply =~ /(.*)/s ); $reply = $1 if ( $reply =~ /(.*)/s );
my(%Status, %Info, %Jobs, @BgQueue, @UserQueue, @CmdQueue); my(%Status, %Info, %Jobs, @BgQueue, @UserQueue, @CmdQueue);
eval($reply); eval($reply);
########################################################################### ###########################################################################
# Generate test message if required # Generate test message if required
########################################################################### ###########################################################################
if ( $opts{u} ne "" ) { if ( $opts{u} ne "" ) {
my $headers = $Conf{EMailHeaders}; my $headers = $Conf{EMailHeaders};
$headers .= "\n" if ( $headers !~ /\n$/ ); $headers .= "\n" if ( $headers !~ /\n$/ );
my $subject = $Conf{EMailAdminSubject} ne "" ? $Conf{EMailAdminSubject} my $subject =
: "BackupPC test email"; $Conf{EMailAdminSubject} ne ""
? $Conf{EMailAdminSubject}
: "BackupPC test email";
my $mesg = <<EOF; my $mesg = <<EOF;
To: $opts{u} To: $opts{u}
Subject: $subject Subject: $subject
$headers $headers
This is a test message from $0. This is a test message from $0.
Regards, Regards,
PC Backup Genie PC Backup Genie
EOF EOF
SendMail($mesg); SendMail($mesg);
exit(0); exit(0);
} }
########################################################################### ###########################################################################
# Generate per-host warning messages sent to each user # Generate per-host warning messages sent to each user
########################################################################### ###########################################################################
my @AdminBadHostsEmail = (); my @AdminBadHostsEmail = ();
my @AdminBadHosts = (); my @AdminBadHosts = ();
foreach my $host ( sort(keys(%Status)) ) { foreach my $host ( sort(keys(%Status)) ) {
# #
# read any per-PC config settings (allowing per-PC email settings) # read any per-PC config settings (allowing per-PC email settings)
# #
$bpc->ConfigRead($host); $bpc->ConfigRead($host);
%HostConf = $bpc->Conf(); %HostConf = $bpc->Conf();
my $user = $Hosts->{$host}{user}; my $user = $Hosts->{$host}{user};
# #
# Accumulate host errors for the admin email below # Accumulate host errors for the admin email below
# #
if ( ($Status{$host}{reason} eq "Reason_backup_failed" if ( ($Status{$host}{reason} eq "Reason_backup_failed" || $Status{$host}{r
|| $Status{$host}{reason} eq "Reason_restore_failed") eason} eq "Reason_restore_failed")
&& $Status{$host}{error} !~ /^lost network connection to host/ && $Status{$host}{error} !~ /^lost network connection to host/
&& !$HostConf{BackupsDisable} && !$HostConf{BackupsDisable} ) {
) {
push(@AdminBadHostsEmail, $HostConf{EMailAdminUserName}); push(@AdminBadHostsEmail, $HostConf{EMailAdminUserName});
push(@AdminBadHosts, "$host ($Status{$host}{error})"); push(@AdminBadHosts, "$host ($Status{$host}{error})");
} }
next if ( time - $UserEmailInfo{$user}{$host}{lastTime} next
< $HostConf{EMailNotifyMinDays} * 24*3600 if ( time - $UserEmailInfo{$user}{$host}{lastTime} < $HostConf{EMailNotify
|| $HostConf{XferMethod} eq "archive" MinDays} * 24 * 3600
|| $HostConf{BackupsDisable} || $HostConf{XferMethod} eq "archive"
|| $Hosts->{$host}{user} eq "" || $HostConf{BackupsDisable}
|| $user eq "" || $Hosts->{$host}{user} eq ""
); || $user eq "" );
my @Backups = $bpc->BackupInfoRead($host);
my $last = 0; my @Backups = $bpc->BackupInfoRead($host);
my $last = 0;
my $lastGoodOutlook = 0; my $lastGoodOutlook = 0;
my $lastNum = -1; my $lastNum = -1;
my $numBadOutlook = 0; my $numBadOutlook = 0;
my $numBackups = 0; my $numBackups = 0;
for ( my $i = 0 ; $i < @Backups ; $i++ ) { for ( my $i = 0 ; $i < @Backups ; $i++ ) {
my $fh; my $fh;
# #
# ignore partials and active backups -> only fulls and incrs # ignore partials and active backups -> only fulls and incrs
# should be used in figuring out when the last good backup was # should be used in figuring out when the last good backup was
# #
next if ( $Backups[$i]{type} eq "partial" || $Backups[$i]{type} eq "acti ve" ); next if ( $Backups[$i]{type} eq "partial" || $Backups[$i]{type} eq "acti ve" );
$lastNum = $Backups[$i]{num} if ( $lastNum < $Backups[$i]{num} ); $lastNum = $Backups[$i]{num} if ( $lastNum < $Backups[$i]{num} );
$last = $Backups[$i]{startTime} if ( $last < $Backups[$i]{startTime} ); $last = $Backups[$i]{startTime} if ( $last < $Backups[$i]{startTime}
);
$numBackups++; $numBackups++;
next if ( $Backups[$i]{xferMethod} ne "smb" ); next if ( $Backups[$i]{xferMethod} ne "smb" );
my $badOutlook = 0; my $badOutlook = 0;
my $comp = 0; my $comp = 0;
my $file = "$TopDir/pc/$host/XferLOG.$Backups[$i]{num}"; my $file = "$TopDir/pc/$host/XferLOG.$Backups[$i]{num}";
if ( !-f $file ) { if ( !-f $file ) {
$comp = 1; $comp = 1;
$file = "$TopDir/pc/$host/XferLOG.$Backups[$i]{num}.z"; $file = "$TopDir/pc/$host/XferLOG.$Backups[$i]{num}.z";
} }
next if ( !-f $file || !defined($fh = BackupPC::XS::FileZIO::open($file, 0, $comp)) ); next if ( !-f $file || !defined($fh = BackupPC::XS::FileZIO::open($file, 0, $comp)) );
while ( 1 ) { while ( 1 ) {
my $s = $fh->readLine(); my $s = $fh->readLine();
last if ( $s eq "" ); last if ( $s eq "" );
if ( $s =~ /^\s*Error reading file.*\.pst : (ERRDOS - ERRlock|NT_STA if ( $s =~ /^\s*Error reading file.*\.pst : (ERRDOS - ERRlock|NT_S
TUS_FILE_LOCK_CONFLICT)/ TATUS_FILE_LOCK_CONFLICT)/
|| $s =~ /^\s*Error reading file.*\.pst\. Got 0 bytes/ ) { || $s =~ /^\s*Error reading file.*\.pst\. Got 0 bytes/ ) {
$badOutlook = 1; $badOutlook = 1;
last; last;
} }
} }
$fh->close(); $fh->close();
$numBadOutlook += $badOutlook; $numBadOutlook += $badOutlook;
if ( !$badOutlook ) { if ( !$badOutlook ) {
$lastGoodOutlook = $Backups[$i]{startTime} $lastGoodOutlook = $Backups[$i]{startTime}
if ( $lastGoodOutlook < $Backups[$i]{startTime} ); if ( $lastGoodOutlook < $Backups[$i]{startTime} );
} }
} }
if ( $numBackups == 0 ) { if ( $numBackups == 0 ) {
my $subj = defined($HostConf{EMailNoBackupEverSubj}) my $subj =
? $HostConf{EMailNoBackupEverSubj} defined($HostConf{EMailNoBackupEverSubj})
: $Lang->{EMailNoBackupEverSubj}; ? $HostConf{EMailNoBackupEverSubj}
my $mesg = defined($HostConf{EMailNoBackupEverMesg}) : $Lang->{EMailNoBackupEverSubj};
? $HostConf{EMailNoBackupEverMesg} my $mesg =
: $Lang->{EMailNoBackupEverMesg}; defined($HostConf{EMailNoBackupEverMesg})
sendUserEmail($user, $host, $mesg, $subj, { ? $HostConf{EMailNoBackupEverMesg}
userName => user2name($user) : $Lang->{EMailNoBackupEverMesg};
}) if ( !defined($Jobs{$host}) ); sendUserEmail(
$user, $host, $mesg, $subj,
{
userName => user2name($user)
}
) if ( !defined($Jobs{$host}) );
next; next;
} }
if ( time - $last > $HostConf{EMailNotifyOldBackupDays} * 24*3600 ) { if ( time - $last > $HostConf{EMailNotifyOldBackupDays} * 24 * 3600 ) {
my $subj = defined($HostConf{EMailNoBackupRecentSubj}) my $subj =
? $HostConf{EMailNoBackupRecentSubj} defined($HostConf{EMailNoBackupRecentSubj})
: $Lang->{EMailNoBackupRecentSubj}; ? $HostConf{EMailNoBackupRecentSubj}
my $mesg = defined($HostConf{EMailNoBackupRecentMesg}) : $Lang->{EMailNoBackupRecentSubj};
? $HostConf{EMailNoBackupRecentMesg} my $mesg =
: $Lang->{EMailNoBackupRecentMesg}; defined($HostConf{EMailNoBackupRecentMesg})
my $firstTime = sprintf("%.1f", ? $HostConf{EMailNoBackupRecentMesg}
(time - $Backups[0]{startTime}) / (24*3600)); : $Lang->{EMailNoBackupRecentMesg};
my $days = sprintf("%.1f", (time - $last) / (24 * 3600)); my $firstTime = sprintf("%.1f", (time - $Backups[0]{startTime}) / (24 *
sendUserEmail($user, $host, $mesg, $subj, { 3600));
firstTime => $firstTime, my $days = sprintf("%.1f", (time - $last) / (24 * 3600));
days => $days, sendUserEmail(
userName => user2name($user), $user, $host, $mesg, $subj,
numBackups => $numBackups, {
}) if ( !defined($Jobs{$host}) ); firstTime => $firstTime,
days => $days,
userName => user2name($user),
numBackups => $numBackups,
}
) if ( !defined($Jobs{$host}) );
next; next;
} }
if ( $numBadOutlook > 0 if ( $numBadOutlook > 0 && time - $lastGoodOutlook > $HostConf{EMailNotifyOl
&& time - $lastGoodOutlook > $HostConf{EMailNotifyOldOutlookDays} dOutlookDays} * 24 * 3600 ) {
* 24 * 3600 ) {
my($days, $howLong); my($days, $howLong);
if ( $lastGoodOutlook == 0 ) { if ( $lastGoodOutlook == 0 ) {
$howLong = eval("qq{$Lang->{howLong_not_been_backed_up}}"); $howLong = eval("qq{$Lang->{howLong_not_been_backed_up}}");
} else { } else {
$days = sprintf("%.1f", (time - $lastGoodOutlook) / (24*3600)); $days = sprintf("%.1f", (time - $lastGoodOutlook) / (24 * 3600));
$howLong = eval("qq{$Lang->{howLong_not_been_backed_up_for_days_days }}"); $howLong = eval("qq{$Lang->{howLong_not_been_backed_up_for_days_days }}");
} }
my $subj = defined($HostConf{EMailOutlookBackupSubj}) my $subj =
? $HostConf{EMailOutlookBackupSubj} defined($HostConf{EMailOutlookBackupSubj})
: $Lang->{EMailOutlookBackupSubj}; ? $HostConf{EMailOutlookBackupSubj}
my $mesg = defined($HostConf{EMailOutlookBackupMesg}) : $Lang->{EMailOutlookBackupSubj};
? $HostConf{EMailOutlookBackupMesg} my $mesg =
: $Lang->{EMailOutlookBackupMesg}; defined($HostConf{EMailOutlookBackupMesg})
my $firstTime = sprintf("%.1f", ? $HostConf{EMailOutlookBackupMesg}
(time - $Backups[0]{startTime}) / (24*3600)); : $Lang->{EMailOutlookBackupMesg};
my $lastTime = sprintf("%.1f", my $firstTime = sprintf("%.1f", (time - $Backups[0]{startTime}) / (24 *
(time - $Backups[$#Backups]{startTime}) / (24*3600)); 3600));
sendUserEmail($user, $host, $mesg, $subj, { my $lastTime = sprintf("%.1f", (time - $Backups[$#Backups]{startTime})
days => $days, / (24 * 3600));
firstTime => $firstTime, sendUserEmail(
lastTime => $lastTime, $user, $host, $mesg, $subj,
numBackups => $numBackups, {
userName => user2name($user), days => $days,
howLong => $howLong, firstTime => $firstTime,
serverHost => $HostConf{ServerHost}, lastTime => $lastTime,
}) if ( !defined($Jobs{$host}) ); numBackups => $numBackups,
userName => user2name($user),
howLong => $howLong,
serverHost => $HostConf{ServerHost},
}
) if ( !defined($Jobs{$host}) );
} }
} }
# #
# Send per-host errors to per-host admin email # Send per-host errors to per-host admin email
# #
if ( @AdminBadHosts ) { if ( @AdminBadHosts ) {
for my $i (0 .. $#AdminBadHosts) { for my $i ( 0 .. $#AdminBadHosts ) {
my $badHost = $AdminBadHosts[$i]; my $badHost = $AdminBadHosts[$i];
if ( $AdminBadHostsEmail[$i] ne "" ) { if ( $AdminBadHostsEmail[$i] ne "" ) {
my $badHostMesg .= <<EOF; my $badHostMesg .= <<EOF;
The following host had an error that is probably caused by a The following host had an error that is probably caused by a
misconfiguration. Please fix this host: misconfiguration. Please fix this host:
- $badHost - $badHost
EOF EOF
my $headers = $Conf{EMailHeaders}; my $headers = $Conf{EMailHeaders};
$headers .= "\n" if ( $headers !~ /\n$/ ); $headers .= "\n" if ( $headers !~ /\n$/ );
my $subject = $Conf{EMailAdminSubject} ne "" ? $Conf{EMailAdminSubje my $subject =
ct} $Conf{EMailAdminSubject} ne ""
: "BackupPC administrat ? $Conf{EMailAdminSubject}
ive attention needed"; : "BackupPC administrative attention needed";
$badHostMesg = <<EOF; $badHostMesg = <<EOF;
To: $AdminBadHostsEmail[$i] To: $AdminBadHostsEmail[$i]
Subject: $subject Subject: $subject
$headers $headers
${badHostMesg}Regards, ${badHostMesg}Regards,
PC Backup Genie PC Backup Genie
EOF EOF
SendMail($badHostMesg); SendMail($badHostMesg);
} }
} }
skipping to change at line 354 skipping to change at line 369
########################################################################### ###########################################################################
# Generate sysadmin warning message # Generate sysadmin warning message
########################################################################### ###########################################################################
my $adminMesg = ""; my $adminMesg = "";
# #
# Report if we skipped backups because the disk was too full # Report if we skipped backups because the disk was too full
# #
if ( $Info{DUDailySkipHostCntPrev} > 0 ) { if ( $Info{DUDailySkipHostCntPrev} > 0 ) {
my $n = $Info{DUDailySkipHostCntPrev}; my $n = $Info{DUDailySkipHostCntPrev};
my $m = $Conf{DfMaxUsagePct}; my $m = $Conf{DfMaxUsagePct};
my $mInode = $Conf{DfMaxInodeUsagePct}; my $mInode = $Conf{DfMaxInodeUsagePct};
$adminMesg .= <<EOF; $adminMesg .= <<EOF;
Yesterday $n hosts were skipped because the file system containing Yesterday $n hosts were skipped because the file system containing
$TopDir was too full. The threshold in the configuration $TopDir was too full. The threshold in the configuration
file is currently $m%, while yesterday the file system was up file is currently $m%, while yesterday the file system was up
to $Info{DUDailyMaxPrev}% full. The maximum inode usage yesterday to $Info{DUDailyMaxPrev}% full. The maximum inode usage yesterday
was $Info{DUInodeDailyMaxPrev}% and the threshold is currently $mInode%. was $Info{DUInodeDailyMaxPrev}% and the threshold is currently $mInode%.
Please find more space on the file system, or reduce the number of full Please find more space on the file system, or reduce the number of full
or incremental backups that we keep. or incremental backups that we keep.
skipping to change at line 398 skipping to change at line 413
list that should be backed up then there is a problem with the list that should be backed up then there is a problem with the
hosts file: hosts file:
- $oldDirs - $oldDirs
EOF EOF
} }
if ( $adminMesg ne "" && $Conf{EMailAdminUserName} ne "" ) { if ( $adminMesg ne "" && $Conf{EMailAdminUserName} ne "" ) {
my $headers = $Conf{EMailHeaders}; my $headers = $Conf{EMailHeaders};
$headers .= "\n" if ( $headers !~ /\n$/ ); $headers .= "\n" if ( $headers !~ /\n$/ );
my $subject = $Conf{EMailAdminSubject} ne "" ? $Conf{EMailAdminSubject} my $subject =
: "BackupPC administrative atte $Conf{EMailAdminSubject} ne ""
ntion needed"; ? $Conf{EMailAdminSubject}
: "BackupPC administrative attention needed";
$adminMesg = <<EOF; $adminMesg = <<EOF;
To: $Conf{EMailAdminUserName} To: $Conf{EMailAdminUserName}
Subject: $subject Subject: $subject
$headers $headers
${adminMesg}Regards, ${adminMesg}Regards,
PC Backup Genie PC Backup Genie
EOF EOF
SendMail($adminMesg); SendMail($adminMesg);
} }
########################################################################### ###########################################################################
# Save email state and exit # Save email state and exit
########################################################################### ###########################################################################
if ( !$opts{t} ) { if ( !$opts{t} ) {
$Data::Dumper::Indent = 1; $Data::Dumper::Indent = 1;
my $dumpStr = Data::Dumper->Dump( my $dumpStr = Data::Dumper->Dump([\%UserEmailInfo], [qw(*UserEmailInfo)]);
[\%UserEmailInfo],
[qw(*UserEmailInfo)]);
if ( open(HOST, ">", "$LogDir/UserEmailInfo.pl") ) { if ( open(HOST, ">", "$LogDir/UserEmailInfo.pl") ) {
binmode(HOST); binmode(HOST);
print(HOST $dumpStr); print(HOST $dumpStr);
close(HOST); close(HOST);
} }
} }
exit(0); exit(0);
sub user2name sub user2name
{ {
my($user) = @_; my($user) = @_;
my($name) = (getpwnam($user))[6]; my($name) = (getpwnam($user))[6];
$name =~ s/\s.*//; $name =~ s/\s.*//;
$name = $user if ( $name eq "" ); $name = $user if ( $name eq "" );
return $name; return $name;
} }
sub sendUserEmail sub sendUserEmail
{ {
my($user, $host, $mesg, $subj, $vars) = @_; my($user, $host, $mesg, $subj, $vars) = @_;
return if ( $Conf{BackupsDisable} ); return if ( $Conf{BackupsDisable} );
$vars->{user} = $user; $vars->{user} = $user;
$vars->{host} = $host; $vars->{host} = $host;
$vars->{headers} = $Conf{EMailHeaders}; $vars->{headers} = $Conf{EMailHeaders};
$vars->{headers} .= "\n" if ( $vars->{headers} !~ /\n$/ ); $vars->{headers} .= "\n" if ( $vars->{headers} !~ /\n$/ );
$vars->{domain} = $Conf{EMailUserDestDomain}; $vars->{domain} = $Conf{EMailUserDestDomain};
$vars->{CgiURL} = $Conf{CgiURL}; $vars->{CgiURL} = $Conf{CgiURL};
$subj =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; $subj =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg;
$vars->{subj} = encode('MIME-Header', $subj); $vars->{subj} = encode('MIME-Header', $subj);
$mesg =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; $mesg =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg;
SendMail($mesg); SendMail($mesg);
$UserEmailInfo{$user}{$host}{lastTime} = time; $UserEmailInfo{$user}{$host}{lastTime} = time;
$UserEmailInfo{$user}{$host}{lastSubj} = $subj; $UserEmailInfo{$user}{$host}{lastSubj} = $subj;
} }
sub SendMail sub SendMail
{ {
my($mesg) = @_; my($mesg) = @_;
my $from = $Conf{EMailFromUserName}; my $from = $Conf{EMailFromUserName};
my $utf8 = 1 my $utf8 = 1
if ( $Conf{EMailHeaders} =~ /Content-Type:.*charset="utf-?8"/i ); if ( $Conf{EMailHeaders} =~ /Content-Type:.*charset="utf-?8"/i );
local(*MAIL); local(*MAIL);
if ( $opts{t} ) { if ( $opts{t} ) {
binmode(STDOUT, ":utf8") if ( $utf8 ); binmode(STDOUT, ":utf8") if ( $utf8 );
print("#" x 75, "\n"); print("#" x 75, "\n");
print $mesg; print $mesg;
return; return;
} }
$from = "-f $from" if ( $from ne "" ); $from = "-f $from" if ( $from ne "" );
print("Sending test email using $Conf{SendmailPath} -t $from\n") print("Sending test email using $Conf{SendmailPath} -t $from\n")
if ( $opts{u} ne "" ); if ( $opts{u} ne "" );
if ( !open(MAIL, "|$Conf{SendmailPath} -t $from") ) { if ( !open(MAIL, "|$Conf{SendmailPath} -t $from") ) {
print("Can't run sendmail ($Conf{SendmailPath}): $!\n"); print("Can't run sendmail ($Conf{SendmailPath}): $!\n");
return; return;
} }
binmode(MAIL, ":utf8") if ( $utf8 ); binmode(MAIL, ":utf8") if ( $utf8 );
print MAIL $mesg; print MAIL $mesg;
close(MAIL); close(MAIL);
} }
 End of changes. 31 change blocks. 
110 lines changed or deleted 129 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)