parsing long `To' and 'Cc' from email

Gerardo Herzig gherzig at
Thu Sep 6 23:53:56 CEST 2007

Steve Holden wrote:

>Gerardo Herzig wrote:
>>Hi all. Im trying to develop yet another email filter. Just for fun for 
>>now. Im having a little trouble parsing long 'To' and 'Cc' headers. 
>>Sometimes p.e. the 'To' header comes like
>>'account1 at, account at'
>>others comes like
>>'"My self" <my.account at>, "My brother" <brother.account at>',
>>other times a \r\t comes inside the `To' header. And any combination of 
>>the above mentioned (and shurely more) can ocur.
>>the email.* package dont seems to parse that kind of headers 
>>`correctly'. What i want is to get a list with all the email address in 
>>the `To' header.
>>Someone know if there is a more sofisticated parser for doing this?
>Have you tried using email.utils.getaddresses()?
>  Steve
No, i was not. And it works just perfect! One day i will make a hard 
question!! I wonder why this getaddresess() function is not a method 
into the HeaderParser class.

Ok, so my content-filter can continue now. Thanks Steve!

More information about the Python-list mailing list