Operating System - HP-UX
1821051 Members
2763 Online
109631 Solutions
New Discussion

procmailrc script challenge

 
SOLVED
Go to solution
Fred G. Claypool, Jr.
Frequent Advisor

procmailrc script challenge

Hi everyone,

Is anyone out there in HP Forumsland really good at constructing .procmailrc recipes?

For several years now, we've used procmail to redirect "bounceback" messages to certain folks in our company. We use SAP, and when our [custom] SAP programming wants to email something, from sendmail's perspective, it's always "authored" by the SAP administrative user -- as opposed to the individual SAP user.

Therefore, it doesn't matter if Bob, Sally, or Frank send out an emailed purchase order. It all appears as if the single "sapadmin" user sent it out. If Bob, Sally, or Frank send something to "this_is_a_bad_address@nothere.com", that email will be undeliverable and thus it's sent back to the "sapadmin" user.

Our procmailrc script (in "sapadmin"'s home directory) receives the undeliverable message, and it looks at the Subject line to figure out to whom to forward the undeliverable message. If the subject line contains "Purchase Order: 12345", for example, our procmailrc script knows to forward this message back to Bob.

Whoops! What if Bob didn't send this email? Well, he's going to get it anyway.

Here's a section of our current procmailrc script:

-----------------------------------
:0 B
* ^Subject: Account Statement as of
! guy_in_credit_department@mycompany.com

:0 B
* ^Subject: Purchase Order
! lady_in_purchasing@mycompany.com

:0
! sysadms
-----------------------------------

So... after a while... Bob eventually gets ticked off that he's the recipient of one of his colleague's bad input of a customer's address. He might just ignore these forwarded undeliverable messages to him... and thus, the underlying problem is never resolved.

Here's what we'd like to occur. When our SAP programming constructs the body of the message (or maybe even in the headers of the message), we'll include the SAP user's name, such as:

X-sap-user: Sally

And then we'd like procmail, upon receiving an undeliverable message that Bob sent, to find this X-sap-user line (in either the header or body) and then cause the message to be forwarded to the X-sap-user name + "@mycompany.com". In the example above, it would be forwarded to Sally@mycompany.com.

Anybody know how to do something like that? :-)

Thanks,
~Fred
Experience gained while correcting a previous mistake is the best teacher imaginable!
1 REPLY 1
Heironimus
Honored Contributor
Solution

Re: procmailrc script challenge

The easy way is to pipe the message to a script that extracts/replaces the appropriate fields instead of trying to do it all inside procmail.

The hard way is to use \/ and $MATCH. I think something like "* ^X-sap-user: +\/[^ ]+" for your expression would put the field's value in $MATCH, but I'd have to play with it some.

The correct way is to have your SAP program set the sender appropriately when it generates a message so that procmail doesn't have to do anything.