Procmail Filtering From and Body

procmailregex

I have a script generated e-mail which comes in hourly. I do not need to see it except under certain conditions, and so I just want it filtered to its own mailbox. The message comes from cron, and I want to be careful not to filter out other cron messages, only this one based upon the source and content.

The body line (first line of the message starts with it) I am trying to match is:

/etc/cron.hourly/scriptrun:

Here is what I came up with that is NOT working. I am not sure where i went wrong.

:0 HB
* ^From:.*root@ns1.domain.net
* ^Subject: {Cron
* \/etc\/cron.hourly\/scriptrun
.Save/

Any ideas would be greatly appreciated.

Best Answer

It's not clear what you want the single left brace to match; the way it's now, it's a syntax error. I'll assume you simply want it to match literally.

:0
* ^From:.*root@ns1\.domain\.net
* ^Subject: \{Cron
* B ?? ^^/etc/cron\.hourly/scriptrun
.Save/

You'll notice the backslashes to match regex metacharacters literally (but slashes are not metacharacters, so we don't backslash them; and actually, \/ has a special meaning in Procmail, and doesn't match a literal slash!), and the B ?? to match just the one condition against the body. The double anchor ^^ is a Procmail construct which matches before the first character on the first line (and also after the last character on the last line).

I'll also note that what you see in your email client can be quite different from the raw message which Procmail processes; for example, in a multipart MIME message, the first line of the first body part will be preceded by a MIME preamble and a MIME boundary. For a simple Cron message, this is unlikely to be an issue, but I'm mentioning it just in case.

Related Topic