#!/opt/bin/perl # ######################################################################### # # # Program for counting mails in mailfolders with certain properties # # # ######################################################################### # # # Version 1.1 - Written 29.02.96 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # Configure here the search directory: $dir = '/u/preport'; # Configure here the search pattern: $pat = '^erledigt|noteserl'; # Default settings: $version = 'version 1.1'; $self = $0; $self =~ s!^.*/!!; # Scan search directory: unless (opendir(DIR,"$dir")) { die "$self: can't open directory '$dir': $!\n"; } warn "$self: reading directory '$dir'...\n"; while ($file = readdir(DIR)) { next if $file eq '.'; next if $file eq '..'; next unless -f "$dir/$file"; if ($file =~ /$pat/o) { push(@list, "$dir/$file"); warn "$self: found file '$file'!\n"; } } closedir(DIR); unless (@list > 0) { die "$self: can't find files matching '$pat'!\n"; } # If STDERR is connected to a TTY, disable buffering: if (-t STDERR) { select(STDERR); $| = 1; select(STDOUT); } # Initialize: $dot = 0; $all = 0; $cnt = 0; $sum = 0; # Loop through list of folders: foreach $folder (@list) { # Loop through mail folder: unless (open(FOLDER, "<$folder")) { warn "$self: can't open folder '$folder': $!\n"; } else { warn "$self: scanning folder '$folder'...\n"; $k = 0; while () { chop; if (/^From \S/) { if ($k) { &accumulate; } $k = 1; $sig = 0; $who = ''; } if ($k) { if (/Bearbeiter:\s*(.+)$/) { if ($who ne '') { $who .= ",$1"; } else { $who = $1; } $_ = lc($_); } &checksum; } } close(FOLDER); if ($k) { &accumulate; } if ($dot) { print STDERR "\n"; $dot = 0; } } } unless ((-t STDOUT) && (open(MORE, "| more"))) { unless (open(MORE, ">-")) { die "$self: can't open STDOUT: $!\n"; } } print MORE "\n"; print MORE " Bearbeiterstatistik:\n"; print MORE " ====================\n"; print MORE "\n"; foreach $user (sort alphanumeric keys(%count)) { printf(MORE "%-20s : %5d ", $user, $count{$user}); $sum += $count{$user}; if ($count{$user} != 1) { print MORE "erledigte preports\n"; } else { print MORE "erledigter preport\n"; } } print MORE "\n"; printf(MORE "Gesamt : %5d Bearbeiter\n", $sum); printf(MORE "Gesamt : %5d preports gefunden\n", $all); printf(MORE "Gesamt : %5d preports ohne Mehrfachkopien\n", $cnt); print MORE "\n"; close(MORE); exit; sub alphanumeric { my($result); $result = ($count{$b} <=> $count{$a}); if ($result == 0) { return($a cmp $b); } else { return($result); } } sub accumulate { my($user); $all++; print STDERR "."; $dot++; if ($dot > 74) { print STDERR "\n"; $dot = 0; } unless ($duplicate{$sig}) { $cnt++; $duplicate{$sig} = 1; $who =~ s/\.//g; foreach $user (split(/[^a-zA-Z_]+/,lc($who))) { if ($user ne '') { $count{$user}++; } } } } sub checksum { my($i,$carry,$t); for ( $i=0; $i> 1) != $sig); $sig = $t; $sig += ord(substr($_,$i,1)) + $carry; } } __END__