Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method for parsing text Cc field of email header?

I have the plain text of a Cc header field that looks like so:

[email protected], John Smith <[email protected]>,"Smith, Jane" <[email protected]>

Are there any battle tested modules for parsing this properly?

(bonus if it's in python! the email module just returns the raw text without any methods for splitting it, AFAIK) (also bonus if it splits name and address into to fields)

like image 959
smurthas Avatar asked Mar 24 '11 23:03

smurthas


1 Answers

There are a bunch of function available as a standard python module, but I think you're looking for email.utils.parseaddr() or email.utils.getaddresses()

>>> addresses = '[email protected], John Smith <[email protected]>,"Smith, Jane" <[email protected]>'
>>> email.utils.getaddresses([addresses])
[('', '[email protected]'), ('John Smith', '[email protected]'), ('Smith, Jane', '[email protected]')]
like image 171
Martin Tournoij Avatar answered Sep 23 '22 13:09

Martin Tournoij