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: ktagdiwa(_at_)cisco(_dot_)com<mailto:ktagdiwa(_at_)cisco(_dot_)com>
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:
messenger(_at_)webex(_dot_)com<mailto:messenger(_at_)webex(_dot_)com>)
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:
ktagdiwa(_at_)cisco(_dot_)com<mailto:ktagdiwa(_at_)cisco(_dot_)com>, the
procmail recipe should extract
ktagdiwa(_at_)cisco(_dot_)com<mailto:ktagdiwa(_at_)cisco(_dot_)com> 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
"kveera(_at_)cisco(_dot_)com<mailto:kveera(_at_)cisco(_dot_)com>"
procmail: Match on "^Email:(.*\<)\/[^ ].*"
procmail: Assigning
"EMAIL_FOUND=kveera(_at_)cisco(_dot_)com<mailto:kveera(_at_)cisco(_dot_)com>"
procmail: Executing "/opt/local/bin/formail,-i,From:
kveera(_at_)cisco(_dot_)com<mailto:kveera(_at_)cisco(_dot_)com>"
procmail: Assigning "LOG=************************* EMAIL_FOUND is set to:
'kveera(_at_)cisco(_dot_)com<mailto:kveera(_at_)cisco(_dot_)com>'
*************************"
************************* EMAIL_FOUND is set to:
'kveera(_at_)cisco(_dot_)com<mailto:kveera(_at_)cisco(_dot_)com>' ******
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:image001.jpg@01CBF2C7.8F409860]
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Komal Tagdiwala | IT Engineer | Cisco Systems, Inc.| Contact Center
Applications & Technologies
400 E Tasman Dr | SJC 12/3 | San Jose, CA 95134 |
ktagdiwa(_at_)cisco(_dot_)com<mailto:ktagdiwa(_at_)cisco(_dot_)com> | 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/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail