July 28th, 2012, 10:28 PM
-
Detect From: email address
I am trying to match on a from email address in a forwarded email thread. The email can be forwarded multiple times with various types of formats of the From: email address. I only need to get the last one, but it has to be the "From:" email address.
I've tried three versions, which are close, but not quite right.
From: [^\\[]+\\[mailto:([^@]+@[^]]+)\\]
From: [^<]+<([^@]+@[^>]+)>
From: [^<]+<+mailto:+([^@]+@[^>]+)>
Thanks for any help.
Last edited by requinix; July 29th, 2012 at 02:40 AM.
July 29th, 2012, 03:33 PM
-
Show us some examples of what you are trying to match.
July 29th, 2012, 04:11 PM
-
Hi Dman100,
The email headers can vary wildly.
What would help most is if you would paste a sample email header, highlighting the line to be matched.
To see the full email with the headers, in Gmail, you select "show original" from the drop-down menu at the right of the message. In Horde, outlook, other programs, it might say "show full message", "show headers", etc.
Wishing you a fun week.
July 29th, 2012, 05:05 PM
-
Here are a few examples:
Code:
From: Cole, Amy [mailto:acole-rms@STERICYCLE.com]
Sent: Tuesday, July 10, 2012 1:59 PM
To: Sunovion O/E
Subject: Request for RGA
Please submit an RA for each of the attached Debit Memos.
Thank You
Amy Cole
RA Associate - Retail Returns
Stericycle
acole-rms@stericycle.com<mailto:acole-rms@stericycle.com>
2670 Executive Drive
Suite A
Indianapolis, IN 46241
p (317) 217-6731
f (317) 217-6761
[image001.jpg]
this should detect: acole-rms@STERICYCLE.com
Here is another:
Code:
From: Mathai, Julia
Sent: Thursday, June 07, 2012 9:57 AM
To: 'Ashley Orf'
Subject: RE: Debit Memo # 28057
please see the attached RAs
Julia Mathai
Order Management Specialist
Direct 508-357-7826 I Fax 508-787-4191 l Email julia.mathai@sunovion.com<mailto:julia.mathai@sunovion.com>
________________________________
From: Ashley Orf [mailto:returns@totalrxreturns.com]
Sent: Thursday, June 07, 2012 9:47 AM
To: Mathai, Julia
Subject: Debit Memo # 28057
Debit Memo #28057 product was destroyed in house on 2/13/12
This one should detect: returns@totalrxreturns.com
Looking to get the last From: email address in the forwarded thread.
Does that help?
July 29th, 2012, 06:04 PM
-
Yes, it helps! Thank you.
This regex will match your addresses.
Code:
(?i)mailto:\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b
(The (?i) is a case-insensitive flag, depending on what you are using, you may have a different flag.)
In your language, you find all the matches with this regex. Then you take the last one.
Are you on php?
If so, first you define
PHP Code:
$regex = '~(?i)mailto:\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b~';
(Note the tilde delimiters.)
Then you match everything:
PHP Code:
$found = preg_match_all($regex,$email,$matches,PREG_SET_ORDER);
Then you look at the number of matches:
PHP Code:
$size = count ($matches);
Then you display the last match:
PHP Code:
$last = $matches[$size-1][0];
If you put parentheses around the email address (between the two \b tags), then you can display it in the same way, by showing Group 1:
PHP Code:
$last = $matches[$size-1][1];
Okay, I only typed this in the window without testing. There might be a typo but it would probably be minor.
Pls let me know if this helps.