how to split the contain of retr (using poplib module)
Piers Lauder
piers at cs.su.oz.au
Thu Nov 25 05:24:56 EST 1999
muniff at yahoo.com (Ahmad Munif) wrote:
>
> i'm using poplib module to connect to pop3 server.
> i can retrieve mail with retr mothode.
> but i don't know, how to split the contain of mail,
> so, i can get the value of mail, such as: To,From,body message.
> how to split it ?
The `retr' method returns three values: (comment, lines, octets)
You can ignore `comment' and `octets', the interesting one
is `lines', which is a list of message lines with trailing
<CR><NL> combinations stripped.
Here's an example of parsing `lines' into something useful:
import mimetools, string, StringIO
lines.append('') # last newline
data = string.join(lines, '\n')
mime = mimetools.Message(StringIO.StringIO(data), 1)
Read the mimetools documentation for how to get at the header
components in the `mime' instance.
More information about the Python-list
mailing list