Hi,--On 16. November 2005 10:39:37 -0300 Bartosz Jozwiak <[EMAIL PROTECTED]> wrote:
I am running Cyrus IMAP for sometime right now. We have around 2000 users. I will like to upgrade quota for each user. Does anybody has a script which could do it fast?
I use the attached script. Cheers, Sebastian Hagedorn -- Sebastian Hagedorn - RZKR-R1 (Gebäude 52), Zimmer 18 Zentrum für angewandte Informatik - Universitätsweiter Service RRZK Universität zu Köln / Cologne University - Tel. +49-221-478-5587 Skype: shagedorn
#!/usr/bin/perl # # HG, 2005-04-13 # Set the quota for all users in specified file # File format: username quota # # Usage: massquota.pl filename use strict; use warnings; my $adminuser = "cyrus"; my $server = "cyrus.rrz.uni-koeln.de" ; use Cyrus::IMAP::Admin; #use Getopt::Long; my $user = ""; my $quota = -1; my $result; #my $result = GetOptions('user=s' => \$user, 'quota=i' => \$quota); die "Usage: $0 filename" if @ARGV!=1; open IN, $ARGV[0] or die "Can't open file '$ARGV[0]': $!"; my $imapcon = Cyrus::IMAP::Admin->new($server) || die "Unable to connect to $server"; unless ($imapcon) { die "Error creating IMAP connection object\n" ; } $result = $imapcon->authenticate(-user => $adminuser, -mechanism => "DIGEST-MD5") ; # print "Authenticate-Result: $result\n"; die "Authentication failed" unless $result; if ($imapcon->error) { die $imapcon->error ; } while (<IN>) { chomp; next if /^$/; next if /^#/; ($user, $quota) = split; unless (defined $user and defined $quota) { print STDERR "Illegal file format: $_\n"; next; } if ($quota < 0 or $quota > 2000000) { print STDERR "$user can't get quota $quota. Quota has to be >= 0 and <= 2000000\n"; next; } my @boxes = $imapcon->listmailbox("user/$user"); if ($imapcon->error) { print STDERR "Error: $user, ", $imapcon->error,"\n"; next; } if (@boxes == 0) { print STDERR "Mailbox does not exist: user/$user\n"; next; } my %current_quota=$imapcon->listquota("user/$user"); if ($imapcon->error) { print STDERR "Warning: $user apparently has no quota root yet - it will be created\n"; } $result = $imapcon->setquota("user/$user", "STORAGE", $quota); if ($imapcon->error) { print STDERR "Error: $user, ", $imapcon->error,"\n"; next; } %current_quota=$imapcon->listquota("user/$user"); if ($imapcon->error) { print STDERR "Error: $user, ", $imapcon->error,"\n"; next; } print "Quota for user/$user has been set to $current_quota{'STORAGE'}[1]\n"; } $imapcon->send('', '', 'LOGOUT');
---- Cyrus Home Page: http://asg.web.cmu.edu/cyrus Cyrus Wiki/FAQ: http://cyruswiki.andrew.cmu.edu List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html