add user script?

Jason Englander jason at englanders.cc
Fri Oct 4 14:16:49 EDT 2002


On Fri, 4 Oct 2002, Tarjei Huse wrote:

> does anyone have a simple {add|delete}-user script that adds/deletes a user
> to/from cyrus-imapd? I need something to start with. Just a script that adds a
> user mailbox and maybe other default mailboxes.

You could easily simplify/complicate it more, but here's one that
creates, one that deletes, and a little config file for both.  They're in
Perl (used with 5.6.1 and 5.8.0), they use the IMAP::Admin module.

To create other default mailboxes, add lines like this to the create
script:

my $subfolder = "Trash";
$err = $imap->create("${mailbox}.${subfolder}");
die "Unable to create ${mailbox}.${subfolder}\n\t$imap->{'Error'}\n" if $err;

One of these days I'll combine all of my little cyrus scripts into one
that uses getopt and subroutines...

-- 
Jason Englander <jason at englanders.cc>
394F 7E02 C105 7268 777A  3F5A 0AC0 C618 0675 80CA

-------------- next part --------------
#!/usr/bin/perl -w

use IMAP::Admin;
use strict;
use vars qw( $server $admin $password );

require './cyrus.cfg';

die "\nusage: $0 mailbox [mailbox ...]\n\n" if @ARGV < 1 ||
  ! defined($server) || ! defined($admin) || ! defined($password);

my $imap = IMAP::Admin->new(
  'Server' => $server,
  'Login' => $admin,
  'Password' => $password
);

foreach my $basemailbox (@ARGV) {
  my @list = $imap->list("$basemailbox.*");
  @list = sort {$b cmp $a} @list;
  push(@list,$basemailbox);
  foreach my $mailbox (@list) {
    print "Mailbox: $mailbox\n";
    print "  ACLs: ";
    my $err = $imap->set_acl($mailbox, 'cyrus', "lrswipdca");
    if ($err == 0) {
      print "OK\n";
      print "  Delete: ";
      $err = $imap->delete($mailbox);
      if ($err == 0) { print "OK\n"; }
      else { print "Error!\nError occurred destroying $mailbox\n  $imap->{'Error'}\n"; }
    }
    else { print "Error!\nError occurred setting acls for $mailbox\n  $imap->{'Error'}\n"; }
  }
}
-------------- next part --------------
#!/usr/bin/perl -w

use IMAP::Admin;
use strict;
use vars qw( $server $admin $password $default_quota );

require './cyrus.cfg';

die "\nUsage: $0 [mailbox ...]\n\n" if @ARGV < 1 || ! defined($server) ||
  ! defined($admin) || ! defined($password) || ! defined($default_quota);

my $imap = IMAP::Admin->new(
  'Server' => $server,
  'Login' => $admin,
  'Password' => $password
);

foreach my $mailbox (@ARGV) {
  my ($err);

  $err = $imap->create($mailbox);
  die "Error occurred building $mailbox\n\t$imap->{'Error'}\n" if $err;

  $err = $imap->set_quota($mailbox, $default_quota);
  die "Error occurred setting quota for $mailbox\n\t$imap->{'Error'}\n" if $err;

  $err = $imap->set_acl($mailbox, $admin, 'lrswipcda');
  die "Error occurred setting acls for $mailbox\n\t$imap->{'Error'}\n" if $err;

  $err = $imap->set_acl($mailbox, $admin, 'lrswipcda');
  print "Error occurred setting ACL for user $admin for $mailbox\n\t$imap->{'Error'}\n" if $err;

  # This is for fud
  $err = $imap->set_acl($mailbox, "anyone", "0");
  print "Error occurred setting fud ACL $mailbox\n\t$imap->{'Error'}\n" if $err;
}
-------------- next part --------------
$server = "localhost";
$admin = "cyrus";
$password = "password";
$default_quota = 100000;


More information about the Info-cyrus mailing list