2000-03-01-22:09:44 Doug Wellington:
> Bennett provided a lot of good code to move files around, but I wonder
> if it wouldn't just be easier to use nmh's "packf" command to batch
> convert each of your MH style directories into single mbox style files
> and then deal with them that way...
If packf converts the MH into mbox, then you could use an
mbox2maildir script to finish the job. I attach the one I use.
Or you could probably hackup something cool around procmail's
formail program, which does really brainy splitting of mbox folders,
knows about Content-Length and all that creepy stuff.
-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