-sub cyrus_insert {
- my( $username, $quota ) = @_;
-
- warn "cyrus_insert: starting for user $username, quota $quota\n";
-
- warn "cyrus_insert: connecting to $cyrus_server\n";
- my $client = Cyrus::IMAP::Admin->new($cyrus_server);
-
- warn "cyrus_insert: authentication as $cyrus_admin_user\n";
- $client->authenticate(
- -user => $cyrus_admin_user,
- -mechanism => "login",
- -password => $cyrus_admin_pass
- );
-
- warn "cyrus_insert: creating user.$username\n";
- my $rc = $client->create("user.$username");
- my $error = $client->error;
- die "cyrus_insert: error creating user.$username: $error" if $error;
-
- warn "cyrus_insert: setacl user.$username, $username => all\n";
- $rc = $client->setacl("user.$username", $username => 'all' );
- $error = $client->error;
- die "cyrus_insert: error setacl user.$username: $error" if $error;
-
- if ( $quota ) {
- warn "cyrus_insert: setquota user.$username, STORAGE => $quota\n";
- $rc = $client->setquota("user.$username", 'STORAGE' => $quota );
- $error = $client->error;
- die "cyrus_insert: error setquota user.$username: $error" if $error;
- }
-
- 1;
-}
-
-sub cp_insert {
- my( $username, $password ) = @_;
-
- my $app = new Net::APP ( $cp_server,
- User => $cp_user,
- Password => $cp_pass,
- Domain => $mydomain,
- Timeout => 60,
- #Debug => 1,
- ) or die "$@\n";
-
- $app->create_mailbox(
- Mailbox => $username,
- Password => $password,
- Workgroup => $cp_workgroup,
- Domain => $mydomain,
- );
-
- die $app->message."\n" unless $app->ok;
-}
-
-sub vpopmail_insert {
- my( $username, $password, $domain, $vpopdir ) = @_;
-
- (open(VPASSWD, ">>$exportdir/domains/$domain/vpasswd")
- and flock(VPASSWD,LOCK_EX)
- ) or die "can't open vpasswd file for $username\@$domain: $exportdir/domains/$domain/vpasswd";
- print VPASSWD join(":",
- $username,
- $password,
- '1',
- '0',
- $username,
- "$vpopdir/domains/$domain/$username",
- 'NOQUOTA',
- ), "\n";
-
- flock(VPASSWD,LOCK_UN);
- close(VPASSWD);
-
- mkdir "$exportdir/domains/$domain/$username", 0700 or die "can't create Maildir";
- mkdir "$exportdir/domains/$domain/$username/Maildir", 0700 or die "can't create Maildir";
- mkdir "$exportdir/domains/$domain/$username/Maildir/cur", 0700 or die "can't create Maildir";
- mkdir "$exportdir/domains/$domain/$username/Maildir/new", 0700 or die "can't create Maildir";
- mkdir "$exportdir/domains/$domain/$username/Maildir/tmp", 0700 or die "can't create Maildir";
-
- my $queue = new FS::queue { 'job' => 'FS::svc_acct::vpopmail_sync' };
- my $error = $queue->insert;
- die $error if $error;
-
- 1;
-}
-
-sub vpopmail_sync {
-
- my (@vpopmailmachines) = $conf->config('vpopmailmachines');
- my ($machine, $dir, $uid, $gid) = split (/\s+/, $vpopmailmachines[0]);
-
- chdir $exportdir;
- my @args = ("$rsync", "-rlpt", "-e", "$ssh", "domains/", "vpopmail\@$machine:$vpopdir/domains/");
- system {$args[0]} @args;
-
-}
-