#!/usr/local/bin/perl

open( LYNX, "cat global.gen|" );
#open( LYNX, "lynx -dump http://www.uiuc.edu/ph/www/tskirvin/global/global.gen|" )
#	|| die "open(lynx)\n";

while( <LYNX> ) { last if /^==Generic Global Killfile==/ }

$state = 'prename';
print <<EOT;
# This tin killfile has been automatically generated by 
# global.tin.pl. You should probably rerun this script rather than 
# editing this file directly.  The Global Killfile is located at:
# http://www.uiuc.edu/ph/www/tskirvin/global/
# This script can be found at:
# http://www.uiuc.edu/ph/www/tskirvin/global/global.pl
# This (alpha) script is based off of a script by Brian Edmonds (with 
# permission) for use with the Internet blacklist.  The original script 
# can be found at:
# http://www.cs.ubc.ca/spider/edmonds/usenet/gnus/blacklist.pl

EOT

print "# Begin Global Killfile Additions\n";
while( <LYNX> ) {
  last if /^==Generic Global Killfile End==/;
  if( /^Name:\s+(.*)/ ) {
    $state = 'premail'; $name = $1;
  } elsif( $state eq 'premail' && /^Mail:\s+(.*)/ ) {
    $state = 'inemail';
#    print "  ;; $name\n";
    for $f (split(/,/,$1)) {
      $f = $1;
#      $f =~ s/^\s|\s$//g; $f =~ s/^,|,$//g;
# Must use a filter thingie again...
      print ":0:\n* ^From.*$f\n/dev/null\n\n";
    }
  } elsif( $state eq 'inemail' && /^\s+(.*)/ ) {
    for $f (split(/,/,$1)) {
       $f = $1;
#      $f =~ s/^\s|\s$//g; $f =~ s/^,|,$//g;
      print "2 K\n0\n*$f*\n";
    }
  } elsif( $state eq 'inemail' ) {
    $state = 'prename';
  }
} close LYNX;
print "# End Global Killfile Additions\n";

# EOF
