[Mimedefang] Header wrapping revisited

Nels Lindquist nlindq at maei.ca
Thu Feb 21 15:01:35 EST 2002


Okay, definitely making progress.

I tried modifying action_add_header from the latest beta instead, and 
here's what it looks like now:

sub action_add_header {
    use Mail::Header ();

    my($header, $value) = @_;
    my $headers = new Mail::Header (Modify => 1, FoldLength => 65);
    $headers->add($header, $value);
    unless (open(HDRS, ">>NEWHEADERS")) {
        syslog('err', "Could not open NEWHEADERS to add headers: 
$!");
        return;
    }
    my(@lines);
    my($thing);
    my($first) = 1;
    my (@newval) = $headers->get($header);
    my ($newval) = @newval;
    @lines = split("\n", $newval);

    # Change newlines to "\n"; they'll be changed back by MIMEDefang
    print HDRS "$header\n";
    foreach $thing (@lines) {
	if (!$first) {
	    print HDRS "\\n\t";
	}
	$first = 0;
	print HDRS "$thing";
    }
    print HDRS "\n";
    close(HDRS);
}

This works much better, except for two problems.  One is that 
mimedefang.c only allows size SMALLBUF (256 bytes) headers to be read 
in, so new headers larger than 256 bytes are truncated.

Again referencing the libmilter docs:
"....each line of the header must be under 2048 characters and should 
be under 998 characters."

Would it be better to increase the size of SMALLBUF, or define a 
special buffer size just for headers?

The second problem is that Mail::Header isn't doing a terribly good 
job of wrapping.

It's supposed to be biased toward splitting on commas, etc. but the 
header is coming out like so:

X-Spam-Status: Yes, hits=20.92 required=5 tests=NO_REAL_NAME
	    ,SMTPD_IN_RCVD,MSG_ID_ADDED_BY_MTA_2,PLING,CALL_1_800,REMOVA
	    L_INSTRUCTIONS,EXCUSE_3,REMOVE_SUBJ,EXCUSE_7,REMOVE_IN_QUOTE
	    S,UCE_MAIL_ACT,MAILTO_TO_REMOVE,MAILTO_LINK,MAILTO_WITH_SUBJ
	    ,A

----
Nels Lindquist <*>
Information Systems Manager
Morningstar Air Express Inc.




More information about the MIMEDefang mailing list