[Mimedefang] Debugging message modification

Philip Prindeville philipp_subx at redfish-solutions.com
Wed Mar 13 21:01:18 EDT 2024


Hi,

I added DKIM signatures via filter_wrapup() but I'm seeing weirdness when mailing mailing lists and autoresponders where the DKIM signature seems to appear to be part of the message.

I can post the function if that helps.

Right now, I thought it would help if I wrote the modified message to a file, but the header that I added via action_add_header() doesn't present when I call $entity->stringily() and write that to a flat file.

Something like:

    my $dkim = Mail::DKIM::Signer->new(
    ...
    );

    if (open(TOSIGN, "<INPUTMSG")) {
	while (<TOSIGN>) {
	    chomp;
	    s/\r$//;

	    $dkim->PRINT("$_\r\n");
	}
	$dkim->CLOSE();

	md_syslog('debug', "Adding DKIM header");

	my ($header, $signature) = split(/:\s+/i, $dkim->signature()->as_string(), 2);
	$signature =~ s/\r\n/\n\g;

	action_add_header($header, $signature);

        if (@Recipients == 1 && focus($Recipients[0]) eq 'xyzzy at gmail.com') {
    	    open(COPY, ">/tmp/signed.eml");
            print COPY $entity->stringify();
            close(COPY);
        }
    }
}


But when I look at the logs and the file, the logs say the header was added... but the flat file written out shows otherwise.

What am I doing wrong?

Looking at the documentation, it says:

5) After filter_end returns, the function filter_wrapup is called if it has been defined. It is passed a single argument consisting of the (possibly modified) MIME::Entity object representing the message about to be delivered, including any modifications made in filter_end. Within filter_wrapup, you can not call functions that modify the message body, but you can still add or modify message headers.

But also:

action_add_header(\$hdr, \$val)Add a header to the message. This can be used in filter_begin or filter_end. The \$hdr component is the header name without the colon, and the \$val is the header value. For example, to add the header:
<!-- -->

    X-MyHeader: A nice piece of text

use:
    action_add_header("X-MyHeader", "A nice piece of text");


Wait, what?  We "can still add or modify message headers", but action_add_header() doesn't seem to be callable from within filter_wrapup(), only filter_begin() and filter_end().

Is there another way we're expected to add headers?

Thanks,

-Philip





More information about the MIMEDefang mailing list