Mailing List CGatePro@mail.stalker.com Message #100971
From: Nicolas Hatier <nicolas.hatier@niversoft.com>
Subject: Re: CLI ListMailboxes function
Date: Tue, 26 Oct 2010 22:41:45 -0400
To: CommuniGate Pro Discussions <CGatePro@mail.stalker.com>

Why do you use the filter parameter at all?

Normally, ListMailbox should return you an hash of hashes, the top-level keys being the folder full names (top/sub/mailbox), and the hash values being the mailbox metadata.

You need something simpler, something like this:


my $Boxes= $cli->ListMailboxes(accountName=>'john');
my $Total = 0;
foreach my $key (sort keys %$Boxes)
{
    my $data = $Boxes->{$key};
    if (ref $data eq 'HASH')
    {
        print "$key: " . $data->{"Size"} . "\n";
        $Total += $data->{"Size"};
    }
}
print "Account total: $Total\n";



Nicolas

On 2010-10-26 20:25, Matthew Black wrote:
I'm writing some code to produce a quota usage report that examines the size of every folder for a user. Look at this example code from the CLI guide:

--- http://www.communigate.com/CGPerl/#Mailbox ---
ListMailboxes(accountName => account,[ filter => '*',] [authAccountName => extAccount]);

    Example:

      my $Boxes= $cli->ListMailboxes(accountName=>'john',filter=>'INBOX*')
         || die "Error: ".$cli->getErrMessage.", quitting";

      foreach (sort keys %$Boxes) {
        print "$_\n";
        my $data=@$Boxes{$_};
        if(ref $data eq 'HASH') {
          foreach (keys %$data) {
            print "  $_ = @$data{$_}\n";
          }
        }
      }
------------------------------------------------------------

This code snippet partially fails (it skips top-level folders) if users have mailboxes within mailboxes. For example, a lot of our users place all their folders under their INBOX instead of the top level. This would prevent displaying information for INBOX, but not the mailboxes within.

In that foreach loop, I found that mailboxes which themselves contain other mailboxes (x.folder in Unix filesystem for maildir format), the ref $data type is an ARRAY containing a HASH structure.

QUESTION: Is this so programs can detect the folder hierarchy?

QUESTION: Does the ARRAY element always contains a single HASH structure?

If so, can the CGP gurus expand that example or add a note explaining the resulting $data structure?

I can provide my code to CGP or anyone upon direct request (unless I get too many, in which case I can post). Not the best code, but could be helpful to others.

Thanks.

--- sample output ---
# ./mq.pl johndoe
ACCOUNT = johndoe
QUOTA = 1,363,148,800 (1300M)   USAGE = 1,335,583,233
LAST ALERT  = #T26-10-2010_22:29:51
LAST NOTICE = #T26-10-2010_13:07:08
FORWARD TO  = johndoe@gmail.com   (Keep=Y  Automatic=N  Preserve=Y)

        Size  # Msg  Mailbox
       3,716      1  Calendar
       2,445      6  Contacts
           0      0  Drafts
#802,828,671  #7863  INBOX
 485,950,957   2006  INBOX/invitation
 #10,721,398    #66  Junk E-mail
           0      0  Notes
 #36,075,178   #571  Sent Items (not default)
         868      1  Tasks
          #0     #0  Trash
------------------------------------------------------------
NOTE: user actually named their sent folder with that funny name.

matthew black
e-mail postmaster
california state university, long beach

#############################################################
This message is sent to you because you are subscribed to
 the mailing list <CGatePro@mail.stalker.com>.
To unsubscribe, E-mail to: <CGatePro-off@mail.stalker.com>
To switch to the DIGEST mode, E-mail to <CGatePro-digest@mail.stalker.com>
To switch to the INDEX mode, E-mail to <CGatePro-index@mail.stalker.com>
Send administrative queries to  <CGatePro-request@mail.stalker.com>

--

Nicolas Hatier, ing. <nicolas.hatier@niversoft.com>
Niversoft idées logicielles - http://www.niversoft.com

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster