[Edit][Create New]
[ IndexPage / インストール / qmail / スプール一括変換 ]

スプール一括変換

スプールを一括で変換させる

↓のようなものを作って、一括で置換させた。 root権で走らせると、1人ずつ置換していいかどうか聞いてくれる。 mboxや、Maildir、mbox2maildirの場所は最初のほうの3行をいじればよい。

    #!/usr/bin/perl

    use strict;

    my $mbox_loc     = "/var/mail/%%USER%%"; # sendmail mail-file

    my $maildir_loc  = "/usr/home/%%USER%%/Maildir";   #

    my $script_loc   = "mbox2maildir";

    my @ent;

    while(@ent = getpwent){

        my $name = $ent[0];

        my $uid  = $ent[2];

        my $grp  = $ent[3];

        #print join(":", $name, $uid, $grp);

        #print "\n";

        # メールファイルとMaildirを取得

        my $mloc = $mbox_loc;

        my $dloc = $maildir_loc;

        $mloc =~ s/%%USER%%/$name/g;

        $dloc =~ s/%%USER%%/$name/g;

        # メールファイルとMaildirのどちらかがなければ蹴る

        next unless -s $mloc;

        next unless -d $dloc;

        # 質問する

        my $comm =  "$script_loc $mloc $dloc $uid $grp";

        $| = 1;

        print "$comm OK? (y/n): ";

        my $ans = <STDIN>;

        $| = 0;

        # 実行

        $! = '';

        system($comm) if $ans =~ /^y/i;

        die $! if $!;

    }