Creating Calendar folder via IMAP directly?

vovan at planet.nl vovan at planet.nl
Tue Feb 7 16:10:20 CET 2006


Here's an example:
#!/usr/bin/perl -w

use Cyrus::IMAP::Admin;

# CONFIGURATION

my $cyrus_server = "localhost";
my $cyrus_user = "manager";
my $domain = '@net.home';

# Default 100 Megs
my $quota_size = "100000";
my $mechanism = "login";
my $cyrus_pass;

#
# EOC
#

if (!$ARGV[0]) {
        die "Usage: $0 [user to add] [quota in Kb]\n";
}
else {
        $newuser = "$ARGV[0]";
        if ( defined $ARGV[1] ) { $quota_size = $ARGV[1] }
}

system "stty -echo";    # turn off screen echo to hide passwords
print "Password: ";     # show a prompt
chomp($cyrus_pass = <STDIN>);  # remove newline from input and store in 
$cyrus_pass
print "\n";             # newline after password prompt
system "stty echo";     # restore screen echo

sub createMailbox {

        my ($user, $subfolder) = @_;

        my $cyrus = Cyrus::IMAP::Admin->new($cyrus_server);
        
$cyrus->authenticate($mechanism,'imap','',$cyrus_user,'0','10000',$cyrus_pass);

        if ($subfolder eq "INBOX") {
                $mailbox = "user/$user$domain";
        } else {
                $mailbox = "user/$user/$subfolder$domain";
        }

        $cyrus->create($mailbox);
        if ($cyrus->error) {
                print STDERR "Error: ", $mailbox," ", $cyrus->error, "\n";
        } else {
                print "Created Mailbox: $mailbox \n";
        }

}

sub setQuota {

        my ($user) = @_;

        my $cyrus = Cyrus::IMAP::Admin->new($cyrus_server);
        
$cyrus->authenticate($mechanism,'imap','',$cyrus_user,'0','10000',$cyrus_pass);

        $mailbox = "user/$user$domain";
        $cyrus->setquota($mailbox,"STORAGE",$quota_size);
        if ($cyrus->error) {
                print STDERR "Error: ", $mailbox," ", $cyrus->error, "\n";
        } else {
                print "Setting Quota: $mailbox at $quota_size \n";
        }

}

sub setInfo {

        my ($user, $subfolder, $entry, $value) = @_;

        my $cyrus = Cyrus::IMAP::Admin->new($cyrus_server);
        
$cyrus->authenticate($mechanism,'imap','',$cyrus_user,'0','10000',$cyrus_pass);

        if ($subfolder eq "INBOX") {
                $mailbox = "user/$user$domain";
        } else {
                $mailbox = "user/$user/$subfolder$domain";
        }
        $cyrus->mboxconfig($mailbox, $entry, $value);
        if ($cyrus->error) {
                print STDERR "Error: ", $mailbox," ", $cyrus->error, "\n";
        } else {
                print "Set $mailbox $entry -> $value \n";
        }

}


print "Adding User: ", $newuser, "\n";

createMailbox($newuser,'INBOX');
setInfo($newuser, 'INBOX', '/vendor/kolab/folder-type', 'mail');
setInfo($newuser, 'INBOX', '/vendor/kolab/folder-test', 'true');
createMailbox($newuser,'Sent');
setInfo($newuser, 'Sent', '/vendor/kolab/folder-type', 'mail');
createMailbox($newuser,'Trash');
setInfo($newuser, 'Trash', '/vendor/kolab/folder-type', 'mail');
createMailbox($newuser,'Drafts');
setInfo($newuser, 'Drafts', '/vendor/kolab/folder-type', 'mail');

setQuota($newuser);

createMailbox($newuser,'Calendar');
setInfo($newuser, 'Calendar', '/vendor/kolab/folder-type', 'event.default');
setInfo($newuser, 'Calendar', '/vendor/kolab/h-share-uid', "$newuser$domain");

createMailbox($newuser,'Contacts');
setInfo($newuser, 'Contacts', '/vendor/kolab/folder-type', 'contact.default');
setInfo($newuser, 'Contacts', '/vendor/kolab/h-share-uid', "$newuser$domain");

createMailbox($newuser,'Notes');
setInfo($newuser, 'Notes', '/vendor/kolab/folder-type', 'note.default');
setInfo($newuser, 'Notes', '/vendor/kolab/h-share-uid', "$newuser$domain");

createMailbox($newuser,'Tasks');
setInfo($newuser, 'Tasks', '/vendor/kolab/folder-type', 'task.default');
setInfo($newuser, 'Tasks', '/vendor/kolab/h-share-uid', "$newuser$domain");

createMailbox($newuser,'Journal');
setInfo($newuser, 'Journal', '/vendor/kolab/folder-type', 'journal.default');
setInfo($newuser, 'Journal', '/vendor/kolab/h-share-uid', "$newuser$domain");



Quoting "T. Ribbrock" <admin_slox-e at itsef.com>:

> On Fri, Feb 03, 2006 at 07:24:00AM +0100, VoVaN wrote:
>> I've the script already in a separated file using Cyrus::IMAP::Admin, so if
>> somebody likes...
>
> As per ypur request once more, this time to the list:
>
> You mean you've got a script that will create the Calendar folder on a
> Kolab server with the correct annotation? If so, I'd be interested!
>
> Cheerio,
>
> Thomas
>
> _______________________________________________
> Kolab-users mailing list
> Kolab-users at kolab.org
> https://kolab.org/mailman/listinfo/kolab-users
>
>
>








More information about the users mailing list