#!/usr/bin/perl # a cute li'l script for converting .qmail files to .courier files # to help with qmail-to-courier migration # Written by Sheer Pullen (sheer@sheer.us) but not a sample of his best work ;-) # use FileHandle; do_rename("/home"); sub do_rename { my $dir = shift; my $fh = new FileHandle; # print "do_rename $dir\n"; opendir($fh, $dir); while($file = readdir($fh)) { # print "Considering $file\n"; if(-d "$dir/$file") { next if $file eq "."; next if $file eq ".."; next if $file eq "Maildir"; do_rename("$dir/$file"); } else { if($file eq ".qmail") { $cmd = "mv $dir/$file $dir/.courier"; system($cmd); } if(($head, $tail) = $file =~ /(\.qmail-)(.*)/) { if($tail) { $outputfile = "$dir/.courier-$tail"; $cmd = "mv $dir/$file $dir/.courier-$tail"; } else { $outputfile = "$dir/.courier"; $cmd = "mv $dir/$file $dir/.courier"; } print "renaming $head $tail [$cmd]\n"; if(! -f $outputfile) { print "I would run $cmd\n"; system($cmd); } else { print "I would NOT run $cmd because it would overwrite $outputfile\n"; } } } } closedir($fh); }