1 package FS::part_export::cyrus;
3 use vars qw(@ISA %info);
7 @ISA = qw(FS::part_export);
9 tie my %options, 'Tie::IxHash',
10 'server' => { label=>'IMAP server' },
11 'username' => { label=>'Admin username' },
12 'password' => { label=>'Admin password' },
17 'desc' => 'Real-time export to Cyrus IMAP server',
18 'options' => \%options,
22 <a href="http://asg.web.cmu.edu/cyrus/imapd/">Cyrus IMAP Server</a>.
23 Cyrus::IMAP::Admin should be installed locally and the connection to the
24 server secured. <B>svc_acct.quota</B>, if available, is used to set the
29 sub rebless { shift; }
32 my($self, $svc_acct) = (shift, shift);
33 $self->cyrus_queue( $svc_acct->svcnum, 'insert',
34 $svc_acct->username, $svc_acct->quota );
38 my( $self, $new, $old ) = (shift, shift, shift);
39 return "can't change username using Cyrus"
40 if $old->username ne $new->username;
42 # #return '' unless $old->_password ne $new->_password;
43 # $self->cyrus_queue( $new->svcnum,
44 # 'replace', $new->username, $new->_password );
48 my( $self, $svc_acct ) = (shift, shift);
49 $self->cyrus_queue( $svc_acct->svcnum, 'delete',
50 $svc_acct->username );
53 #a good idea to queue anything that could fail or take any time
55 my( $self, $svcnum, $method ) = (shift, shift, shift);
56 my $queue = new FS::queue {
58 'job' => "FS::part_export::cyrus::cyrus_$method",
61 $self->option('server'),
62 $self->option('username'),
63 $self->option('password'),
68 sub cyrus_insert { #subroutine, not method
69 my $client = cyrus_connect(shift, shift, shift);
70 my( $username, $quota ) = @_;
71 my $rc = $client->create("user.$username");
72 my $error = $client->error;
73 die "creating user.$username: $error" if $error;
75 $rc = $client->setacl("user.$username", $username => 'all' );
76 $error = $client->error;
77 die "setacl user.$username: $error" if $error;
80 $rc = $client->setquota("user.$username", 'STORAGE' => $quota );
81 $error = $client->error;
82 die "setquota user.$username: $error" if $error;
87 sub cyrus_delete { #subroutine, not method
88 my ( $server, $admin_username, $password_username, $username ) = @_;
89 my $client = cyrus_connect($server, $admin_username, $password_username);
91 my $rc = $client->setacl("user.$username", $admin_username => 'all' );
92 my $error = $client->error;
95 $rc = $client->delete("user.$username");
96 $error = $client->error;
102 my( $server, $admin_username, $admin_password ) = @_;
104 eval "use Cyrus::IMAP::Admin;";
106 my $client = Cyrus::IMAP::Admin->new($server);
107 $client->authenticate(
108 -user => $admin_username,
109 -mechanism => "login",
110 -password => $admin_password,
116 #sub cyrus_replace { #subroutine, not method