d0d307
#!/usr/bin/perl
d0d307
#
d0d307
# Usage:	folderxfer inputfile
d0d307
#
d0d307
# Purpose:	Converts contents of Berkeley-format mail folders
d0d307
#		to Cyrus mailboxes
d0d307
#
d0d307
# Input:	Output of 'bsd2cyrus' 
d0d307
#		(username:Cyrus-folder-name:Berkeley-folder-path)
d0d307
#
d0d307
# Warnings:	The root mailbox and empty Cyrus folder must 
d0d307
#		exist before conversion takes place, and source folders 
d0d307
#		should be checked for RFC 822 content before being processed
d0d307
#
d0d307
#$Id: folderxfer,v 1.1 2004/02/04 12:59:42 karsten Exp $
d0d307
d0d307
$pwd       = "/usr/lib/cyrus-imapd";      
d0d307
$mailstore = "/var/spool/imap";        # Cyrus mailstore
d0d307
$cat       = "/bin/cat";
d0d307
$cmd       = "/usr/bin/formail -n 20 -s $pwd/cpmsg";
d0d307
d0d307
$folders = "$ARGV[0]";
d0d307
if (!$folders) { die "Usage: $0 filename"; }
d0d307
d0d307
open (MB,"$folders") || die "can't open $folders";
d0d307
d0d307
while (<mb>) {
d0d307
d0d307
    chop;
d0d307
d0d307
    # Be careful with this split - the last token might have
d0d307
    # whitespace we want to preserve
d0d307
d0d307
    ($user,$cyrusfolder,$folder) = split(/:/,$_,3);
d0d307
    @fields = split(/\./,$cyrusfolder);
d0d307
    $cyrfol = $fields[$#fields];
d0d307
d0d307
    $fcat = "$cat \"$folder\"";
d0d307
    print $fcat;
d0d307
    $prefix = substr($user,0,1);
d0d307
    system ("$fcat | $cmd '$mailstore/$prefix/user/$user/$cyrfol'");
d0d307
    #print "'$mailstore/$prefix/user/$user/$cyrfol";
d0d307
}
d0d307
close MB;
d0d307
d0d307