Since my previous patch could cause trouble with normal setups (mails
are counted more than once then) .. I rewrote it and added mail-queue-id
tracking in order to prevent such a behavior.
regards,
Patrick
--- /usr/sbin/mailgraph.old 2007-05-26 17:47:14.000000000 +0200
+++ /usr/sbin/mailgraph 2007-06-06 07:14:17.000000000 +0200
@@ -27,6 +27,8 @@
# don't cache more than minute because of daylight saving time switch
my @str2time_last_minute;
my $str2time_last_minute_timestamp;
+#tracking hash for mailqeue id's
+my %mqIDsL;
# 0: sec, 1: min, 2: h, 3: day, 4: month, 5: year
sub str2time($$$$$$$)
{
@@ -494,31 +496,80 @@
if($prog =~ /^postfix\/(.*)/) {
my $prog = $1;
- if($prog eq 'smtp') {
- if($text =~ /\bstatus=sent\b/) {
+ # once the postfix queue manager removes the email
+ # we can be sure it's processed, and thus erase the mail
+ # specific queue ID from the global hash
+ if($prog eq 'qmgr') {
+ if($text =~ /^([0-9A-F]+): removed/) {
+ my $mqid = $1;
+ my @mqIDs = values(%mqIDsL);
+ my $exists = grep /$mqid/i, @mqIDs;
+ if($exists == "1") {
+ delete $mqIDsL{$mqid};
+ }
+ }
+ }
+
+ elsif($prog eq 'smtp') {
+ #get the mail-specific queue ID
+ my(@mqiD) = split(/queued as (.*?)\)/, $text);
+ #check wether the queue id is already present in
+ #the global mqueueID-pool
+ my @mqIDs = values(%mqIDsL);
+ my $exists = grep /$mqiD[1]/i, @mqIDs;
+ if(($text =~ /\bstatus=sent\b/) && ($exists=="0")) {
return if $opt{'ignore-localhost'} and
$text =~
/\brelay=[^\s\[]*\[127\.0\.0\.1\]/;
return if $opt{'ignore-host'} and
$text =~
/\brelay=[^\s,]*$opt{'ignore-host'}/oi;
event($time, 'sent');
+ #push the specific mail queue ID into the
global mqIDs-pool
+ $mqIDsL{$mqiD[1]} = $mqiD[1];
}
elsif($text =~ /\bstatus=bounced\b/) {
event($time, 'bounced');
}
}
elsif($prog eq 'local') {
+ #get the queue ID
+ my(@mqiD) = split(/ /, $text);
+ my $mqid = substr($mqiD[0], 0, -1);
+ #check wether the queue id is already present in
+ #the global mqueueID-pool
+ my @mqIDs = values(%mqIDsL);
+ my $exists = grep /$mqid/i, @mqIDs;
if($text =~ /\bstatus=bounced\b/) {
event($time, 'bounced');
}
+ #
+ # Once a user uses a mail-retrieval tool like fetchmail
in conjunction with a MTA like postfix for local mail distribution
+ # the mail will be sent to a local user's mailbox and
thus should be considered as 'mail receiving'.
+ #
+ # Without this patch the mails would just stay
unaccounted for the graphs.
+ #
+ elsif(($text =~/\bstatus=sent\b/) && ($exists=="0")) {
+ event($time, 'received');
+ #push the specific mail queue ID into the global
mqIDs-pool
+ $mqIDsL{$mqid} = $mqid;
+
+ }
}
elsif($prog eq 'smtpd') {
- if($text =~ /^[0-9A-F]+: client=(\S+)/) {
- my $client = $1;
+ if($text =~ /^([0-9A-F]+): client=(\S+)/) {
+ #get the mail specific queue ID
+ my $mqid = "$1";
+ my $client = "$2";
+ #check if it's in the pool already
+ my @mqIDs = values(%mqIDsL);
+ my $exists = grep /$mqid/i, @mqIDs;
return if $opt{'ignore-localhost'} and
$client =~ /\[127\.0\.0\.1\]$/;
return if $opt{'ignore-host'} and
$client =~ /$opt{'ignore-host'}/oi;
- event($time, 'received');
+ return if $exists == "1";
+ event($time, 'received');
+ #push the specific mail queue ID into the
global mqIDs-pool
+ $mqIDsL{$mqid} = $mqid;
}
elsif($opt{'virbl-is-virus'} and $text =~
/^(?:[0-9A-F]+: |NOQUEUE: )?reject: .*: 554.* blocked using irbl.dnsbl.bit.nl/)
{
event($time, 'virus');