Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm having a problem reading mail from an exahcnge 5.5 server using Mail::ImapClient;
As far as I can see it should be pretty straightforward, I've read the perl module documentation and checked out RFC2060 which gives specifics about the IMAP SEARCH command but I can't seem to get this supposedly simple thing to work.
The following code should login to the mail box and do a search for any mails that have 'test' in the subject header.
#!perl use strict; use Mail::IMAPClient; my $server='xxx'; my $user='yyy'; my $password='zzz'; my $imap=new Mail::IMAPClient( Server=>$server, User=>$user, Password=>$password ) or die "Cannot connect to \"$server\" as \"$user\" : $!"; my @search=("SUBJECT","test"); $imap->search(@search) or warn "Search error\n"; my @results = $imap->Results; foreach(@results) {print "Result : \"$_\"\n";} print "Inbox count : ".$imap->message_count('inbox');
But instead of retrieving the mails in question it just returns.
Search error Result : "2 UID SEARCH SUBJECT test " Result : "2 BAD SEARCH command received in invalid state. " Inbox count : 6
Whatever search fields I put into the search array I get he same error but the $imap->message_count always seem to work fine which indicates that I am successfully able to login to the account and retrieve information, it's just the syntax of the search command that seems to be the issue.
Could any monks offer any advice?