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

Reading and writing Mozilla-mail in python

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Tue, 09 Dec 2003 14:27:42 +0100, Uwe Grauer wrote:
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: dm**@dman13.dyndns.org
Jul 18 '05 #2

P: n/a
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: <3F************@web.de>
Sender: so*****@somewhere.de

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

Jul 18 '05 #3

P: n/a

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
Uwe Grauer wrote:
Whats going on here.

Could someone please verify this?

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

Thanks,
Uwe


Jul 18 '05 #4

P: n/a
Uwe Grauer <ne**@grauer-online.de> writes:
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")) ?

Has anyone seen this before?

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

Uwe
Uwe Grauer wrote:
Whats going on here.
Could someone please verify this?
I'm using python 2.3.2 on Win2000 SP4 + all patches
Thanks,
Uwe


--
brainbot technologies ag
boppstrasse 64 . 55118 mainz . germany
fon +49 6131 211639-1 . fax +49 6131 211639-2
http://brainbot.com/ mailto:ra**@brainbot.com
Jul 18 '05 #5

P: n/a
Uwe Grauer <ne**@grauer-online.de> wrote:
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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #6

P: n/a
Tim Roberts wrote:
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>


Jul 18 '05 #7

P: n/a
Ralf Schmitt wrote:
Uwe Grauer <ne**@grauer-online.de> writes:

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")) ?

Indeed, you are right.

Thanks
Uwe

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.