#!/usr/bin/perl

$home = $ENV{HOME};

opendir(DIR,"$home/.cscmail");
@filelist = grep !/^\.\.?$/, readdir DIR;
closedir(DIR);
foreach $file (@filelist) {
 $newfile = $file;
 $newfile =~ s/^(\d+)(\d)(\d)\.(...)/\/$3\/$2\/$4\/$1$2$3\.$4/ and $dir1 = $3 and $dir2 = $2;
 $newfile =~ s/^(\d)(\d)\.(...)/\/$2\/$1\/$3\/$1$2\.$3/ and $dir1 = $2 and $dir2 = $1;
 $newfile =~ s/^(\d)\.(...)/\/$1\/0\/$2\/0$1\.$2/ and $dir1 = $1 and $dir2 = 0;
 mkdir("$home/.cscmail/$dir1", 0700);
 mkdir("$home/.cscmail/$dir1/$dir2", 0700);
 mkdir("$home/.cscmail/$dir1/$dir2/msg", 0700);
 mkdir("$home/.cscmail/$dir1/$dir2/hdr", 0700);
 rename("$home/.cscmail/$file", "$home/.cscmail/$newfile");
}
