help with rfc822

Gerrit Holl gerrit.holl at pobox.com
Fri Jan 21 07:13:35 EST 2000


drmental at my-deja.com wrote on 948427830:
> Please help a newbie,
> 
> I'm trying to parse an email that is received with poplib, what i need
> out of it is the email address of the sender and the email body.
> 
> I've tried to store the email as a temp file and then use the
> rfc822.Message(tmpfile) and that does not return a Message instance.
> I've tried to use the StringIO and that give me an error.  Can someone
> give me a brief example of how get the email addres out of an email that
> is stored as a string?

I don't know about poplib, but suppose you have a string returned like:
'''From: foo <foo at somewhere.com>
To: bar <bar at somewher.com>
Subject: This is the subject.
X-Mailer: Mutt 1.0i

Hi,

This is a test.

regards,
Gerrit.
'''

Then, you can create a StringIO instance in it using:
sio = StringIO.StringIO(s)

where s is the string returned.
You can pass 'sio' to rfc822.Message now!

regards,
Gerrit.

-- 
Please correct any bad English you encounter in my email message!
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----




More information about the Python-list mailing list