##########################
# Create a mailbox
##########################
sub createmailbox {
	my ($imap, $mailbox) = @_;
	my ($err);

	if ($imap->list($mailbox)) {
		return "ERROR: mailbox $mailbox already exists";
	}

	$err = $imap->create($mailbox);

	if ($err != 0) {
		return "ERROR: " . $imap->{'Error'};
	}

	return "success";
}


##########################
# Set mailbox quota
##########################
sub setmailquota {
	my ($imap, $mailbox, $quota) = @_;
	my ($err);

	if (! $imap->list($mailbox)) {
		return "ERROR: mailbox $mailbox does not exist";
	}

	$err = $imap->set_quota($mailbox, $quota);

	if ($err != 0) {
		return "ERROR: " . $imap->{'Error'};
	}

	return "success";
}


##########################
# Delete a mailbox
##########################
sub deletemailbox {
	my ($imap, $mailbox) = @_;
	my ($err);

	if (! $imap->list($mailbox)) {
		return "ERROR: mailbox $mailbox does not exist";
	}

	# Give ourselves delete rights on the mailbox
	$err = $imap->set_acl($mailbox, "cyrus", "c");

	if ($err != 0) {
		return "ERROR: " . $imap->{'Error'};
	}

	$err = $imap->delete($mailbox);

	if ($err != 0) {
		return "ERROR: " . $imap->{'Error'};
	}

	return "success";
}


1;

