1

I have never used procmail before but I believe (from my R&D) that it is likely my best choice to crack my riddle. Our system receives an email, out of which I need 3 values, which are:

  1. either a 4-digit or 5-digit integer from the SUBJECT line. (we will refer to as "N")

  2. email alias from REPLY-TO line (we will refer to as "R")

  3. determine the type of email it is, by which I mean to say a "case" or a "project". (we will refer to as "T") This value would be parsed out of the SUBJECT line.

If any one could help me with that recipe, I would be most appreciative.

The next thing I need to do is:

  1. send these 3 values to a Python script (can I do this directly from procmail? pipe? something else?)
  2. delete the email messages

I need to accept these emails from only 4 domain names, such as:

(@sjobeck.com|@cases.example.com|@messages.example.com|@bounces.example.com)

Last, is to pipe these 3 values in to the second script, and some advice as to the best syntax to do so. Any advice here is most appreciative. Would this be something like this:

this-recipe $N $T $R | second-script.py

Or exactly how would that look? Or is this not a procmail issue and a Python issue? (if it is, that's fine, I'll handle it over there.)

Thanks so much!

Jason

1 Answers1

1

Procmail can extract those values, or you can just pass the whole message to Python on stdin.

Assuming you want the final digits and you require there to be 4 or 5, something like this:

R=`formail -zxReply-to: | sed 's/.*<//;s/>.*//'`
:0
* ^From:.*@(helpicantfindgoogle\.com|searchengineshateme\.net|disabled\.org)\>
* ^Subject:(.*[^0-9])?\/[0-9][0-9][0-9][0-9][0-9]?$
| scriptname.py --reply-to "$R" --number "$MATCH"

This illustrates two different techniques for extracting a header value; the Reply-To header is extracted by invoking formail (this will extract just the email terminus, as per your comment; if you mean something else by "alias" then please define it properly) while the trailing 4- or 5-number integer from the Subject is grabbed my matching it in the condition with the special operator \/.

Update: Added an additional condition to only process email where the From: header indicates a sender in one of the domains helpicantfindgoogle.com, searchengineshateme.net, or disabled.org.

As implied by the pipe action, your script will be able to read the triggering message on its standard input, but if you don't need it, just don't read standard input.

If delivery is successful, Procmail will stop processing when this recipe finishes. Thus you should not need to explicitly discard a matching message. (If you want to keep going, use :0c instead of just :0.)

As an efficiency tweak (if you receive a lot of email, and only a small fraction of it needs to be passed to this script, for example) you might want to refactor to only extract the Reply-To: when the conditions match.

:0
* ^From:.*@(helpicantfindgoogle.com|searchengineshateme\.net|disabled\.org)\>
* ^Subject:(.*[^0-9])?\/[0-9][0-9][0-9][0-9][0-9]?$
{
  R=`formail -zxReply-To: | sed 's/.*<//;s/>.*//'`
  :0
  | scriptname.py --reply-to "$R" --number "$MATCH"
}

The block (the stuff between { and }) will only be entered when both the conditions are met. The extraction of the number from the Subject: header into $MATCH works as before; if the From: condition matched and the Subject: condition matched, the extracted number will be in $MATCH.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thx much. I am close. I now see that I need to better parse the REPLYTO line so Thanks much. I am getting close. I now see I need to better parse the REPLY-TO. I would like to get the contents of what is between the "<" and ">" symbols, and ignore all else for that email alias. A sample of what I am getting now is: procmail: Assigning "R=Jason SJOBECK " – Jason Sjobeck Dec 11 '12 at 08:23
  • Can you kindly help with a pattern match to accept only mail from my 4 domains? Thx so much! – Jason Sjobeck Dec 11 '12 at 08:24
  • Updated answer. HTH, HAND. – tripleee Dec 11 '12 at 08:34
  • Fantastic stuff. Will be testing tonight after-hours. Thx again. Will report back. – Jason Sjobeck Dec 11 '12 at 21:15
  • Thx, good sir. (I'm off to the next piece of my puzzle, which is nearly complete, which is writing the 2 values into mySQL, then I'm done.) Namaste. – Jason Sjobeck Dec 12 '12 at 04:21
  • I am sorry but while writing my other new script I realized that I did not handle one other variable. I edited the question above to include the new variable. I would also like to make one tiny tweak to your good suggestion for "MATCH" and from now on refer to that value as "N". Thanks again, really, thanks, for the hand on this. – Jason Sjobeck Dec 12 '12 at 07:19
  • You keep on piling on requirements. I see no effort of your own to solve these issues. If you need help, we're here, but this is a site for technical questions, not a free coding service. – tripleee Dec 12 '12 at 16:25
  • That is not an accurate statement at all. I apologized. I did not know until I got there. It is also not accurate to state no effort on my part as I have invested many many hours of my time in to learning this and perfecting this on my side. I have thanked you profusely every chance I have got & I want to do so again now. You have been wonderfully helpful. I really appreciate your valuable time & considerable skill. – Jason Sjobeck Dec 12 '12 at 17:03
  • I appreciate the thanks but I think you need to examine the goals, rules, and conventions of this site. My suggestion would be for you to revert your latest edit, and post a new, separate, self-contained question about the particular issue you still need help with. It's certainly okay to include a link to this question for background if you think it's necessary. – tripleee Dec 12 '12 at 17:17