Thomas von Hassel wrote:

>
> Ok, any good ideas how to migrate many IMAP accounts from one server to
> another (from Imail to courier)
>
> the account part is easy enought, but how do i get theire mail folders
> transferd in an easy way ?
>
> i have been looking into fetchmail but i dont think this alone will do
> the job ?

Hi Thomas,

I did the very same (Imail -> Courier) and used mb2md.pl
(http://batleth.sapienti-sat.org/projects/mb2md/) for converting the
mailboxes and a home grown script to traverse the user dirs, change some
 unwanted folder names and so on. This second script was a quick hack so
it isn't documented at all :( It assumes that you already have all
accounts on the courier box, that the new home dirs of the users are in
/home and that the Imail-mboxes are mounted at /mnt/smb.
I recommend that you mount the Imail-share read-only and do tests runs
with the scripts.

You might have to tweak it a bit to your needs...

Cheers,
Juri

-- 
  If each of us have one object, and we exchange them,
     then each of us still has one object.
  If each of us have one idea,   and we exchange them,
     then each of us now has two ideas.
#!/usr/bin/perl -W
#
#
use File::Find;
use File::Path;
use File::Copy;
use Cwd;

$warnings = 0;

$tmpdir = "/home/tmp";
$workingdir = cwd();

find (\&getusers, "/mnt/smb");
sub getusers {
    my $user;
    if (-d $File::Find::name) {
        $user = $_;
        chomp $user;
        $user =~ s/(\S*).*/\L$1/;
        if (getpwnam($user)) {
            $users{$File::Find::name} = $user;
        }
    }
}

while (($userdir,$user) = each(%users)) {
    print "Doing $user:\n";
    my @usersubdirs;
    mkpath ("$tmpdir/$user");
    chdir ($userdir);
    open USERDIRS, "find '.' -type d -print|";
    while (<USERDIRS>) {
        $dir = $_;
        chomp ($dir);
        $dir =~ s/\.\///;
        if ($dir ne ".") {
            if ($dir =~ /\./) {
                print STDERR "WARN!!! $dir has a -dot- in the name!\n";
                $dir =~ s/\.//;
                print STDERR "will be $dir !\n";
                ++$warnings;
            }
            @usersubdirs = (@usersubdirs, $dir);
            print "creating $tmpdir/$user/$dir\n";
            mkpath ("$tmpdir/$user/$dir") || die "can't create dir: $!";
        }
    }
    close USERDIRS;
    open MBOXES, "find '.' -iname '*.mbx' -print|";
    chdir ("$tmpdir");
    while (<MBOXES>) {
        $mbox = "$_";
        chomp ($mbox);
        $mbox =~ s/^\.\///;
        $mbox_neu = "$mbox";
        $mbox_neu =~ s/\.mbx$//;
        if ("$mbox_neu" =~ /\./) {
            print STDERR "WARN!!! $mbox has a -dot- in the name!\n";
            $mbox_neu =~ s/\.//;
            print STDERR "will be $mbox_neu !\n";
            ++$warnings;
        }
        @args = ("dos2unix", "-n", "$userdir/$mbox", "$tmpdir/$user/$mbox_neu.mbx");
        system (@args);
    }
    close MBOXES;
    system("chown -R $user $tmpdir/$user");
    (-e "$tmpdir/$user/main.mbx") && system("su - $user -c \"cp $tmpdir/$user/main.mbx 
/var/spool/mail/$user; rm -f $tmpdir/$user/main.mbx\"");
    (-e "$tmpdir/$user/Main.mbx") && system("su - $user -c \"cp $tmpdir/$user/Main.mbx 
/var/spool/mail/$user; rm -f $tmpdir/$user/Main.mbx\"");
    system("rm -f $tmpdir/$user/main.mbx");
    chdir ($workingdir);
    system("su - $user -c \"mb2md -m\"");
    system("su - $user -c \"mb2md -s $tmpdir/$user -r mbx\"");
    for $dir (@usersubdirs) {
        print "---------------- $dir ----------------\n";
        system("su - $user -c \"mb2md -s $tmpdir/$user -f \'$dir\' -r mbx\"");
    }
    print "Warnings: $warnings\n";
    rmtree("$tmpdir/$user");
    system("su - $user -c \"cp /dev/null /var/spool/mail/$user\"");
}

Attachment: dotheforwards.sh
Description: Binary data

Reply via email to