Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > ee26cf15a147cef2d50a65db1795ee9f > files > 30

cyrus-imapd-2.1.18-2mdk.src.rpm

#!/usr/bin/perl -w
# 
# imapcreate: create IMAP mailboxes with quotas
#             Reads user names from standard input.

use Getopt::Long;
use Cyrus::IMAP::Admin;

sub usage {
  print "imapcreate - create IMAP mailboxes with quotas\n";
  print "  usage:\n";
  print "    imapcreate [-u user] [-p pass] [-q quota] [-t partition:list]\n";
  print "    <server>\n";
  print "\n";
  print "  example: \n";
  print "    imapcreate -u cyradm -q 50000 -t p1:p2 mail.testing.umanitoba.ca\n";
  print "\n";
  exit 0;
}

my $debug = 1; # XXX
my $user;
my $pass;
my $quota;
my @part;
GetOptions("u|user=s" => \$user, "p|pass=s" => \$pass, "q|quota=i" => \$quota,
   "t|part=s" => \@part);
@part = split(/:/, join(':', @part));
push @part, 'default' unless @part;
my $pn = 0;

$server = shift(@ARGV) if (@ARGV);

usage unless $server;

# Authenticate
my $cyrus = Cyrus::IMAP::Admin->new($server);
$cyrus->authenticate(-mechanism => 'login', -user => $user,
     -password => $pass);
die $cyrus->error if $cyrus->error;

# For all users
while (<>) {
    chomp;
    my $mbox = 'user.' . $_;

# Select the partition
    my $pt = $part[$pn];
    $pn += 1;
    $pn = 0 unless $pn < @part;

# Create the account
    print STDERR "Creating $mbox on $pt\n" if $debug;
    if ($pt eq 'default') {
$cyrus->createmailbox($mbox);
    }
    else {
$cyrus->createmailbox($mbox, $pt);
    }
    warn $cyrus->error if $cyrus->error;

# Set the quota
    if ($quota) {
print STDERR "Setting quota for $mbox to $quota\n" if $debug;
$cyrus->setquota($mbox, 'STORAGE', $quota);
warn $cyrus->error if $cyrus->error;
    }
}