Link to home
Start Free TrialLog in
Avatar of Terry Rogers
Terry RogersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Mimedefang Adding Footer

I currently have the following setup in my mimedefang-filter file in /etc/mail ...

 # Add footer to outgoing emails
    if ($Sender =~ /contractpoint.co.uk/) {
        $text_footer = " ";
        $html_footer = " ";
    }

    if ($Sender =~ /tradeonlyplumbing.co.uk/) {
        $text_footer = " ";
        $html_footer = " ";
    }

    if ($Sender =~ /tradeonlyplumbing.com/) {
        $text_footer = " ";
        $html_footer = " ";
    }

    if ($Sender =~ /williams.uk.com/) {
        $text_footer = ".";
        $html_footer = "<b>.</b>";
    }

    append_text_boilerplate($entity,$text_footer,0);
    append_html_boilerplate($entity,$html_footer,0);

I need this to be modified so that any mail going from @williams.uk.com to @tradeonlypluming.com, @tradeonlypluming.co.uk or @williams.uk.com does not have the filter added. This also needs to be the case for @tradeonlyplumbing.com and @tradeonlyplumbing.co.uk.

I also need to specify some email address's that wont have a footer added, namely any outgoing mail from mickwilliams@williams.uk.com will not have a footer added.

I need to add the footer if any external address is in cc or bcc fields as well, but not if its sender is one of a set.

This is urgent and requires implementing ASAP.
Avatar of PsiCop
PsiCop
Flag of United States of America image

Ugh.

Well, first, in your basic checking code, I wouldn't use $Sender, I'd use $RelayAddr. This is really more of a Perl programming issue. sendmail is only involved because MIMEDefang is a sendmail MILTER.

To check the TO:, CC: or BCC: fields, you're going to have to open and parse ./HEADERS - the MIMEDefang variables will only have the SMTP Envelope Headers, not the Message Headers.

Anyway, I'd have some list of your internal mail server IP addresses, perhaps in a hash:

%OurIPs = (   "10.1.2.3", 1, "192.168.11.11", 0 );

Where the Key is the IP address and the Value is a boolean indicator as to if E-Mail sent from that relay should get a footer.

Then, probably down in filter_end, you'd have code like this:

if ( exists($OurIPs{$RelayAddr}) )
   {
   # The sending host is one of our hosts, we need to think about footers
   if ( $OurIPs{$RelayAddr} )
       {
        # The boolean flag indicates the sending host is eligible to have
        #   footers appended
        ....
        parse ./HEADERS and add footers as appropriate
        ....
        }
     else
       {
        # This particular internal host is exempt from having footers appended
       }
else
    {
    # This isn't even our host
    # Run E-Mail thru SpamAssassin instead
    }

Again, this is more a Perl programming issue, and might be better-placed in the Perl TA.
Avatar of Terry Rogers

ASKER

The problem with that solution is that not all hosts are internal, so are not coming from specified relay address's, we use authentication on the sending side outside of our network.

Im not a perl programmer and someone else made up the code ive posted here. Any more ideas?
I don't understand how the solution I proposed won't work. So you strip out the check for whether or not the host is internal - big deal. The general approach is still the same - somewhere down in filter_end, you need to open and examine the ./HEADERS file (where MIMEDefang stores the Message Headers), parse out the "To:", "CC:" and "BCC:" lines, and apply your business logic to the decision to add the footer.

As I said above, this is really a Perl programming issue (how to write the code) as opposed to a sendmail or OS issue. I really think you should take it over to the Perl TA, and in your Question, you need to include (or link to) the appropriate bits of MIMEDefang documentation.

You might also try the MIMEDefang website --> http://www.mimedefang.org

They have a Wiki with code examples, and also a mailing list where this would be a good question.

I've written my own MIMEDefang filter, but mine is geared towards anti-SPAM, and doesn't really get into the type of Message Header examination you need. But MIMEDefang is the correct tool for the job.
Issue resolved with the following code ...

    my $text_footer;
    my $html_footer;

    # Add footer to outgoing emails
    if ($Sender =~ /contractpoint.co.uk/) {
        $text_footer = "";
        $html_footer = "";
    }

    if ($Sender =~ /tradeonlyplumbing.co.uk/) {
        $text_footer = "";
        $html_footer = "";
    }

    if ($Sender =~ /tradeonlyplumbing.com/) {
        $text_footer = "";
        $html_footer = "";
    }

    if ($Sender =~ /williams.uk.com/) {
        $text_footer = "";
        $html_footer = "";
    }

    if ($Sender =~ /mickwilliams/) {
        $text_footer = "";
        $html_footer = "";
    }

    if ($Sender =~ /raystafford/) {
        $text_footer = "";
        $html_footer = "";
    }

    # Do a final check and if ALL the addresses are internal, clear the headers

    my $one_external = 0;

    foreach $recip (@Recipients) {
        if ( !(($recip =~ /tradeonlyplumbing/) or ($recip =~ /williams.uk.com/) or ($recip =~ /contractpoint.co.uk/)) ) {
                $one_external = 1;
        }
    }

    if ( $one_external == 0 ) {
        $text_footer = "";
        $html_footer = "";
    }

    # We have to look at adding footers to *ALL* mails as we don't know if an 'internal' mail is
    # coming from an internal relay or interface.

    if ( $text_footer ne "" ) {
        append_text_boilerplate($entity,$text_footer,0);
    }

    if ( $html_footer ne "" ) {
        append_html_boilerplate($entity,$html_footer,0);
    }
Considering the Asker posted to the MIMEDefang mailing list as I suggested in one of my Comments, I don't see that a refund of points is appropriate.
No solution was provided, and the MIMEDefang mailing list also did not come up with anything, I had an external support company come up with the above solution.
*shrug* Whatever.
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial