cyrus-imapd/bsd2cyrus
John Dennis 38f2261a6f auto-import cyrus-imapd-2.2.12-1.2.fc4 on branch devel from
cyrus-imapd-2.2.12-1.2.fc4.src.rpm
2005-04-15 20:24:15 +00:00

82 lines
1.9 KiB
Perl

#!/usr/bin/perl
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
#
# Usage: bsd2cyrus inputfile
#
# Purpose: Maps a user's Berkeley-format mail folder names into the
# Cyrus namespace
#
# Input: List of usernames, one per line
#
# Output: Lines of the format
# username:Cyrus-mailbox-name:BSD-mailbox-name
#
#$Id: bsd2cyrus,v 1.1 2004/02/04 12:59:42 karsten Exp $
require "find.pl";
# User's subdirectory where personal mail folders are stored
# (typically $HOME/mail)
$maildir = "mail";
$inputfile = "$ARGV[0]";
if (! $inputfile) { die "Usage: $0 inputfile\n"; }
open (DATA, $inputfile) || die "can't open $inputfile";
while (<DATA>) {
chop;
($user,$pw,$uid,$gid,$quota,$cmnt,$gcos,$home) = getpwnam $_;
next if $home eq "";
&find("$home/$maildir");
}
close DATA;
foreach (@folders) {
($user,$folder) = split(/:/,$_,2);
if (! rfc822($folder) ) { next; }
@tokens = split(/\//, $folder);
$mailbox = $tokens[$#tokens];
# Sanity checks - earlier tests should have caught these.
next if ($mailbox =~ /\.gz$/); # Skip gzipped files
next if ($mailbox =~ /\.Z$/); # Skip compressed files
next if ($mailbox =~ /^\./); # Skip hidden files
# Replace "bad" characters with an underscore followed by
# the ASCII representation of the "bad" character.
$mailbox = rm_badchars($mailbox);
print "$user:user.$user.$mailbox:$folder\n";
}
sub wanted {
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _;
if ($_ ne '.') { push @folders, "$user:$dir/$_"; }
}
sub rfc822 {
my ($file) = @_;
my ($rc) = 1;
if (-d $file || -z $file || -B $file || -x $file) {
$rc = 0;
}
return $rc;
}
sub rm_badchars {
my ($mailbox) = @_;
$mailbox =~ s/ /_040/g;
$mailbox =~ s/\!/_041/g;
$mailbox =~ s/\"/_042/g;
$mailbox =~ s/\#/_043/g;
return $mailbox;
}