I have been trying to create a script in perl to perform certain admin 
tasks like adding users, setting quotas, etc. After some frustration I 
turned to the info-cyrus archives to find a working script to build 
from. So I found and copied the following code from the archive and I 
am having some trouble executing it. 

#!/usr/local/bin/perl -w
# 
# imapcreate: create IMAP mailboxes with quotas
#             Reads user names from standard input.

use Getopt::Long;
use Cyrus::IMAP::Admin;

sub usage {
  print "imapcreate - create IMAP mailboxes with quotas\n";
  print "  usage:\n";
  print "    imapcreate [-u user] [-p pass] [-q quota] [-t 
partition:list]\n";
  print "    \n";
  print "\n";
  print "  example: \n";
  print "    imapcreate -u cyradm -q 50000 -t p1:p2 
mail.testing.umanitoba.ca\n";
  print "\n";
  exit 0;
}

my $debug = 1;                  # XXX
my $user;
my $pass;
my $quota;
my @part;
GetOptions("u|user=s" => \$user, "p|pass=s" => \$pass, "q|quota=i" => 
\$quota,
           "t|part=s" => \@part);
@part = split(/:/, join(':', @part));
push @part, 'default' unless @part;
my $pn = 0;

$server = shift(@ARGV) if (@ARGV);

usage unless $server;

# Authenticate
my $cyrus = Cyrus::IMAP::Admin->new($server);
$cyrus->authenticate(-mechanism => 'login', -user => $user,
                     -password => $pass);
die $cyrus->error if $cyrus->error;

# For all users
while (<>) {
    chomp;
    my $mbox = 'user.' . $_;

# Select the partition
    my $pt = $part[$pn];
    $pn += 1;
    $pn = 0 unless $pn < @part;

# Create the account
    print STDERR "Creating $mbox on $pt\n" if $debug;
    if ($pt eq 'default') {
        $cyrus->createmailbox($mbox);
    }
    else {
        $cyrus->createmailbox($mbox, $pt);
    }
    warn $cyrus->error if $cyrus->error;

# Set the quota
    if ($quota) {
        print STDERR "Setting quota for $mbox to $quota\n" if $debug;
        $cyrus->setquota($mbox, 'STORAGE', $quota);
        warn $cyrus->error if $cyrus->error;
    }
}

-------------------------
After executing this code I receive the following errors:

Login failed: UserID Unknown at 
/usr/lib/perl5/site_perl/5.6.0/i386-linux/Cyrus/IMAP/Admin.pm line 78

Looking at line 78 and surrounding lines I get even more perplexed:


sub AUTOLOAD {
  use vars qw($AUTOLOAD);
  no strict 'refs';
  $AUTOLOAD =~ s/^.*:://;
  my $sub = $Cyrus::IMAP::{$AUTOLOAD};
  *$AUTOLOAD = sub { &$sub($_[0]->{cyrus}, @_[1..$#_]); }; <----Line 78
  goto &$AUTOLOAD;
}

Any help or suggestion would be appreciated.

Thank you,
--Mark


----------------------------------------
Mark A. Jarvis
Information Technology
System Administrator I
Phone:(606) 783-2269
Morehead State University

Reply via email to