#
# Module to check sender's address against known spammers for despam
# Copyright 1997 by Leslie M. Barstow III
#
package From;

#
# Setup routine
#
sub Setup
 {
  local(@line);
  local($counter,$tmpfile);
  ($tmpfile) = @_;
  open(TMPF,"$tmpfile");
if ($::debug)
 {
  print "Evaluating From lines in message\n";
 }
  while(<TMPF>)
   {
    if (/^(From|Sender|X-Sender|Message-ID|Received|Return-Path|Reply-To|X-Authenticated-Sender):\s*/)
     {
      $s_line[$counter++] = $';
     }
    last if (/^$/);
   }
  chomp @line;
  close(TMPF);
if ($::debug)
 {
  foreach $lin (@s_line)
   {
    print "     $lin\n";
   }
 }
  return(@s_line);
 }

#
# Comparison section
#
sub Compare
 {
  local($SPAMLIST);
  ($SPAMLIST) = @_;
  print "Unable to open $SPAMLIST.\n" unless open(SPAMF,"$SPAMLIST");
if ($::debug)
 {
  foreach $lin (@line)
   {
    print "     $lin\n";
   }
 }
  while(<SPAMF>)
   {
    next if (/^#/);
    ($flag, $line) = /(\S*)\s*(.*)/;
    if ($flag ne "From")
     {
      close(SPAMF);
if ($::debug)
 {
      print "despam: Expecting From line in $SPAMLIST.\n";
      print "        Please inform your administrator.\n";
 }
      return -1;
     }
    for ($i = 0; $i < scalar(@s_line); $i++)
     {
if ($::debug)
 {
      print "despam: comparing $s_line[$i] to $line\n";
 }
      if ($s_line[$i] =~ /$line/i)
       {
if ($::debug)
 {
        print "MATCH!\n";
 }
        return 1;
       }
     }
   }
  close(SPAMF);
  return 0;
 }

#
# Description section (return a short description)
#
sub Description
 {
  return "Compare From, Sender, and other headers against known addresses";
 }

1;
