[Mimedefang] documentation bug/omission for newbies

starlight.2016q2 at binnacle.cx starlight.2016q2 at binnacle.cx
Sun Apr 17 17:35:07 EDT 2016

[edited slightly from original to pass filter]


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 hard-bounce via filter_sender() a recent clueless null-sender spam barrage, and the desire to hard bounce obfuscated-sender ESP spam from unknown ESP clients.

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);
my $bh = defined $part0 ? $part0->bodyhandle : undef;
if (defined $bh && (my $bio = $bh->open("r"))) {
    while (defined($_ = $bio->getline)) {
	if (m/MATCH SOME TEXT/) {
	    $bdyscn_flag = 1; last
if ($bdyscn_flag) {
   # do something

to solve this sort of problem without resorting to calling


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