[Vmail-discuss] maildir conversion / courier

ilgiz kalmetev ilgiz kalmetev <ilgiz at bashtelecom.ru>
Tue, 26 Aug 2003 17:53:26 +0600


Hello, Donovan.

You wrote 26 =E0=E2=E3=F3=F1=F2=E0 2003 =E3., 5:21:39:

DC> I finally got courier working !

   Good! :)

DC> I now have to convert all the mailbox files to maildir. I have looked=
 at using the
DC> mb2md tool but it doesn't seem to like the format of the default mail=
box files we use.
DC> Does anyone happen to have a script to do this conversion ? Or any id=
eas on how this can be done ?

   May be this? :

./bsdspool2maildir.sh:
=3D=3D=3D cut =3D=3D=3D
#! /bin/sh

BSDSPOOL=3D/var/mail/...     # mbox directory
MAILDIRS=3D/var/mail/...     # Maildir directory

mkdir -p $MAILDIRS

ls -1 $BSDSPOOL | \
while read i
do
    echo $i
    mbox2mdir.p $BSDSPOOL/$i $MAILDIRS/$i
done

# And to fix the files and directories permissions:
chown ....
chmod ....
=3D=3D=3D cut =3D=3D=3D


./mbox2mdir.p
=3D=3D=3D cut =3D=3D=3D
#! /usr/bin/perl

my $mbox =3D shift;
my $dir =3D shift;
my $maildir =3D "Maildir";

#chdir($dir) or die "fatal: unable to chdir to $dir\n";
-d $dir or mkdir $dir,770 or die("fatal: $dir doesn't exist and can't be =
created.\n");
chdir($dir);
$spoolname =3D "$maildir";
-d $spoolname or mkdir $spoolname,0770
  or die("fatal: $spoolname doesn't exist and can't be created.\n");

chdir($spoolname) or die("fatal: unable to chdir to $spoolname.\n");
-d "tmp" or mkdir("tmp",0770) or die("fatal: unable to make tmp/ subdir\n=
");
-d "new" or mkdir("new",0770) or die("fatal: unable to make new/ subdir\n=
");
-d "cur" or mkdir("cur",0770) or die("fatal: unable to make cur/ subdir\n=
");

$fn  =3D "";
$oldfn =3D "";
open(SPOOL, "<$mbox")
  or die "Unable to open $mbox\n";
$i =3D time;
while(<SPOOL>) {
  if (/^From /) {
    $oldfn =3D $fn if( $fn );
    $fn =3D sprintf("new/%d.$$,S=3D", $i);
    open(OUT, ">$fn") or die("fatal: unable to create new message");
    rename $oldfn, $oldfn.(stat($oldfn))[7] if( $oldfn );
    $i++;
    next;
  }
  s/^>From /From /;
  print OUT or die("fatal: unable to write to new message");
}
close(SPOOL);
close(OUT);
rename $fn, $fn.(stat($fn))[7] if( $fn ); # create size-suffix for exim q=
uotas mechanizm
#unlink("$mbox");
=3D=3D=3D cut =3D=3D=3D

--=20
 ilgiz                          mailto:ilgiz@bashtelecom.ru