[Mimedefang] Modifying Headers Before Milter Does

Kevin A. McGrail kmcgrail at pccc.com
Mon Aug 6 14:37:31 EDT 2007


If you want SA to trigger on a header when it is called from MIMEDefang, 
I've written a function to do this. I don't know a better way to do this but 
as DFS put it, holy overhead batman!

You need to call it as WELL as a normal change_header routine such as:

action_change_header("X-RelayRegistry", "Passed - ". $answer[0]->string);
&append_header_immediately(header=>"X-RelayRegistry: Passed - " . 
$answer[0]->string);

sub change_header_immediately {
  my (%params) = @_;

  &append_header_immediately(%params, change=>1);

  #md_syslog('warning', "Changing $params{'header'} immediately");
}

sub append_header_immediately {
  #IN ORDER TO HAVE A HEADER TEST IN SPAMASSASSIN REACT TO DATA THAT MD 
CREATES, WE HAVE TO EDIT THE INPUTMSG FILE PRIOR TO
  #CALLING SA.  USING action_change_header, ETC WILL NOT WORK.  NO CHANGES 
TO THIS FILE ARE SAVED SO IF YOU WANT HEADERS
  #ADDED OR APPENDED, USE STANDARD MD CALLS ALSO!!!:
  #
  # action_change_header('Date', $date);
  # &change_header_immediately(header=>"Date: $date");

  my (%params) = @_;

  my ($filehandle, $output, $firstlineonly, $header);

  $filehandle = new IO::File('+< ./INPUTMSG');

  $firstlineonly = 1;

  $params{'change'} ||= 0;
  $params{'kilobyte_limit'} ||= 256;

  $header = $params{'header'};
  $header =~ s/^([^:.]*): .*$/$1/;

  if (-s "./INPUTMSG" == 0) {
    md_syslog('warning', "INPUTMSG is Size 0");
  }

  if (-s "./INPUTMSG" < $params{'kilobyte_limit'}*1024 && $filehandle) {
    while (<$filehandle>) {
      if ($params{'change'} > 0) {
        if ($_ =~ /^$header:/) {
          $output .= "$params{'header'}\n";
        } else {
          $output .= $_;
        }
      } elsif ($_ =~ /^$/ && $firstlineonly) {
        $output .= "$params{'header'}\n$_";
        $firstlineonly = 0;
      } else {
        $output .= $_;
      }
    }

    if ($output eq '') {
      md_syslog('warning', '$output is blank');
    }
    seek $filehandle, 0, 0;
    print $filehandle $output;
    close ($filehandle);
  }
  #md_syslog('warning', "Adding $params{'header'} immediately");
}

Regards,
KAM

>> spamassassin to use in its rules. Right now, I'm writing this header
>> directly to the HEADERS file. It appears that spamassassin is supposed
>> to use this file.
>
>   It doesn't use the HEADERS file.  In mimedefang.pl, MD reads in the
> contents of INPUTMSG into an array.  It then prepends the synthesized
> headers to the array and passes that to its call to SA.  Look in
> mimedefang.pl at the spam_assassin_mail() procedure to see how this is
> done.  If you want to add your own headers, you would have to edit
> INPUTMSG. 




More information about the MIMEDefang mailing list