Skip wrote:
What would be a command line equivalent that I can test this expression against
my current inbox in order to see if I would have had any FPs? Something like
for file in *; do egrep ^To:.*(?:,[^,]{1,80}){20} $file;done
but this will only check one line (the To: header is obviously many, many lines
long) and generates a syntax error as is.
perl script.pl *
==== script.pl
#! perl
use strict;
my @files = @ARGV;
foreach my $_file (@files) {
my %header = read_headers($_file) ;
if ($header{"to"} =~ /(?:,[^,]{1,80}){100}/) {
print "$_file: MATCH100\n";
} elsif ($header{"to"} =~ /(?:,[^,]{1,80}){50}/) {
print "$_file: MATCH50\n";
} elsif ($header{"to"} =~ /(?:,[^,]{1,80}){20}/) {
print "$_file: MATCH20\n";
}
}
# This reads all the headers, should we need them
sub read_headers()
{
my $_file = $_[0];
my $cur_hdr = ":"; # invalid
my %header = ();
open (IN, $_file) or die "Cannot open $_file: [EMAIL PROTECTED]";
while (<IN>) {
# compress whitespace (also remove trailing space)
$_ =~ s/\s+$//;
$_ =~ s/\s+/ /g;
# blank line: end of header
if (! /\S/) {
last;
}
# new header
if (/^(\S+):/) {
$cur_hdr = lc($1);
$header{$cur_hdr} .= $';
next;
}
# header continuation
if (/^\s+/) {
$header{$cur_hdr} .= $';
next;
}
# missing blank line.
last;
}
close(IN);
return %header;
}