Cannot get email package to work

J

Jeff Blaine

Python 2.3.4 for Windows

Just trying a simple test today. I clicked on an email message in Mozilla
1.7.3's mail reader. I selected 'Save As' and saved it as the default type.
I opened the file with Wordpad to examine it, and sure enough it looks like
a complete email message with headers, newline, and body.
From nobody Fri Sep 17 17:26:06 2004

[]

?
 
S

Steve Holden

Jeff said:
Python 2.3.4 for Windows

Just trying a simple test today. I clicked on an email message in Mozilla
1.7.3's mail reader. I selected 'Save As' and saved it as the default
type.
I opened the file with Wordpad to examine it, and sure enough it looks like
a complete email message with headers, newline, and body.
From nobody Fri Sep 17 17:26:06 2004

[]

?
Very strange. I stored your message in the way you described and I see
the following (under Cygwin):

sholden@DELLBOY ~
$ python
Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
>>> myfd = open("/tmp/test.eml")
>>> msg = email.message_from_file(myfd)
>>> msg
>>> msg.get_all("From")
['Jeff Blaine said:
>>> msg.keys()
['Path', 'From', 'User-Agent', 'X-Accept-Language', 'MIME-Version',
'Newsgroups'
, 'Subject', 'Content-Type', 'Content-Transfer-Encoding', 'Lines',
'Message-ID',
'NNTP-Posting-Host', 'X-Complaints-To', 'X-Trace',
'NNTP-Posting-Date', 'Organi
zation', 'Date', 'Xref', 'X-Received-Date']
Under Windows Python 2.3.3 (#51, Dec 18 2003, 20:22:39), however, I see
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: Message instance has no attribute '__neg__'

which I am somewhat unable to explain.

so-now-you-have-two-problems-ly y'rs - steve
 
H

Heiko Wundram

Am Sonntag, 19. September 2004 00:12 schrieb Steve Holden:
Under Windows Python 2.3.3 (#51, Dec 18 2003, 20:22:39), however, I see


Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: Message instance has no attribute '__neg__'

---> Typo, should be msg = email.message_from_file(fd)

So, I guess it does work under windows. ;)

Heiko.
 
J

Jeff Blaine

I figured it out after trying again (and it worked). I believe I had
done the following in my interpreter:
>>> import email
>>> myfd = open('c:/temp/my-work.eml')
>>> email.message_from_file(myfd)
>>> msg = email.message_from_file(myfd) <-- now this is broken
>>> msg.keys() []
>>> msg.get_all('From')
>>>

It works though if you do it right the first time. Thanks for the prodding.
['Return-Path', 'Delivered-To', 'Received', 'Received', 'Received',
'Message-ID', 'Date', 'From', 'User-Agent', 'X-Accept-Language',
'MIME-Version', 'To', 'Subject', 'Content-Type', 'Content-Transfer-Encoding']
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top