Trying to understand rfc822.Message() behaviour

P

Phoe6

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.
Subject: testing - fortune
Mood: happy


"Why should we subsidize intellectual curiosity?"
- Ronald Reagan

Subject: testing - fortune
Mood: happy

What is happening here. Why is the message not coming up?
 
F

Fredrik Lundh

Phoe6 said:
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.

Subject: testing - fortune
Mood: happy


"Why should we subsidize intellectual curiosity?"
- Ronald Reagan


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>
 
N

Neil Cerutti

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.

Subject: testing - fortune
Mood: happy


"Why should we subsidize intellectual curiosity?"
- Ronald Reagan


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.
 
D

Dennis Lee Bieber

What is happening here. Why is the message not coming up?

A quick test seems to indicate that Message only parses the headers.
One is still responsible for reading the body using the open file...
message.headers ['Subject: testing - fortune\n', 'Mood: happy\n']
print f.readline()
"Why should we subsidize intellectual curiosity?"
- Ronald Reagan
"Why should we subsidize intellectual curiosity?"
- Ronald Reagan
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top