Rob Tanner wrote:
> You might try the package IMAP::Admin, available from CPAN. It's a
> generic package tailored for Cyrus (though not from CMU). It's not
> interactive like cyradm, but rather a standard package like any other.
> I use it in utilities that create and delete accounts and set ACLs and
> quotas.
>
Here's a snippet that shows how to create a user and set up some folders:
----
#!/usr/bin/perl -w
use strict;
use IMAP::Admin
my $UserName=shift();
# Create IMAP folder
my $Imap = IMAP::Admin->new(
Server=>'localhost', Login=>'admin', Password=>'password');
my $Err = $Imap->create("user.$UserName");
$Err = $Imap->create("user.$UserName.Trash");
$Err = $Imap->create("user.$UserName.Drafts");
$Err = $Imap->create("user.$UserName.Sent Items");
if ($Err != 0) {
warn "$Imap->{'Error'}\n";
$Imap->close();
die;
} else {
# We give 'admin' the right to delete this user
$Err = $Imap->set_acl("user.$UserName", 'admin', 'c');
$Err = $Imap->set_acl("user.$UserName.Trash", 'admin', 'c');
$Err = $Imap->set_acl("user.$UserName.Drafts", 'admin', 'c');
$Err = $Imap->set_acl("user.$UserName.Sent Items", 'admin', 'c');
}
if ($Err != 0) {
warn "$Imap->{'Error'}\n";
$Imap->close();
die;
}
$Imap->close();
----