Невеликий додаток до комплекту: конвертер mailbox -> maildir
#! /usr/bin/perl
#####################################################################################################
# Mailbox to maildir converting script
# Based on Russell Nelson`s convert-and-create script
# Message-ID is used for mailfile name
#####################################################################################################
while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) =
getpwent()) {
if ($uid >= "1000") {
if (!-e $dir) {
print "warning: ${name}'s home dir, $dir, doesn't exist (passwd: $passwd), skipping.\n";
next;
}
$st_uid = (stat($dir))[4];;
if ($uid != $st_uid) {
print "warning: $name is $uid, but $dir is owned by $st_uid, skipping.\n";
next;
}
print "$name\n";
$spoolname = "$dir/.maildir";
-d $spoolname || mkdir $spoolname,0700 || print "fatal: mailbox doesn't exist and can't be created.\n";
chown ($uid,$gid,$spoolname);
chdir($spoolname) || print ("fatal: unable to chdir to $spoolname.\n");
-d "tmp" || mkdir("tmp",0700) || print "fatal: unable to make tmp/ subdir\n";
-d "new" || mkdir("new",0700) || print "fatal: unable to make new/ subdir\n";
-d "cur" || mkdir("cur",0700) || print "fatal: unable to make cur/ subdir\n";
chown ($uid,$gid,"tmp","new","cur");
open(SPOOL, "</var/spool/mail/$name") || next;
$i = time;
while(<SPOOL>) {
if (/^From /) {
$fn = sprintf("new/%d.tmp", $i);
open(OUT, ">$fn") || die("fatal: unable to create new message");;
chown ($uid,$gid,$fn);
$i++;
next;
}
s/^>From /From /;
print OUT || die("fatal: unable to write to new message");
}
close(SPOOL);
close(OUT);
}
chdir ($spoolname."/new/");
while (<*.tmp>) {
@files = <*.tmp>;
print "@files[0]";
open (MSG, "<@files[0]");
while(<MSG>) {
if (/^Message-Id:.\W(\d+\..*\@[\w+\.]*\w+)\W/){
$msgid = $1;
print "$msgid";
}
}
close(MSG);
rename $spoolname."/new/".@files[0], $spoolname."/new/".$msgid;
}
}
endpwent();
Код не дуже правильний, але працює без зайвих проблем.