#!/usr/bin/perl
##########################################################################
# $Id: vpopmail,v 1.4 2002/10/12 02:08:19 kirk Exp $
##########################################################################
# Written & Maintained by Chris Smith (csmith@squiz.net)
##########################################################################

$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

while (defined($ThisLine = <STDIN>)) {
   if (
         ( $ThisLine =~ /vpop_mail/ ) or
         ( $ThisLine =~ /vchkpw: login success (.*?)\:/i)
      ) {
      # We don't care about these
   } elsif (($VirtAccount) = ($ThisLine =~ /no virt found (.*?)\:/i )) {
      $NoAccount{$VirtAccount}++;
   } elsif (($ThisLine =~ /bounce msg/)) {
      $Bounce++;
   } elsif (($Email) = ($ThisLine =~ /password fail (.*?)\:/i )) {
      $PasswordFail{$Email}++;
   } elsif ((undef, $NoUser) = ($ThisLine =~ /(no user found|user not found) (.*?)\:/i )) {
      $NoUserFound{$NoUser}++;
   } else {
      # Report any unmatched entries...
      push @OtherList,$ThisLine;
   }
}

if ( (keys %PasswordFail) ) {
   print "\nPassword Failures:\n";
   foreach $Line (sort {$a cmp $b} keys %PasswordFail) {
      print "\t" . $Line . " - ". $PasswordFail{$Line} . " Time(s)\n";
   }
}

if ( (keys %NoAccount) ) {
   print "\nNo Account Found:\n";
   foreach $Line (sort {$a cmp $b} keys %NoAccount) {
      print "\t" . $Line . " - ". $NoAccount{$Line} . " Time(s)\n";
   }
}

if ( (keys %NoUserFound) ) {
   print "\nNo Such User Found:\n";
   foreach $Line (sort {$a cmp $b} keys %NoUserFound) {
      print "\t" . $Line . " - ". $NoUserFound{$Line} . " Time(s)\n";
   }
}

if ($Bounce) {
   print "\nBounced messages: ". $Bounce."\n";
}

if (($#OtherList >= 0) and (not $IngoreUnmatched)){
   print "\n**Unmatched Entries**\n";
   print @OtherList;
}

exit(0);

