[Mimedefang] documentation bug/omission for newbies

starlight.2016q2 at binnacle.cx starlight.2016q2 at binnacle.cx
Sun Apr 17 17:42:31 EDT 2016


Hello,

First, I must say MIMEDefang is awesome and thank you for this excellent software.

Am a causal email hacker trying to keep my private MTA alive in the ever thickening email jungle.  Lately have been increasing the degree of customization in MIMEDefang, with a trigger being the need to bounce via filter_sender() a recent clueless null-sender barrage, and the desire to bounce obfuscated-sender ESP messages.

Just reached the point where it is necessary to scan message text bodies with perl regexs and modify dispositions based on that.

The MIME::Tools aspect of hacking MIMEDefang could really benefit from a short but technically informative paragraph in the MAN pages and other documentation.

I just spent a day butting my head against the fact that filter_begin() is _always_ passed a multipart MIME message container that _never_ has a useable $entity->bodyhandle().  This is not mentioned anywhere.

Would have saved me that day if the above tidbit were mentioned and that one can easily write something similar to

my $bdyscn_flag = 0;
my $part0 = $entity->parts(0);
if (defined $part0) {
    my ($type, $subtype) = split('/', $part0->effective_type);
    my $bh = $type eq 'text' ? $part0->bodyhandle : undef;
    if (defined $bh && (my $bio = $bh->open("r"))) {
        while (defined($_ = $bio->getline)) {
            chomp;
            if (m/MATCH SOME TEXT/) {
                $bdyscn_flag = 1; last
            }
        }
        $bio->close;
    }
}
if ($bdyscn_flag) {
   # do something
}

to solve this sort of problem without resorting to calling

   $entity->make_singlepart()

which will (presumably) fail if MIME attachments are present.

-----

Also a warning to newbies to not try using INPUTMSG for this sort of activity would be very helpful.  Was frustrating learning the hard way that an INPUTMSG filter that works nicely with a simple netcat/nc/ncat plain-text test message will fail when presented with encoded body text from a remote MTA.  In vivid contrast to the normalized HEADERS file, INPUTMSG is not useful.

The most helpful bit of code to read for quickly grasping the streaming recursive-container nature of MIME is MIME::Tools::dump_entity().  Worth a mention in introductory material.




More information about the MIMEDefang mailing list