Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I'm unable to save a UnixMailbox correctly

15 views
Skip to first unread message

Grzegorz Adam Hankiewicz

unread,
Jan 29, 2002, 6:39:00 PM1/29/02
to
Hi. I am trying to write a script which opens a unix mailbox file
through the mailbox module. Then, retrieves all the messages with
.next() and goes through each one and it's headers checking some
things. Finally, I want to open another file and write the results as
another unix mailbox. The code I am using to save each message is:
for f in mail.headers: file.write(f) mail.rewindbody() for f in
mail.fp.readlines(): file.write(f) ...being mail an rfc822 object
returned by mailbox' next method. The problem is that the written
file lacks the initial "From: ", which I am unable to get from the
rfc822 object. Basically, why doesn't rfc822 have some
dump_raw_lines() method which returns a list of lines (those exactly
read in first place) to recreate the message? And how could I get
over the file parameter of mailbox.UnixMailbox to feed it lines from
standard input instead of a physical file? PD: Please cc your answers
to gra...@terra.es. -- Grzegorz Adam Hankiewicz

Chris Liechti

unread,
Jan 29, 2002, 7:01:30 PM1/29/02
to
gra...@terra.es (Grzegorz Adam Hankiewicz) wrote in
news:f4c749a5.02012...@posting.google.com:
>...

> The code I am using to save each message is:
> for f in mail.headers: file.write(f) mail.rewindbody() for f in
> mail.fp.readlines(): file.write(f) ...being mail an rfc822 object
> returned by mailbox' next method.

> The problem is that the written
> file lacks the initial "From: ", which I am unable to get from the
> rfc822 object.

then try to use "mail.unixfrom" if its empty (shouldn't be in you
case) just fake one...
chris

>...


--
Chris <clie...@gmx.net>

Grzegorz Adam Hankiewicz

unread,
Jan 30, 2002, 2:18:29 PM1/30/02
to
Unluckily mail.unixfrom returns None -- Grzegorz Adam Hankiewicz

Steve Holden

unread,
Jan 30, 2002, 2:59:12 PM1/30/02
to
"Grzegorz Adam Hankiewicz" <gra...@terra.es> wrote ...

> Unluckily mail.unixfrom returns None -- Grzegorz Adam Hankiewicz

So, like Chris told you, just add a fake "From " line, which is what
Netscape does. Before you write out the rfc822 message just write a line
like

From - Thu Jan 22 22:03:29 1998

(this is an actual example from a Netscape mail folder, perfectly acceptable
to UnixMailbox)

regards
Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/

0 new messages