[Mimedefang] Patch: adding custom headers for SpamAssassin
Kevin A. McGrail
kmcgrail at pccc.com
Fri Sep 22 11:33:07 EDT 2006
Here's what I do:
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 LIKE:
# 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;
$header = $params{'header'};
$header =~ s/^([^:.]*): .*$/$1/;
if (-s "./INPUTMSG" < 256*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 .= $_;
}
}
}
seek $filehandle, 0, 0;
print $filehandle $output;
close ($filehandle);
#md_syslog('warning', "Adding $params{'header'} immediately");
}
>> It's just a simple way (a global array) to add headers to the temprary
>> message created for SpamAssassin, so that these headers may be included
>> in rules and in the bayes automagic. The change to mimedefang.pl is
>> small.
>
> I'd rather not add yet another global variable. A long-range TODO at
> Roaring Penguin is to rewrite MIMEDefang to be more CPAN-like and not rely
> on global variables. So incurring more technical debt now is probably not
> a great idea. :-)
>
> However, maybe I can code it as a callback to add the headers, or find
> some other way to do it... I'll have a look.
More information about the MIMEDefang
mailing list