472,330 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

Reading and writing Mozilla-mail in python

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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Google Mike | last post by:
Tell me if this can be done, and if I have a misconception here. I am writing an app that will be served up in an app farm, and therefore I need...
12
by: Christoph Bergmann | last post by:
Hi... We want to write an open source web based TEXT editor and would be happy about any help ;-) Please notice: We do NOT want to write a...
4
by: Mateo | last post by:
Hi! I have labels on my page (some are web forms controls, and some are plain HTML labels), and I need Mozilla compatibile way for reading...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server...
2
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it...
3
by: Phil Endecott | last post by:
Dear All, I'm trying to read the content of the clipboard in a cross-browser way. Google will find various scripts such as this one: ...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make...
15
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i;...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.