In an email, it looks like a "from" or "to" field can contain one or more addresses, each address can be like "john@test.com"
or "John D Jr <john@test.com>"
So a "from" field can look like any of the following:
"a@a.com"
"a@a.com, Bob Blue <b@b.com>"
"Abe Allen <a@a.com>, b@b.com"
"Abe Allen <a@a.com>, Bob Blue <b@b.com>"
"Abe Allen <a@a.com>, Bob Blue <b@b.com>, c@c.com"
and so on.
I want to parse these fields, extracting each address' email if it's valid, and the name if it's present. Since I'm not familiar with the email standard, I may be missing some cases of what address fields can look like. Is there a Ruby library that can do this?
I don't know of a library, but if you are trying to get a list of the emails you could do the following yourself. (Long winded on purpose)
If you want to match their names and email addresses, you will need something else.
Also, this won't work if there are '<' or '>' in the email address, but that's pretty uncommon.
Yes, there's a gem for this; it's called mail.
Assuming your data follows the examples you gave, this should work: