[Mimedefang] HTML mails problem

Amalarasan j.amalarasan at patni.com
Thu May 23 08:30:44 EDT 2002


Hi David,

    The filter is attached.

Thanks
Amal

"David F. Skoll" wrote:

> On Thu, 23 May 2002, Amalarasan wrote:
>
> > Now when I send an HTML mail from outlook express the
> > message is coming twice and then the boilerplate text.
>
> I'd need to see your filter.
>
> >     Also I want to disable mimedefang from doing all the spam filtering,
> > antivirus scanning, etc. How can I do this?.
>
> Edit the filter; see mimedefang-filter(5) man page.
>
> --
> David.
>
> _______________________________________________
> MIMEDefang mailing list
> MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

--

_______________________________________________________________________

J. Amalarasan
Senior Systems Engineer
Patni Computer Systems
Email: j.amalarasan at patni.com
Phone: 91 + 44 + 431 3261 - 65
Fax   : 91 + 44 + 431 3266
Extn  : 475

Res   : 91 + 44 + 2484685

-------------- next part --------------
# -*- Perl -*-
#***********************************************************************
#
# mimedefang-filter
#
# Suggested minimum-protection filter for Microsoft Windows clients, plus
# SpamAssassin checks if SpamAssassin is installed.
#
# Copyright (C) 2002 Roaring Penguin Software Inc.
#
# This program may be distributed under the terms of the GNU General
# Public License, Version 2, or (at your option) any later version.
#
# $Id: suggested-minimum-filter-for-windows-clients,v 1.23 2002/05/10 19:19:02 dfs Exp $
#***********************************************************************

#***********************************************************************
# Set administrator's e-mail address here.  The administrator receives
# quarantine messages and is listed as the contact for site-wide
# MIMEDefang policy.  A good example would be 'defang-admin at mydomain.com'
#***********************************************************************
$AdminAddress = 'amal at patni.com';
$AdminName = "Amalarasan";
$Email = 'netadmin at patni.com';

#***********************************************************************
# Set the e-mail address from which MIMEDefang quarantine warnings and
# user notifications appear to come.  A good example would be
# 'mimedefang at mydomain.com'.  Make sure to have an alias for this
# address if you want replies to it to work.
#***********************************************************************
$DaemonAddress = 'mimedefang at patni.com';

#***********************************************************************
# Set various stupid things your mail client does below.
#***********************************************************************

# Set the next one if your mail client cannot handle nested multipart
# messages
$Stupidity{"flatten"} = 0;

# Set the next one if your mail client cannot handle multiple "inline"
# parts (*cough* Exchange *cough* Outlook)
$Stupidity{"NoMultipleInlines"} = 0;


# This procedure returns true for entities with bad filenames.
sub filter_bad_filename {
    my($entity) = @_;
    return re_match($entity, '\.(bat|chm|cmd|com|cpl|dll|exe|hlp|hta|ini|js|lib|lnk|msi|msp|ocx|pif|reg|scr|sct|shb|shs|sys|vbe|vbs?|vxd|wsf|wsh)');
}

#***********************************************************************
# %PROCEDURE: filter_begin
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Called just before e-mail parts are processed
#***********************************************************************
sub filter_begin {
    $Boilerplate = "
http://www.patni.com
World-Wide Partnerships. World-Class Solutions.

This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to whom
this imessage was originally addressed. Any review, e-transmission dissemination
or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has beem forwarded to you without proper authority, please notify us immediately at $Email and delete this mail.";
     
    # ALWAYS drop messages with suspicious chars in headers or body
    if ($SuspiciousCharsInHeaders || $SuspiciousCharsInBody) {
	action_quarantine_entire_message();
	if ($SuspiciousCharsInHeaders) {
	    action_notify_administrator("Message quarantined because of suspicious characters in headers");
	} else {
	    action_notify_administrator("Message quarantined because of suspicious characters in body");
	}
	# Do NOT allow message to reach recipient(s)
	return action_discard();
    }

    # Spam checks if SpamAssassin is installed
    if ($Features{"SpamAssassin"}) {
	if (-s "./INPUTMSG" < 256*1024) {
    # Only scan messages smaller than 256kB.  Larger messages
    # are extremely unlikely to be spam, and SpamAssassin is
	    # dreadfully slow on very large messages.
	    my($hits, $req, $names, $report) = spam_assassin_check();
	    if ($hits >= $req) {
		my($score);
		if ($hits < 40) {
		    $score = "*" x int($hits);
		} else {
		    $score = "*" x 40;
		}
		# We add a header which looks like this:
		# X-Spam-Score: 6.8 (******) NAME_OF_TEST,NAME_OF_TEST
		# The number of asterisks in parens is the integer part
		# of the spam score clamped to a maximum of 40.
		# MUA filters can easily be written to trigger on a
		# minimum number of asterisks...
		action_change_header("X-Spam-Score", "$hits ($score) $names");
		$Boilerplate = $report;
	    }
	}
   }
}

#***********************************************************************
# %PROCEDURE: filter
# %ARGUMENTS:
#  entity -- a Mime::Entity object (see MIME-tools documentation for details)
#  fname -- the suggested filename, taken from the MIME Content-Disposition:
#           header.  If no filename was suggested, then fname is ""
#  ext -- the file extension (everything from the last period in the name
#         to the end of the name, including the period.)
#  type -- the MIME type, taken from the Content-Type: header.
#
#  NOTE: There are two likely and one unlikely place for a filename to
#  appear in a MIME message:  In Content-Disposition: filename, in
#  Content-Type: name, and in Content-Description.  If you are paranoid,
#  you will use the re_match and re_match_ext functions, which return true
#  if ANY of these possibilities match.  re_match checks the whole name;
#  re_match_ext checks the extension.  See the sample filter below for usage.
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  This function is called once for each part of a MIME message.
#  There are many action_*() routines which can decide the fate
#  of each part; see the mimedefang-filter man page.
#***********************************************************************
sub filter {
    my($entity, $fname, $ext, $type) = @_;

    if (filter_bad_filename($entity)) {
	return action_quarantine($entity, "An attachment named $fname was removed from this document as it\nconstituted a security hazard.  If you require this document, please contact\nthe sender and arrange an alternate means of receiving it.\n");
    }

    # eml is bad if it's not multipart
    if (re_match($entity, '\.eml')) {
	return action_quarantine($entity, "A non-multipart attachment named $fname was removed from this document as it\nconstituted a security hazard.  If you require this document, please contact\nthe sender and arrange an alternate means of receiving it.\n");
    }
    # Clean up HTML if Anomy::HTMLCleaner is installed.
    if ($Features{"HTMLCleaner"}) {
	if ($type eq "text/html") {
	    return anomy_clean_html($entity);
	}
   }

    return action_accept();
}

#***********************************************************************
# %PROCEDURE: filter_multipart
# %ARGUMENTS:
#  entity -- a Mime::Entity object (see MIME-tools documentation for details)
#  fname -- the suggested filename, taken from the MIME Content-Disposition:
#           header.  If no filename was suggested, then fname is ""
#  ext -- the file extension (everything from the last period in the name
#         to the end of the name, including the period.)
#  type -- the MIME type, taken from the Content-Type: header.
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  This is called for multipart "container" parts such as message/rfc822.
#  You cannot replace the body (because multipart parts have no body),
#  but you should check for bad filenames.
#***********************************************************************
sub filter_multipart {
    my($entity, $fname, $ext, $type) = @_;

    if (filter_bad_filename($entity)) {
	action_notify_administrator("A MULTIPART attachment of type $type, named $fname was dropped.\n");
	return action_drop_with_warning("An attachment of type $type, named $fname was removed from this document as it\nconstituted a security hazard.  If you require this document, please contact\nthe sender and arrange an alternate means of receiving it.\n");
    }

    # eml is bad if it's not message/rfc822
    if (re_match($entity, '\.eml') and ($type ne "message/rfc822")) {
	return action_drop_with_warning("A non-message/rfc822 attachment named $fname was removed from this document as it\nconstituted a security hazard.  If you require this document, please contact\nthe sender and arrange an alternate means of receiving it.\n");
    }

    return action_accept();
}


#***********************************************************************
# %PROCEDURE: defang_warning
# %ARGUMENTS:
#  oldfname -- the old file name of an attachment
#  fname -- the new "defanged" name
# %RETURNS:
#  A warning message
# %DESCRIPTION:
#  This function customizes the warning message when an attachment
#  is defanged.
#***********************************************************************
sub defang_warning {
    my($oldfname, $fname) = @_;
    return
	"An attachment named '$oldfname' was converted to '$fname'.\n" .
	"To recover the file, right-click on the attachment and Save As\n" .
	"'$oldfname'\n";
}

# If SpamAssassin found SPAM, append report.  We do it as a separate
# attachment of type text/plain
sub filter_end {
    my($entity) = @_;

    # No sense doing any extra work
    return if message_rejected();

    if ($Boilerplate ne "") {
	action_add_part($entity, "text/plain", "-suggest", "$Boilerplate\n",
		"SpamAssassinReport.txt", "inline");
   }
}

# DO NOT delete the next line, or Perl will complain.
1;



More information about the MIMEDefang mailing list