#!/usr/local/bin/perl -w # # convertMail # # This is a wrapper that converts a directory of mail files into a specified # format and recreates it in /var/imap//. # # Released under GPL. # # $Id: convertMail,v 1.2 1998/05/09 07:46:21 jauderho Exp jauderho $ # (C) Copyright 1998 Jauder Ho # # 050898 jauderho [initial cut at creating a decent tree] # 052998 jauderho [standardize on mbx format] # 062698 jauderho [ignore .gz and .Z files] # $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin"; my $count; my $imapRoot = "/var/imap"; my $imapHome = "$imapRoot/$ENV{'LOGNAME'}"; my $mbxFormat = "mbx"; # Change this to desired format my @tree; # Test for right no. of args. if ( $#ARGV < 0 ) { die "Usage: convertMail \n"; } # Test for directories. if ( ! -d "$imapHome" ) { die "ERROR: $imapHome does not exist.\n"; } if ( ! -d "$ENV{'HOME'}/$ARGV[0]" ) { die "ERROR: $ENV{'HOME'}/$ARGV[0] does not exist.\n"; } chdir("$ENV{'HOME'}/$ARGV[0]"); open(TREE,"find . -print |") or die "ERROR: Find can't find anything!\n"; for () { chomp(); push(@tree,$_) unless /\.summary/; } # Sorting the array causes the directories to float to the top of each # particular subtree. Very convenient as we do not need to run a for loop # twice to first pick out/make the directories and then to actually create # the files. for (sort @tree) { next if /^.$/; # Ignore ./ next if /\.gz$/;# Ignore gzipped files next if /\.Z$/; # Ignore compressed files s/^\.\///; # Throw away the leading ./ $count++; # Check if it is a directory if ( -d $_ ) { # Create if it durnt exist if ( ! -d "$imapHome/$_" ) { print "Creating $_ ...\n"; mkdir("$imapHome/$_",0700); } } # Convert if it is a file. If the file already exists, it warns. if ( -f $_ ) { print "Converting $_ ...\n"; if ( -f "$imapHome/$_" ) { warn "WARNING: File already exists, skipping...\n"; } else { `mbxcvt \"$ENV{'HOME'}/$ARGV[0]/$_\" $mbxFormat \"$imapHome/$_\" 2> /dev/null`; } } } # # Code fragment moved to createIMAPDir instead. # # Finally move inbox over. #if ( ! -f "$imapHome/INBOX" ) { # my $pre1 = ""; # my $pre2 = ""; # # print "Creating /var/imap/$ENV{'LOGNAME'}/INBOX ...\n\n"; # `mbxcvt /var/mail/null $mbxFormat \"$imapHome/INBOX\" 2> /dev/null`; # print wrap($pre1, $pre2, "An empty inbox at /var/imap/$ENV{'LOGNAME'}/INBOX has been created. The next time you read mail, all the mail in /var/mail/$ENV{'LOGNAME'} will be brought over safely into the new mailbox.\n"); #} #