snippets

How do I catch ambiguous MIME structures and concatenated base64?

Some messages are built so that different mail clients, and scanners, see different content: base64 parts made of several base64 streams glued together, or repeated Content-Type and Content-Transfer-Encoding headers. MIMEDefang 3.8 detects both and logs a warning; md_concatenated_base64 and md_mime_suspicious let the filter act on them.

sub filter_begin {
    my ($entity) = @_;

    if (md_concatenated_base64()) {
        md_graphdefang_log('concatenated_base64');
        action_quarantine_entire_message('Base64 part with concatenated streams');
    }
    if (md_mime_suspicious()) {
        md_graphdefang_log('mime_suspicious');
        action_add_header('X-MIMEDefang-Warning', 'ambiguous MIME structure');
    }
}

Buggy but legitimate software can produce these messages too, so prefer quarantining or tagging to rejecting them. md_mime_suspicious always returns 0 if the installed MIME-tools cannot report ambiguous structures.