#!/usr/bin/perl -w
#
# Create's a new user in Cyrus by creating their INBOX
#

if ($#ARGV < 0) {
	print "Usage: $0 username\n";
	print "  Create's a new user in Cyrus by creating their INBOX\n";
	exit(-1);
}

use IMAP::Admin;

require "/private/admin/acct/email/prefs.pl";
require "/private/admin/acct/email/utils.pl";

my $imap = IMAP::Admin->new('Server' => $prefs{'cyrushost'},
			'Login' => $prefs{'cyrususer'},
			'Password' => $prefs{'cyruspass'},
			);

if (! $imap) {
	print "Error connecting to IMAP server.\n";
	exit;
}

my $username = $ARGV[0];
my $mailbox = "user.$username";

my $rv = &createmailbox($imap, $mailbox);

if ($rv ne "success") {
	print "$rv\n";
}
else {
	print "Successfully created inbox for $username\n";
}

$rv = &setmailquota($imap, $mailbox, $prefs{'mailquota'});
if ($rv ne "success") {
	print "$rv\n";
}
else {
	print "Successfully set quota for $username to $prefs{'mailquota'}\n";
}


$imap->close;

