converting Netscrape mailbox to Unix mbox format

Gey-Hong Gweon gweon at umich.edu
Thu Aug 12 11:14:46 EDT 1999


Ivan Van Laningham <ivanlan at callware.com> writes:

> Hi All--
> 
> Eugene Leitl wrote:
> > 
> > Michael Hudson writes:
> > 
> >  > Last I looked Netscape mailbox format *was* unix mbox format (on unix
> >  > anyway; can't speak for Netscape on windows) - have you tried pointing
> >  > pine at them?
> > 
> > Yes. Both pine and VM. Both see a giant 5 MByte message.
> > 
> >  > Otherwise you could try the mailbox standard library module...
> 
> I remember MHonArc doing OK on Netscape mailboxes, but there were a lot
> of missteps.  You might look into their code to see how they parse the
> mbox into individual messages. ...
> 
> Take care,
> Ivan
> ----------------------------------------------
> Ivan Van Laningham
> Callware Technologies, Inc.
> ivanlan at callware.com
> ivanlan at home.com
> http://www.pauahtun.org
> See also: 
> http://www.foretec.com/python/workshops/1998-11/proceedings.html
> Army Signal Corps:  Cu Chi, Class of '70
> ----------------------------------------------

I once "converted" Netscape mailbox files to VM files. The problem that
I had is different from the problem that is described here, so I think
something else is going on here. Anyway, my problem was that some of the
messages stored in Netscape didn't have an empty line, which VM needed
as a separator between messages, before they began. The effect was that
if I just used Netscape mailbox files in VM, VM would show fewer number
of messages because a few of the adjacent messages were recognized as a
single message. I fixed this by writing a simple shell script, which I
attach below. I suppose it could be useful to somebody else migrating
from Netscape to VM. The only thing that will be necessary to run the
script is to replace `name-temp-file` to some temporary file name. In my
case, name-temp-file is another shell script to generate a new temporary
file name.

--- Cut here for script file 'correct-netscape-mail-file' ---
#!/bin/tcsh -f

onintr cleanup

if ( $# != 1 ) then
    echo usage: $0:t \<mail-file-name\>
    exit 1
endif

set inputfile = "$1"
set tempfile = `name-temp-file`
awk 'BEGIN {prev_empty = 1; bad_lines = 0;} {if ($0 ~ /^From[^:]/) {if (! prev_empty) {bad_lines++; print "";}} print $0; if ($0 == "") prev_empty = 1; else prev_empty = 0;} END {if (! prev_empty) {bad_lines++; print "";} exit (bad_lines);}' "$inputfile" > $tempfile
set nerror = $status
if ( $nerror == 0 ) then
    echo Nothing to correct for mail file \`$inputfile\'.
else
    set backupfile = "$inputfile".backup
    set i = 1
    while ( -e "$backupfile" ) 
	set backupfile = "$backupfile".$i
	@ i = $i + 1
    end
    \mv "$inputfile" "$backupfile"
    echo Backup of the original: \`$backupfile\'
    \mv "$tempfile" "$inputfile"
    echo Number of corrections for \`$inputfile\': $nerror.
endif

cleanup:
    if ( $?tempfile ) then
	if ( -e $tempfile ) \rm $tempfile
    endif
--- Cut here for script file 'correct-netscape-mail-file' ---

-- 
Gey-Hong Gweon
The University of Michigan, Physics Department, Ann Arbor, MI 48109
(734) 647-9434 (Office), 763-3417 (Lab), 763-9694 (Fax) 




More information about the Python-list mailing list