By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

Trying to understand rfc822.Message() behaviour

P: n/a
Hi all,
Have a look at this snippet, I have a file direct.txt and I want to
read it as rfc8222.Message() so that I get the Subject: and Mood: as
Dict Keys and content separately, but I am unable to get the Content
Properly.
>>fhandle = open('direct.txt','r')
print fhandle.read()
Subject: testing - fortune
Mood: happy
"Why should we subsidize intellectual curiosity?"
- Ronald Reagan

>>fhandle.seek(0)
import rfc822
message = rfc822.Message(fhandle)
print message
Subject: testing - fortune
Mood: happy
>>>
What is happening here. Why is the message not coming up?

--
Senthil

Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2006-11-30, Phoe6 <or*******@gmail.comwrote:
Hi all,
Have a look at this snippet, I have a file direct.txt and I want to
read it as rfc8222.Message() so that I get the Subject: and Mood: as
Dict Keys and content separately, but I am unable to get the Content
Properly.
>>>fhandle = open('direct.txt','r')
print fhandle.read()
Subject: testing - fortune
Mood: happy
"Why should we subsidize intellectual curiosity?"
- Ronald Reagan

>>>fhandle.seek(0)
import rfc822
message = rfc822.Message(fhandle)
print message
Subject: testing - fortune
Mood: happy
>>>>

What is happening here. Why is the message not coming up?
From the Python Documentation 12.11.1 Message Objects:

class Message( file[, seekable])

A Message instance is instantiated with an input object as
parameter. Message relies only on the input object having a
readline() method; in particular, ordinary file objects
qualify. Instantiation reads headers from the input object up
to a delimiter line (normally a blank line) and stores them
in the instance. The message body, following the headers, is
not consumed.

--
Neil Cerutti
We dispense with accuracy --sign at New York drug store
Nov 30 '06 #2

P: n/a
Phoe6 wrote:
Have a look at this snippet, I have a file direct.txt and I want to
read it as rfc8222.Message() so that I get the Subject: and Mood: as
Dict Keys and content separately, but I am unable to get the Content
Properly.
>>>fhandle = open('direct.txt','r')
print fhandle.read()
Subject: testing - fortune
Mood: happy
"Why should we subsidize intellectual curiosity?"
- Ronald Reagan

>>>fhandle.seek(0)
import rfc822
message = rfc822.Message(fhandle)
print message
Subject: testing - fortune
Mood: happy
What is happening here. Why is the message not coming up?
because the rfc822.Message parser only reads the header; to read the
rest, just call "read" on the file object after you've parsed the header.

see

http://effbot.org/librarybook/rfc822.htm

for some sample code.

</F>

Nov 30 '06 #3

P: n/a
Fredrik Lundh wrote:
Phoe6 wrote:
Have a look at this snippet, I have a file direct.txt and I want to
read it as rfc8222.Message() so that I get the Subject: and Mood: as
Dict Keys and content separately, but I am unable to get the Content
Properly.

because the rfc822.Message parser only reads the header; to read the
rest, just call "read" on the file object after you've parsed the header.

see

http://effbot.org/librarybook/rfc822.htm

Thank you. That helped me best to understand the rfc822 module.

Thanks,
Senthil

Nov 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.