Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Best way to parse email recipient lists?
Shanti Braford
11/9/2006 3:52:00 PM
Hey all,
So... I'm trying to parse email recipient lists (entered by hand into
the "to", "cc" and "bcc" fields of a mail app by users).
These can obviously come in a wild variety of formats, and I'd like to
support as many as possible.
The other gotcha - is that I'd like to keep as much name metadata
available as possible.
Using TMail's parser - I was under the impression that the name portion
in the "to", "cc", "bcc" fields gets stripped, down to an array of email
addresses. (i.e. otherwise we could use just TMail - please let me know
if this is incorrect or if there's a work around)
Here are a few example scenarios (from relatively easy to a little
harder):
raw.uncooked@sushi.co.jp
mr.techie+nospam@gmail.com
<raw@hotmail.com>
"Bob Smith" <bob@smith.org>
Bob Smith <bob@smith.org>
"Jones, Craig" <craig.jones@corp.com>
"Summer Thomas" <sum49@aol.com>; "Al Franken" <al@dnc.org>
"Clinton, Bill" <bill@whitehouse.gov>; "Obama, Barack"
<barack@senate.gov>; "Jenny McCarthy" <jenny@spike.com>
Bob <bob@accounting.com>, <jessica@email.com>, James Blunt
<james@blunt.org>
etc...
Any ideas?
I've been working up RegEx's like crazy but my RegEx foo isn't quite
what it used to be. Are there any shortcuts, or do I need one big RegEx
many specific ones to match the various scenarios?
We're currently using this RegEx to detect when we have a single
properly formatted address (w/o a name attached):
http://tfletcher.com/lib...
...but that's only one small portion of the problem.
- Shanti
--
Posted via
http://www.ruby-...
.
2 Answers
Michael Fleet
11/9/2006 10:55:00 PM
0
Shanti,
Try:
/(\W?([\w\s]+)\W+)?(\w[\w\+\-\.]+@[\w\-\.]+)\W?/i
(with "+" signs in mailbox (like user+nospam@domain.com), which are
invalid)
/(\W?([\w\s]+)\W+)?(\w[\w\\-\.]+@[\w\-\.]+)\W?/i
(without "+" signs)
These should break the addresses down into arrays of matches that you
can parse into:
display name
mailbox
domain
Let me know if this doesn't pass the tests. Better yet, send me a unit
test and i'll make it work. :)
also:
http://www.zenspider.com/Languages/Ruby/QuickR...
Michael Fleet
Disinnovate
http://www.disinn...
--
Posted via
http://www.ruby-...
.
Ara.T.Howard
11/9/2006 11:56:00 PM
0
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Best way to parse email recipient lists?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password