[Mimedefang] Dealing with HTML mail

David F. Skoll dfs at roaringpenguin.com
Tue Jul 30 15:43:00 EDT 2002


Hi,

I've been tweaking my filter and have come up with this nice set of rules
(simplified a bit below):

sub filter_begin {
    $SeenPlainText = 0;
}

sub filter {
    my($entity, $fname, $ext, $type) = @_;
    if ($type eq "text/plain") {
	$SeenPlainText = 1;
    }

    if ($type eq "text/html") {
	if ($SeenPlainText) {
	    syslog('info', "$MsgID: Dropping HTML part -- plain-text part seen");
	    return action_drop();
	}
    }
}

This is somewhat risky (you could conceivably have a message with unrelated
text/plain and text/html parts -- should really make sure you're in a
multipart/alternative container), but it works really well for me.  Lots
of dumb e-mail clients include both plain-text and HTML versions of
the same message.  This recipe nukes the HTML part.  (The plain-text
part invariably comes first, because the MIME spec says multipart/alternative
should start with the "simplest" version to render.)

Regards,

David.




More information about the MIMEDefang mailing list