[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] extracting info in perl from cyrus imap



On Mon, Aug 11, 2003 at 09:55:13PM +0100, Rob Keeling wrote:
> Are there any Perl / cyrus imap experts around on this list?
I claim the first, not the second.

> I have been trying to write a script to list all the mail boxes, check
> if there is a linux user for the box, and delete the un-used boxes.
> 
> However no matter what I try I just get ARRAY (ox82xxxxx) output instead
> of a text string.

This implies that you are trying to print something that not a string, but
is rathwer a reference to an array.

I would hazard a guess that $imapcon->list returns a reference to an array
rather than a list. When you assign this to  [at] mailboxes, you end up with
an array of one element, and that element happens to be an array ref.

If this is the case, then you'll want something like this instead:

    my $mailboxes = $imapcon->list('user.rob*');
    my $boxname;
    print "number of records ", scalar(@$mailboxes), "\n";
    foreach my $mbox (@$mailboxes) {
	print ".";   
	print "$mbox\n";
    }

Dave.

> #!/usr/bin/perl -w
> 
> my $adminuser = "cyrus" ;
> my $adminpass = "password" ;
> my $server = "localhost" ;
> my $quota = 10*1024 ; # 10MB
> my $user_uid_start = 500 ;
> my $err = 0 ;
> my $user = "";
> my $lcuser = "";
> use Cyrus::IMAP::Admin;
> 
> $imapcon = Cyrus::IMAP::Admin->new($server) || die "Unable to connect to $server";
> 
> unless ($imapcon) {
>     die "Error creating IMAP connection object\n" ;
> }
> 
> $imapcon->authenticate(-user => $adminuser, -password => $adminpass, -mechanism => "LOGIN") ;
> 
> if ($imapcon->error) {
>     die $imapcon->error ;
> }
> 
> print "start\n" ;
> 
> @mailboxes = $imapcon->list('user.rob*');
> my $boxname;
> my $mbox;
> print "max records $#mailboxes \n";
> foreach $mbox( [at] mailboxes) {
> print ".";   
> print "$mbox\n";
> }

-- 
In my day, we used to edit the inodes by hand.  With magnets.
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.