We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Mimedefang Adding Footer

Terry Rogers
Terry Rogers asked
on
Medium Priority
909 Views
Last Modified: 2013-12-17
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.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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.
CERTIFIED EXPERT

Commented:
Terry RogersIT Technical Architect

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
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.
Terry RogersIT Technical Architect

Author

Commented:
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);
    }
CERTIFIED EXPERT

Commented:
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.
Terry RogersIT Technical Architect

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
*shrug* Whatever.
Commented:
PAQd, 500 points refunded.

DarthMod
CS Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.