1999-11-27-02:57:18 Nathan Cullen:
> Okay, I'm sold. :)   But first, is there a simple way to convert my
> current mbox folders(files) into maildir format?  Is this handled by
> mutt or another utility?

It can be done in mutt; once you've set mbox_type="Maildir" you can visit an
mbox, tag everything (T~A) and then save all tagged messages to another folder
(;sfoldername) and if foldername doesn't already exist, mutt will create it in
its new default format, Maildir.

That's certainly the easiest approach for a single mbox.

If you have a pile of them, then an external mbox2maildir script may be
appreciated. They are so simple everybody ends up writing their own; the one I
use is attached. It does simple mbox format, i.e. trusting ^From when it sees
it and not attempting to honor Content-Length.

-Bennett
#!/usr/bin/perl -w
use strict;
use File::Basename;
use Sys::Hostname;
use IO::File;

$0 = basename $0;
my($syntax) = "syntax: $0 mbox maildir\n";
die $syntax if $#ARGV != 1;
my($mbox, $maildir) = @ARGV;

die "$0: $mbox is not a file\n" unless -f $mbox;
die "$0: can't read $mbox\n" unless -r $mbox;
die "$0: can't open $mbox\n" unless my($fi) = IO::File->new("<$mbox");

-d $maildir or mkdir $maildir,0777 or die "$0: can't create $maildir: $!\n";
die "$0: cannot chdir $maildir\n" unless chdir $maildir;

for (qw(tmp new cur)) {
        -d $_ or mkdir $_,0700 or die "$0: can't create $maildir/$_: $!\n";
}

my($time) = time;
my($pid) = 10;
my($hostname) = hostname;
my($msg,$fo);
line: while ($_ = $fi->getline) {
        if (/^From /) {
                if (defined $msg and defined $fo) {
                        $fo->close or die;
                        if (-s  "tmp/$msg") {
                                rename "tmp/$msg", "new/$msg" or die;
                        } else {
                                unlink "tmp/$msg" or die;
                        }
                }
                $msg = join '.', $time, $pid++, $hostname;
                die if -f "tmp/$msg";
                $fo = IO::File->new(">tmp/$msg") or
                        die "$0: can't open $maildir/tmp/$msg: $!\n";
                next line;
        }
        $fo->print($_);
}
if (defined $msg and defined $fo) {
        $fo->close or die;
        if (-s  "tmp/$msg") {
                rename "tmp/$msg", "new/$msg" or die;
        } else {
                unlink "tmp/$msg" or die;
        }
}

PGP signature

Reply via email to