Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for perl-modules/Platon/Log/Mail/Postfix.pm between version 1.6 and 1.7

version 1.6, 2004/11/28 23:01:06 version 1.7, 2004/12/09 10:31:27
Line 10 
Line 10 
 # 2004-10-19 - created  # 2004-10-19 - created
 #  #
   
 # $Platon: perl-modules/Platon/Log/Mail/Postfix.pm,v 1.5 2004/10/31 11:52:30 rajo Exp $  # $Platon: perl-modules/Platon/Log/Mail/Postfix.pm,v 1.6 2004/11/28 23:01:06 rajo Exp $
   
 package Platon::Log::Mail::Postfix;  package Platon::Log::Mail::Postfix;
   
Line 54  sub savelog($$;)
Line 54  sub savelog($$;)
                 ($xx->{log_level}, $line) = ($line =~ m/^\[(\S+)\] (.*)$/o);                  ($xx->{log_level}, $line) = ($line =~ m/^\[(\S+)\] (.*)$/o);
         }          }
   
         ($xx->{process_name}, $line) = ($line =~ m/^postfix\/([^[\s]+)(.*)$/o);          ($xx->{process_name}, $line) = ($line =~ m/^([^[\s]+)(.*)$/o);
   
           # process pid is optional
         if ($line =~ s/^\[(\d+)\]: (.*)$/$2/o) {          if ($line =~ s/^\[(\d+)\]: (.*)$/$2/o) {
                 $xx->{pid} = $1;                  $xx->{pid} = $1;
         }          }
Line 62  sub savelog($$;)
Line 64  sub savelog($$;)
                 $xx->{pid} = 0;                  $xx->{pid} = 0;
         }          }
   
           #
           # Support for amavis
           # {{{
           #
           # Try to parse default log format (Debian GNU/Linux), see /etc/amavis/amavisd.conf
           # and README.customize.gz
   
           # %V a list of virus names found; contains at least one entry (possibly empty)
           #    if a virus was found, otherwise a null list
           # %F a list of banned file names
           # %D a list of recipients with successful delivery status (will get mail)
           # %s original envelope sender, rfc2821-quoted and enclosed in angle brackets
           # %o best attempt at determining true sender of the virus - normally same as %s
           # %R a list of original envelope recipients
           # %i quarantine id, e.g. name of the quarantine file, or empty ($VIRUSFILE)
           #    (for use in notification body, not headers)
           # %m 'Message-ID' header field body
           # %c spam level/hits (mnemonic: sCore) as provided by SpamAssassin
   
           #
           # $log_templ = '[? %#V |[? %#F |[?%#D|Not-Delivered|Passed]|BANNED name/type (%F)]|INFECTED (%V)],
           # [?%o|(?)|<%o>] -> [<%R>|,][? %i ||, quarantine %i], Message-ID: %m, Hits: %c';
           #
           if ($xx->{process_name} eq 'amavis') {
                   if ($line !~ m/^\(/o) { # startup messages, etc. ...
                            $xx->{rest} = $line;
                            return $self->_savelog($xx);
                   }
   
                   # $xx->{status} = "Not-Delivered" or "Passed" or "BANNED" or "INFECTED"
                   ($xx->{amavis_counter}, $xx->{status}, $line) = ($line =~ m/^\(\d+-(\d+)\) ([^,\s]+)[\s,]*(.*)$/o);
                   if ($xx->{status} eq 'INFECTED') {
                           ($xx->{amavis_virus_name}, $line) = ($line =~ m/^\(([^\)]+)\), (.*)$/o);
                   }
                   elsif ($xx->{status} eq 'BANNED') {
                           ($xx->{amavis_banned_file}, $line) = ($line =~ m/^name\/type \(([^\)]+)\), (.*)$/o);
                   }
                   elsif (($xx->{status} ne 'Passed') and ($xx->{status} ne 'Not-Delivered')) { # some error messages
                           $xx->{rest} = "$xx->{status} $line";
                           $xx->{status} = undef;
                           return $self->_savelog($xx);
                   }
                   ($xx->{from}, $xx->{recipients}, $line) = ($line =~ m/^(\S+) -> (\S+), (.*)$/o);
   
                   if ($line =~ m/^quarantine (\S+), /o) {
                           $xx->{amavis_quarantine} = $1;
                   }
   
                   ($xx->{"message-id"}, $xx->{amavis_SA_score}) = ($line =~ m/Message-ID: (\S+), Hits: (\S+)$/o);
                   $xx->{amavis_SA_score} = undef if ($xx->{amavis_SA_score} eq '-');
   
                   $xx->{from}                             =~ s/[\<>]//go;
                   $xx->{"message-id"}             =~ s/[\<>]//go;
   
                   my $retval;
                   my @rcpts = split /[<,>]+/, $xx->{recipients};
                   foreach my $to (@rcpts) {
                           next if ($to eq '');
                           $xx->{to} = $to;
                           $retval += $self->_savelog($xx);
                   }
   
                   return $retval;
   
           } # }}}
   
           #
           # Support for postfix
           # {{{
   
           $xx->{process_name} =~ s/^postfix\///og;
   
         if (( $xx->{postfix_key},       $xx->{rest})          if (( $xx->{postfix_key},       $xx->{rest})
                 = ($line =~ m/\s*(\S+) (.*)$/o)) {                  = ($line =~ m/\s*(\S+) (.*)$/o)) {
   
Line 163  sub savelog($$;)
Line 237  sub savelog($$;)
                                         ($xx->{status})  = ($status =~ m/^(\d+)/o);                                          ($xx->{status})  = ($status =~ m/^(\d+)/o);
                                         ($xx->{mail_to}) = ($status =~ m/<([^<>]+)>/o);                                          ($xx->{mail_to}) = ($status =~ m/<([^<>]+)>/o);
                                         $xx->{rest} = $rest;                                          $xx->{rest} = $rest;
                                         use Data::Dumper;  
                                         print Dumper($xx);  
                                 }                                  }
                                 elsif ($xx->{rest} =~ m/^([^(]+)\s*(\(.*\))$/o) {                                  elsif ($xx->{rest} =~ m/^([^(]+)\s*(\(.*\))$/o) {
                                         my ($info);                                          my ($info);
Line 175  sub savelog($$;)
Line 247  sub savelog($$;)
                                 }                                  }
                         }                          }
   
                           # try to parse status info from amavis:
                           # ... relay=127.0.0.1[127.0.0.1], delay=4, status=sent (250 2.6.0 Ok, id=32286-03, from MTA: 250 Ok: queued as 9A1491400624)
                           if ($xx->{rest} =~ m/queued as (\S+)\)$/o) {
                                   $xx->{new_postfix_key} = $1;
                           }
   
                         return $self->_savelog($xx);                          return $self->_savelog($xx);
                 } # }}}                  } # }}}
                 elsif ($xx->{process_name} eq 'qmgr') { # {{{                  elsif ($xx->{process_name} eq 'qmgr') { # {{{
Line 215  sub savelog($$;)
Line 293  sub savelog($$;)
                         ($xx->{client_hostname}, $xx->{client_ip}) = ($xx->{rest} =~ m/from (\S+)\[([\.0-9]+)\]/o);                          ($xx->{client_hostname}, $xx->{client_ip}) = ($xx->{rest} =~ m/from (\S+)\[([\.0-9]+)\]/o);
   
                         return $self->_savelog($xx);                          return $self->_savelog($xx);
                 }                  } # }}}
   
         }          }
   
Line 231  sub _savelog($$;)
Line 309  sub _savelog($$;)
   
         $self->{sql_insert}->execute(          $self->{sql_insert}->execute(
                 $data->{created},               $data->{host},                  $data->{log_level},                     $data->{process_name},                  $data->{created},               $data->{host},                  $data->{log_level},                     $data->{process_name},
                 $data->{pid},                   $data->{postfix_key},   $data->{client_hostname},       $data->{client_ip},             $data->{uid},                  $data->{pid},                   $data->{postfix_key},   $data->{new_postfix_key},       $data->{client_hostname},
                 $data->{"message-id"},  $data->{"resent-message-id"},   $data->{from},          $data->{to},                  $data->{client_ip},             $data->{uid},                   $data->{"message-id"},          $data->{"resent-message-id"},
                   $data->{from},                  $data->{to},
                 $data->{size},                  $data->{nrcpt},                 $data->{relay}, $data->{delay},                  $data->{size},                  $data->{nrcpt},                 $data->{relay}, $data->{delay},
                 $data->{status},                $data->{proto},                 $data->{helo},  $data->{sasl_method},                  $data->{status},                $data->{proto},                 $data->{helo},  $data->{sasl_method},
                 $data->{sasl_username}, $data->{rest}                  $data->{sasl_username},
                   $data->{amavis_counter},        $data->{amavis_virus_name},     $data->{amavis_banned_file},
                   $data->{amavis_quarantine},     $data->{amavis_SA_score},
                   $data->{rest}
         ) or warn $self->{sql_insert}->errstr;          ) or warn $self->{sql_insert}->errstr;
   
 } # }}}  } # }}}
Line 252  sub _init($$;)
Line 334  sub _init($$;)
         $self->prepare_keyword('sql_insert', "          $self->prepare_keyword('sql_insert', "
                 INSERT INTO " . $conf->table . "                  INSERT INTO " . $conf->table . "
                         (created, hostname, log_level, process_name,                          (created, hostname, log_level, process_name,
                         pid, postfix_key, client_hostname, client_ip, client_uid,                          pid, postfix_key, new_postfix_key, client_hostname,
                         message_id, resent_message_id, mail_from, mail_to,                          client_ip, client_uid, message_id, resent_message_id,
                           mail_from, mail_to,
                         mail_size, mail_nrcpt, relay, delay,                          mail_size, mail_nrcpt, relay, delay,
                         status, proto, helo, sasl_method,                          status, proto, helo, sasl_method,
                         sasl_username, message)                          sasl_username,
                           amavis_counter, amavis_virus_name, amavis_banned_file,
                           amavis_quarantine, amavis_SA_score,
                           message)
                 VALUES                  VALUES
                         (?, ?, ?, ?,                          (?, ?, ?, ?,
                         ?, ?, ?, ?, ?,  
                         ?, ?, ?, ?,                          ?, ?, ?, ?,
                         ?, ?, ?, ?,                          ?, ?, ?, ?,
                           ?, ?,
                           ?, ?, ?, ?,
                         ?, ?, ?, ?,                          ?, ?, ?, ?,
                         ?, ?)                          ?,
                           ?, ?, ?,
                           ?, ?,
                           ?)
                 ");                  ");
   
 } # }}}  } # }}}

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top