Why parse it yourself (and risk getting it wrong), when the work has already been done?
The Mime4j library (http://james.apache.org/mime4j/) includes (among many other things related to processing email) an AddressBuilder
class that has methods for parsing email addresses (including groups and individual mailboxes, as well as address lists as they may appear in an email header) out into objects that represent them (instances of the Address
class and its subclasses, Group
and Mailbox
). The returned objects have methods that provide access to the individual components of each address (local part, domain, human-readable name, etc.).
The Javadoc for the AddressBuilder
class can be found here: http://james.apache.org/mime4j/apidocs/org/apache/james/mime4j/field/address/AddressBuilder.html .