def scan_mail_log_line(line, collector):
 m = re.match('(\\S+ \\d+ \\d+:\\d+:\\d+) (\\S+) (\\S+?)(\\[\\d+\\])?: (.*)', line)
 if (not m):
  return
 (date, system, service, pid, log) = m.groups()
 date = dateutil.parser.parse(date)
 if (service == 'dovecot'):
  scan_dovecot_line(date, log, collector)
 elif (service == 'postgrey'):
  scan_postgrey_line(date, log, collector)
 elif (service == 'postfix/smtpd'):
  scan_postfix_smtpd_line(date, log, collector)
 elif (service == 'postfix/cleanup'):
  scan_postfix_cleanup_line(date, log, collector)
 elif (service == 'postfix/submission/smtpd'):
  scan_postfix_submission_line(date, log, collector)
 elif (service in ('postfix/qmgr', 'postfix/pickup', 'postfix/cleanup', 'postfix/scache', 'spampd', 'postfix/anvil', 'postfix/master', 'opendkim', 'postfix/lmtp', 'postfix/tlsmgr')):
  pass
 else:
  collector['other-services'].add(service)

def scan_mail_log_line ( line , collector ) : m = re . match ( '(\\S+ \\d+ \\d+:\\d+:\\d+) (\\S+) (\\S+?)(\\[\\d+\\])?: (.*)' , line ) if ( not m ) : return ( date , system , service , pid , log ) = m . groups ( ) date = dateutil . parser . parse ( date ) if ( service == 'dovecot' ) : scan_dovecot_line ( date , log , collector ) elif ( service == 'postgrey' ) : scan_postgrey_line ( date , log , collector ) elif ( service == 'postfix/smtpd' ) : scan_postfix_smtpd_line ( date , log , collector ) elif ( service == 'postfix/cleanup' ) : scan_postfix_cleanup_line ( date , log , collector ) elif ( service == 'postfix/submission/smtpd' ) : scan_postfix_submission_line ( date , log , collector ) elif ( service in ( 'postfix/qmgr' , 'postfix/pickup' , 'postfix/cleanup' , 'postfix/scache' , 'spampd' , 'postfix/anvil' , 'postfix/master' , 'opendkim' , 'postfix/lmtp' , 'postfix/tlsmgr' ) ) : pass else : collector [ 'other-services' ] . add ( service )
scan a log line and extract interesting data .