Finding key-value pairs in email body
"Komal Tagdiwala (ktagdiwa)" <[email protected]>
| Newsgroups | gmane.mail.procmail |
|---|---|
| Message-ID | <[email protected]> |
Requirement: Extract key-value pair from email body using procmail Example: If the email body contains the following key-value pair, procmail needs to detect its presence and extract the value which will be used later to manipulate the FROM header of the email. Email: [email protected]<mailto:[email protected]> I implemented this requirement as follows: 1. Declared a constant string "SENDER_KEY" in my procmailrc and initialized it to the string value of the key. In the above example, the key is "Email:" consequently, I added the following entry to my procmailrc SENDER_KEY = "Email:" 2. Having declared my key in procmailrc, I wrote a new recipe which uses the following criteria to extract the value contained in that key in the email body: a. If the email body contains the SENDER_KEY (i.e., "Email:") b. And if the email is sent from a specific address (example: [email protected]<mailto:[email protected]>) c. Then extract the key-value pair from the email body and replace the FROM address with the value extracted for the "Email:" key. For example, if the email body contained the key-value pair - Email: [email protected]<mailto:[email protected]>, the procmail recipe should extract [email protected]<mailto:[email protected]> from the message body and replace the FROM address with that address. Below is my recipe :0B *$$\SENDER_KEY { :0BH * ^(From):.*(\<ktagdiwa@cisco\.com) * ^Email:(.*\<)\/[^ ].* { EMAIL_FOUND=$MATCH } :0hfw | /opt/local/bin/formail -i "From: $EMAIL_FOUND" LOG="************************* EMAIL_FOUND is set to: '$EMAIL_FOUND' *************************" } Problem: The above recipe works fine when the email is created from scratch using MS Outlook but when the email is generated using a web-form or some other automation, the recipe does not find a match for the key "Email:" even though the key-value pair is present in that email. If I copy and paste the contents of the automated email into a brand new email created in MS Outlook, the same content works just fine but the original email results in a NO MATCH FOUND for the key "Email:". Below is an excerpt of the procmail log for the same content in two separate emails; first email is the original automated email which results in NO MATCH FOUND, while the second email contains the same content copied and pasted in a brand new email in Outlook which results in a MATCH FOUND. Procmail log excerpt for automated email (NO MATCH FOUND - Recipe does not work) procmail: Assigning "INCLUDERC=/home/cem/recipe-dev/rc.searchNameValuePairInBody" procmail: No match on "()Email:" Procmail log excerpt for same content pasted in a brand new email created in Outlook (MATCH FOUND - Recipe works as expected) procmail: Assigning "INCLUDERC=/home/cem/recipe-dev/rc.searchNameValuePairInBody" procmail: Match on "()Email:" procmail: Match on "^(From):.*(\<ktagdiwa@cisco\.com)" procmail: Assigning "MATCH=" procmail: Matched "[email protected]<mailto:[email protected]>" procmail: Match on "^Email:(.*\<)\/[^ ].*" procmail: Assigning "[email protected]<mailto:[email protected]>" procmail: Executing "/opt/local/bin/formail,-i,From: [email protected]<mailto:[email protected]>" procmail: Assigning "LOG=************************* EMAIL_FOUND is set to: '[email protected]<mailto:[email protected]>' *************************" ************************* EMAIL_FOUND is set to: '[email protected]<mailto:[email protected]>' ****** I am clueless as to why the recipe would not work for the original email but work for the same email content when sent in a brand new email created in MS Outlook. Any pointers? Thanks and regards, Komal [Description: cid:[email protected]] ------------------------------------------------------------------------------------------------------------------------------------------------------------------ Komal Tagdiwala | IT Engineer | Cisco Systems, Inc.| Contact Center Applications & Technologies 400 E Tasman Dr | SJC 12/3 | San Jose, CA 95134 | [email protected]<mailto:[email protected]> | Office: (408)527-2163 ------------------------------------------------------------------------------------------------------------------------------------------------------------------ This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/index.html ____________________________________________________________ procmail mailing list Procmail homepage: http://www.procmail.org/ [email protected] http://mailman.rwth-aachen.de/mailman/listinfo/procmail
image001.jpg
(image/jpeg, 1.7 KB) - not displayed