diff -Nur -x '*.orig' -x '*.rej' smeserver-mailstats-0.0.2/root/usr/bin/spamfilter-stats-7.pl mezzanine_patched_smeserver-mailstats-0.0.2/root/usr/bin/spamfilter-stats-7.pl --- smeserver-mailstats-0.0.2/root/usr/bin/spamfilter-stats-7.pl 2007-10-11 17:25:50.000000000 -0400 +++ mezzanine_patched_smeserver-mailstats-0.0.2/root/usr/bin/spamfilter-stats-7.pl 2007-10-11 17:25:24.000000000 -0400 @@ -76,6 +76,8 @@ # - sort out domains when more that one email address in recipient field # 0.6.16 - cb - fix date range bug (http://bugs.contribs.org/show_bug.cgi?id=3366) # 0.6.17 - cb - avoid numerous re-openings of config db +# 0.6.18 - cb - tidy up options configuration section +# 0.6.19 - cb - rename parse_args => analysis_period, and simplify # # TODO # ---- @@ -121,16 +123,19 @@ use Switch; my $hostname = hostname(); +my $cdb = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB : $!\n"; #Configuration section -my %opt = (); +my %opt = ( + version => '0.6.19', # please update at each change. + debug => 0, # guess what ? + sendmail => '/usr/sbin/sendmail', # Path to sendmail stub + from => 'spamfilter-stats', # Who is the mail from + mail => # mailstats email recipient + $cdb->get('mailstats')->prop('Email') || 'admin', + timezone => `date +%z`, +); -$opt{'version'} = '0.6.16'; # please update at each change. -$opt{'debug'} = 0; # guess what ? -$opt{'sendmail'} = '/usr/sbin/sendmail'; # Path to sendmail stub -$opt{'from'} = 'spamfilter-stats'; # Who is the mail from -#$opt{'mail'} = "admin"; - set from db now... -$opt{'timezone'} = `date +%z`; Date_Init("TZ=$opt{'timezone'}"); my $FetchmailIP = '127.0.0.200'; #Apparent Ip address of fetchmail deliveries @@ -232,7 +237,6 @@ # store the domain of interest. Every other records are stored in a 'Other' zone my $ddb = esmith::DomainsDB->open_ro or die "Couldn't open DomainsDB : $!\n"; -my $cdb = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB : $!\n"; foreach my $domain( $ddb->get_all_by_prop( type => "domain" ) ) { $byrcptdomain{ $domain->key }{ 'type' }='local'; @@ -253,7 +257,7 @@ } } -my ( $start, $end ) = parse_arg(); +my ( $start, $end ) = analysis_period(); # # First check current configuration for logging, DNS enable and Max threshold for spamassassin @@ -283,9 +287,6 @@ my $db = esmith::ConfigDB->open; my $record = $db->new_record('mailstats', { type => 'report', Status => 'enabled' }); $disabled = $false; } -# check mailstats email recipient -my $email = $cdb->get('mailstats')->prop('Email') || 'admin'; -$opt{'mail'} = $email; if ( !$RHSenabled || !$DNSenabled ) { @@ -942,10 +943,10 @@ ############################################################################# -######################################## -# Process parms # -######################################## -sub parse_arg { +################################################ +# Determine analysis period (start and end time) +################################################ +sub analysis_period { my $startdate = shift; my $enddate = shift; @@ -953,30 +954,11 @@ my $time = 0; my $start = UnixDate( $startdate, "%s" ); - my $end = UnixDate( $enddate, "%s" ); - - if ( !$start && !$end ) { - $end = time; - $start = $end - $secsinday; - return ( $start, $end ); - } - - if ( !$start ) { - $start = $end - $secsinday; - return ( $start, $end ); - } - - if ( !$end ) { - $end = $start + $secsinday; - return ( $start, $end ); - } - - if ( $start > $end ) { - return ( $end, $start ); - } - - return ( $start, $end ); + my $end = $enddate ? UnixDate( $enddate, "%s" ) : + $startdate ? $start + $secsinday : time; + $start = $startdate ? $start : $end - $secsinday; + return ( $start > $end ) ? ( $end, $start ) : ( $start, $end ); } sub dbg {