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