#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    141
    Rep Power
    12

    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.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Show us some examples of what you are trying to match.
  4. #3
  5. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    141
    Rep Power
    12
    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?
  8. #5
  9. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    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.

IMN logo majestic logo threadwatch logo seochat tools logo