OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Duplicate messages with always_bcc

From: Ben (benBenjamin.it)
Date: Tue Jan 15 2008 - 23:21:46 CST


Hi, we use Postfix as an SMTP gateway. It does range of things such as
sending mail on to other servers, adding disclaimers to the footer of
certain emails, passing certain emails through to procmail to handle,
SPAM filter, virus filter, etc.

Every email that comes through also gets sent to a general email address
via always_bcc. This basically gets passed to a script which inserts the
mail into a CRM database if the mail was sent to or from one of our
customers. So, always_bcc sends to crmimportourdomain.com. If postfix
passes an email that contains that address, it then passes it to
procmail which then in turn passes it to a script to handle.

I have a procmail rule that basically reads, anything coming to
accountsourdomain.com, then pass it off to another script to handle.
This works, but the problem is that when an email is sent to
accountsourdomain.com, always_bcc comes into play and sends via bcc to
crmourdomain.com. The procmail rule that handles accountsourdomain.com
picks this up again which causes duplicate emails. I just have no idea
how I can get around this. I will post my relevant parts of some files:

main.cf:

smtp inet n - n - - smtpd
  -o always_bcc=crmimportourdomain.com
  -o cleanup_service_name=disclaimer-cleanup
procmail unix - n n - 10 pipe
  flags=hu user=mail argv=/usr/bin/procmail
dspam unix - n n - 10 lmtp
disclaimer-cleanup unix n - n - 0 cleanup
  -o always_bcc=crmimportgesix.com
  -o header_checks=pcre:$config_directory/headers_disclaimer

/etc/postfix/transport:
/^expensesourdomain\.com$/ procmail:expenses
/^crmimportourdomain\.com$/ procmail:crmimport

/etc/procmailrc:
:0w
* ^To:.*expensesourdomain\.com
* !.*crmimportourdomain\.com
* ^Subject:[ \t]*\/[^ ].*
| /usr/local/sbin/somescript.sh

# Catch all rule for crmimport to pickup all remaining messages
[ .. ]

So basically, any rule that gets sent off to procmail and gets caught in
a procmail rule will get generated twice. Seeing that always_bcc doesn't
change the To: header, it's always going to catch the same procmail rule.

Any help appreciated. Thanks.

Ben.