Creating Mailboxes via Script
Joe Dennick
joe at dennick.net
Sat Mar 8 15:07:56 EST 2003
I downloaded that Perl Module and the script worked perfectly! I even
added lines to create the trash, drafts, and sent-mail folders and set
the Acl so cyrus (administrator) had full control.
Thank you for your assistance!
Joe
-----Original Message-----
From: Patrick Boutilier [mailto:boutilpj at ednet.ns.ca]
Sent: Friday, March 07, 2003 12:07 PM
To: joe at dennick.net
Subject: Re: Creating Mailboxes via Script
Joe,
You are right. I remember having problems as well when I tried to
upgrade NetxAP a few years back. This module is the one that should
work.
http://search.cpan.org/CPAN/authors/id/K/KJ/KJOHNSON/NetxAP-0.01.tar.gz
There are better IMAP perl modules out there (Mail::IMAPClient for
example) but I have never updated my script to use them. :-(
Joe Dennick wrote:
> Yes, I changed all of the values to reflect my system, and I tested it
> with a few Print statements. The MySQL piece works flawlessly. I can
> successfully telnet to port 143 on localhost and I have used that to
> set up users in the past. That's what has me baffled. Everything
> should work, but it doesn't. I believe the Perl modules have changed
> in the last 12 months or so.
>
> Than you for your assistance on this!
>
> Joe
>
> -----Original Message-----
> From: Patrick Boutilier [mailto:boutilpj at ednet.ns.ca]
> Sent: Friday, March 07, 2003 9:13 AM
> To: joe at dennick.net
> Subject: Re: Creating Mailboxes via Script
>
>
> Joe,
>
> Did you change these values to what they sould be for your site? If so
> can you telnet to port 143 of the mail server and login that way?
>
> ( . login cyrususer cyruspass)
>
>
> my $cyrususer = "user";
> my $cyruspass = "pass";
> my $mysqluser = "user";
> my $mysqlpass = "pass";
> my $mysqlhost = "host";
> my $mysqldatabase = "database";
> my $mysqluserfield = "field";
> my $mysqlusertable = "table";
> my $IMAPSERVER = "localhost";
>
>
> Joe Dennick wrote:
>
>>OK, I've been playing with this script and variations of it for a
>>while now, and I still can't get it to successfully login to the IMAP
>
> server. It always produces the following error: Can't call method
> "login" on an undefined value at ./bulk line 32.
>
>>I had to go to cpan.org to download the Net::IMAP module and get it
>>installed, but it still didn't make this error go away. I'm no Perl
>>guru, but it looks to me like the connect on line 31 didn't
>>successfully complete causing line 32 to really get mad on the login
>>request.
>>
>>Any assistance would be greately appreciated!
>>
>>Thank you!
>>
>>Joe Dennick
>>joe at dennick.net
>>
>>
>>
>>Patrick Boutilier <boutilpj at ednet.ns.ca> wrote the Mar 5, 2003 7:19
>>AM:
>>
>>
>>
>>>Joe Dennick wrote:
>>>
>>>
>>>>We've got Cyrus-Imap 2.1.12 running very well for our company Red
>>>>Hat
>
>
>>>>8.0. We are authenticating against a MySQL database that we use as
>>>>a
>
>
>>>>master Security Container for all of our application authentication
>>>>and entitlements. We've already populated the database with all of
>>>>the user information required including usernames, passwords, shadow
>>>>passwords, email addresses, etc. Now we need to create Cyrus-Imap
>>>>mailboxes for each user (close to 3,000 mailboxes). I've seen
>>>>several articles that talk about scripting CYRADM to read a text
file
>
>
>>>>containing usernames, but I can't get any of the scripting examples
>>>>to work. It appears as though Cyrus-Imap, or specifically CYRADM
has
>
>
>>>>changed since the examples were created. Is there a way to script
>>>>or
>
>
>>>>batch create users? All I really need to do is create the mailbox
>>>>and set the ACL so cyrus (admin
>>>>account) has admin control over the mailbox. I can manually create
>
> the
>
>>>>mailboxes with the following commands:
>>>>
>>>> cyradm --user cyrus localhost
>>>> IMAP Password: *******
>>>> localhost.localdomain> createmailbox user.12345
>>>> localhost.localdomain> setacl user.12345 cyrus all
>>>> localhost.localdomain> quit
>>>>
>>>>Thank you in advance for your assistance.
>>>>
>>>>Joe Dennick
>>>>joe at dennick.net
>>>>
>>>
>>>
>>>We use a variant of the following script to add new users but in your
>>>case you should be able to use this as all your MySQL accounts need a
>>>Cyrus user created.
>>>
>>>
>>>
>>>#!/usr/bin/perl -w
>>>#
>>>
>>>use File::Basename;
>>>use Net::IMAP;
>>>use DBI;
>>>
>>>my $cyrususer = "user";
>>>my $cyruspass = "pass";
>>>my $mysqluser = "user";
>>>my $mysqlpass = "pass";
>>>my $mysqlhost = "host";
>>>my $mysqldatabase = "database";
>>>my $mysqluserfield = "field";
>>>my $mysqlusertable = "table";
>>>my $IMAPSERVER = "localhost";
>>>
>>>$dbh =
>>>DBI->connect("DBI:mysql:$mysqldatabase:$mysqlhost","$mysqluser","$mys
>>>DBI->q
>>>lpass") || die "SEM: MySQL database connected failed:
>>>$DBI::errstr\n";
>>>
>>>my $select = "SELECT $mysqluserfield FROM $mysqlusertable";
>>> my $sth = $dbh->prepare($select)
>>> || die "Can't prepare select statement: $DBI::errstr";
>>> my $rc = $sth->execute
>>> || die "Can't execute statement: $DBI::errstr";
>>> if ($sth->rows == 0) {
>>> exit 1;
>>> }
>>>
>>> # Login to IMAP server
>>> $imap = new Net::IMAP($IMAPSERVER, Synchronous => 1) || die "no
>
> go $! !";
>
>>> $response = $imap->login($cyrususer, $cyruspass);
>>> print "Login: ", $response->status, "-", $response->status_text,
>
>
>>>"\n";
>>>
>>> while ($userid = $sth->fetchrow) {
>>> print "user.$userid\n";
>>>
>>> # Create the new mailbox
>>> $response = $imap->create(user.$userid);
>>> print "Create: ", $response->status, "-",
>
> $response->status_text, "\n";
>
>>> }
>>>
>>> # Disconnect from IMAP server
>>> $response = $imap->logout();
>>> print "Logout: ", $response->status, "-",
>
> $response->status_text,
>
>>>"\n";
>>>
>>>$dbh->disconnect();
>>
>>
>
>
More information about the Info-cyrus
mailing list