IMAP Email Question

Donn Cave donn at u.washington.edu
Fri Jul 5 13:13:13 EDT 2002


Quoth "Emile van Sebille" <emile at fenx.com>:
| Charel Yueng
| > I  cannot process any string data because it's a tuple. I can't seem
| > to be able to parse any data.
| >
| > What should be my approach to this problem?
| > what I need to extract is separated by the '=' sign ie.
| > charles,yueng,someaddress
| >
|
| >>> s =
| 'fname=charles\r\nfname=yueng\r\naddress=someaddress\r\n\r\n\r\n'
| >>> [x.split("=") for x in s.split()]
| [['fname', 'charles'], ['fname', 'yueng'], ['address', 'someaddress']]

I suspect you're taking his example too literally.  If the message
always looked just like that, then he could save himself the trouble
and just assume the result.

Actual email messages tend to have a body after the header, so if you
want to focus your analysis on the header, then you need to start by 
separating it from the body - header, body = text.split('\r\n\r\n', 1)

Values in an ordinary header may contain white space, so it would
make some sense to start by splitting them on line boundaries.
His example, with the fname= format, doesn't strike me as an RFC822
email message, but if that's just an error in the problem statement,
the rfc822 module might help do all this.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list