#!/usr/bin/perl

use strict;
use Cyrus::IMAP::Admin;

$| = 1;

my $server = "127.0.0.1";
my $cyrus_admin_username = 'foo';
my $cyrus_admin_password = 'baa';

my $mbox = shift or die "usage: make_mailbox.pl <username> .";
$mbox = "user.$mbox";


# Authenticate
my $cyrus = Cyrus::IMAP::Admin->new($server);

print "Authentication start\n";

$cyrus->authenticate(
        -user => $cyrus_admin_username,
        -mechanism => 'login',
        -password => $cyrus_admin_password
);

die $cyrus->error if $cyrus->error;

# Create the account
print "Creating $mbox on \n";
$cyrus->createmailbox($mbox);
warn $cyrus->error if $cyrus->error;


# Finished :)