Hi monks.

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?


In reply to Searching using Mail::IMAPClient on exchange by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.