Reading and writing Mozilla-mail in python

U

Uwe Grauer

Hi all,

who can help on reading and writing mozilla-mail folders with python?
I wanted to implement something like an email-sync for mozilla-mail in
python. I did some tests, but something is strange with the email
(rfc822) modules in python. (The output of parsed messages is different
from the original input)

Any hints of how (what modules) this could be done in a portable manner?

Thanks,
Uwe
 
D

Derrick 'dman' Hudson

Hi all,

who can help on reading and writing mozilla-mail folders with python?

What format are they? mbox?
I wanted to implement something like an email-sync for mozilla-mail in
python.

Some tools to do this already exist. Check on packages.debian.org. I
think one of them is called 'offlineimap' and is implemented in
python.
I did some tests, but something is strange with the email (rfc822)
modules in python. (The output of parsed messages is different from
the original input)

Use the 'email' module for handling individual email messages (not
rfc822). Note that both of those modules only process one message at
a time, not an entire mailbox.

-D

--
In the way of righteousness there is life;
along that path is immortality.
Proverbs 12:28

www: http://dman13.dyndns.org/~dman/ jabber: (e-mail address removed)
 
U

Uwe Grauer

After playing around with the mailbox an email modules i noticed some
strange behaviours:

after the first message is parsed, i got some (kind of parsing errors).

My code:

def test_copy(infile, outfile):
from mailbox import UnixMailbox
from email import message_from_file as mff
try:
fd = open(infile, 'r')
try:
for message in UnixMailbox(fd, mff):
print message
print '***********************************************'
finally:
fd.close()
except:
pass
return

output from script above:

.....
In-Reply-To: <[email protected]>
Sender: (e-mail address removed)

Nein, leider noch nicht, komm auch erst in paar Tagen dazu.


Fro
***********************************************
From - Sun Dec 07 02:59:04 2003
X-UIDL: 6165
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
.....

Look at the Line: Fro

Whats going on here.

Could someone please verify this?

I'm using python 2.3.2 on Win2000 SP4 + all patches

Thanks,
Uwe
 
U

Uwe Grauer

Now i tried it under Linux (Suse 8.2) + self compiled python 2.3.2.
It works!!
So, what the hell is going on with my stupid win2000?

Has anyone seen this before?

It think i'm going to reinstall the whole Shit.

Uwe
 
R

Ralf Schmitt

Uwe Grauer said:
Now i tried it under Linux (Suse 8.2) + self compiled python 2.3.2.
It works!!
So, what the hell is going on with my stupid win2000?

maybe opening the file in binary mode helps (i.e. open(infile, "rb")) ?
 
T

Tim Roberts

Uwe Grauer said:
After playing around with the mailbox an email modules i noticed some
strange behaviours:

after the first message is parsed, i got some (kind of parsing errors).

My code:

def test_copy(infile, outfile):
from mailbox import UnixMailbox
from email import message_from_file as mff
try:
fd = open(infile, 'r')

Ralf is correct. The UnixMailbox method uses tell and seek to remember
file locations and return to them later. Tell and seek on Windows are only
valid with binary files; the \r\n to \n translation screws it up.

Change that to
fd = open(infile, 'rb')
and all will be well.
 
F

Fredrik Lundh

Tim said:
Ralf is correct. The UnixMailbox method uses tell and seek to remember
file locations and return to them later. Tell and seek on Windows are only
valid with binary files; the \r\n to \n translation screws it up.

seek/tell works just fine on text files, as long as you only seek to
positions returned by tell (or to the beginning of the file). This is
standard ANSI C behaviour, btw.

(from a quick glance at the mailbox code, I cannot find any case
where the mailbox doesn't use seek/tell in this way, but I might be
missing something...)

</F>
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,222
Latest member
patricajohnson51

Latest Threads

Top