Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URGENT: Email Regex Help

Posted on 2014-02-05
6
Medium Priority
?
404 Views
Last Modified: 2014-02-06
I am trying to put together a regex to search for specific emails in the To: section of an email header.  I have several email addresses, any one of which can be in the To: section of the header.  There may be one or several of the specific addresses and there must be a match if there are one or more of the addresses.

I have this as a start.

^To:\s+(usera|userb|userc|userd|usere|userf)@mydomain\.com

The email header may contain the following examples in any combination depending on the senders requirements, however I only need to trigger on the first match of the specific addresses.  Based on the regex finding the match, I will trigger other processes.  There also may be other extraneous email addresses which I expect will be ignored based on the criteria.

To: usera@mydomain.com
To: usera@mydomain.com, userb@mydomain.com
To: usera@mydomain.com, userb@mydomain.com, userc@mydomain.com
To: userb@mydomain.com, usere@mydomain.com

I have hit a wall as I am no expert at Regex.

Any help would be appreciated.
0
Comment
Question by:Craig Sharp
  • 4
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
lorenda earned 2000 total points
ID: 39835775
What language/system are you writing this code in? How many email addresses are you searching for? If it's not a TON, it might be faster to simply write a Select statement to catch your emails.

For each msg in object.msg

'code to parse your userID's here, depending on your delimiters
'Also might add another loop here if there are multiple emails in a to field

Select Case userID

Case usera, userb, etc

End Case

next msg
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835816
Thank you for the reply.

This is being used in Postfix running on Linux.  It is designed to be a single Regex statement such as the example.  Postfix uses the regex to scan the email header and then act on that header match such as forwarding an email that has one or more of the addresses in question to a different email server.

I am searching for the first match of any of the specified users email addresses.  This will trigger the forward.
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835822
Sorry, I will be searching for about 8 specific email addresses.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:lorenda
ID: 39835889
Ah - okay - what I posted above would really only work "well" client side ad hoc. Hopefully you'll find a postfix expert. :)
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835913
Thanks for your response Lorenda :-)
0
 
LVL 3

Author Closing Comment

by:Craig Sharp
ID: 39839196
I have found my solution:

^To:.*(usera@mydomain\.com|userb@mydomain\.com|userc@mydomain\.com)+

Lorenda, you were my only response.  Awarding you the points!

Thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question