Which IMAP-folders exist?

The following script will make a list of which folders exist in an IMAP account. The script requires you pass hostname, accountname and password on the commandline, but it should be quite easy to change as you like.

#!/usr/bin/perl -w
use strict;

use Mail::IMAPClient::BodyStructure;
use Mail::IMAPClient;

my ($serv, $usr, $pwd) = (@ARGV); # server, username and password as comandline parameters...

my $imap = Mail::IMAPClient->new(Server=>$serv,User=>$usr,Password=>$pwd);
my @folders = $imap->folders;

foreach my $f (@folders) {
  print 	"$f is a folder with ", $imap->message\_count($f), " messages.n";