More on procmail filtering – Dates
In my last blog, I went over some of the basic capabilities of procmail for mail filtering. Now, to look at it a bit more in depth.
Being the holiday season, the case that comes to mind is routing support emails to the on-call support tech. Our support emails are always routed to a group of users via a mail alias. However, during the holidays when our office is closed, we need to route these to the support tech that is on-call, in addition to the regular recipients.
As each tech is on-call for the day, one rule is put in for each day, such as the following:
:0 Hc
* $DATE ?? 2013-11-29.*
* ^To:.*support@ccscentral.com
* DEFAULT ??
!
Line one specifies that only the message headers need to be searched, and if everything in the rule matches, that a copy of the message is to be generated. The original message will go on to be delivered as normal.
Line two specifies the date that is to be matched. This is the date at the time of processing, not the date in the mail header. The "DATE" variable is set in the procmailrc file, via the declaration DATE=`date "+%Y-%m-%d"`. In other words, the variable DATE gets set to the date that the processing for the message begins, in YYYY-MM-DD format.
Line three matches only if "support@ccscentral.com" is in the "to" address of the email.
Line four checks that the mail is going to be delivered to a specific mailbox. In this case "
Line five is where the copy of the email is sent, in the case that everything in the prior lines matches. The "
So, to summarize this one:
If the date when the message is being processed is 2013-11-29 AND
The email has "support@ccscentral.com" in the "to" header AND
The mail is going to be delivered to the mailbox "
Then email a copy of the message to the email address "
By using the date capabilities of procmail, the support messages can be routed to the appropriate on-call tech automatically. They only receive the emails when they are on call, and no user intervention is needed.
Dave.
