RichardH has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to build a simple imap mail reader, but for some reason, I cannot get the $imap->messages method to work. Any help would be greatly appreciated. And Happy New Year!
Here is the code (with username, password and host changed):
use strict; use Mail::IMAPClient; use Data::Dumper; use IO::File; my $imap = Mail::IMAPClient->new( Server => "some.secure.imap.server", User => "someuser", Password => "somepassword", debug => 1, ) or die "Cannot connect: $@"; my $folder = "Inbox"; $imap->exists($folder) or warn "$folder not found: $@\n"; my $msgcount = $imap->message_count($folder); defined($msgcount) or die "Could not message_count: $@\n"; print "msg count = ", $msgcount, "\n"; my @msgs = $imap->messages or die "Could not messages: $@\n"; my $i; foreach $i (@msgs) { print "\$i = $i\n"; } $imap->disconnect or warn "Could not disconnect: $@\n";
And here is the output
C:\>"C:\Documents and Settings\rsh\My Documents\myperl\imap\imaptest.p +l" Using Mail::IMAPClient version 2.2.9 and perl version 5.8.2 (5.008002) Mail::IMAPClient not using Fast_IO; not available on this platform at +C:\Documents and Settings\rsh\My Documents\myperl\imap\imaptest.pl li +ne 5 Read: * OK [CAPABILITY IMAP4REV1 LOGIN-REFERRALS STARTTLS AUTH=LOGIN] +somehost IMAP4rev1 2003.339 at Wed, 31 Dec 2003 23:25:17 -0600 (CST) Connect: Received this from readline: 0/OUTPUT/* OK [CAPABILITY IMAP4R +EV1 LOGIN-REFERRALS STARTTLS AUTH=LOGIN] somehost IMAP4rev1 2003.339 +at Wed, 31 Dec 2003 23:25:17 -0600 (CST) Sending literal string in two parts: 1 Login "someuser" {6} then: somepassword Sending: 1 Login "XXXXXX" {6} Sent 36 bytes Read: + Ready for argument Sending: somepassword Sent 8 bytes Read: 1 OK [CAPABILITY IMAP4REV1 IDLE NAMESPACE MAILBOX-REFERRALS BINA +RY UNSELECT SCAN SORT THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAP +PEND] User someuser authenticated Autoloading: STATUS Inbox (MESSAGES) Sending: 2 STATUS Inbox (MESSAGES) Sent 27 bytes Read: * STATUS INBOX (MESSAGES 90) 2 OK STATUS completed Sending: 3 STATUS Inbox (MESSAGES) Sent 27 bytes Read: * STATUS INBOX (MESSAGES 90) 3 OK STATUS completed msg count = 90 Sending: 4 UID SEARCH ALL Sent 18 bytes Read: 4 BAD Command unrecognized: UID SEARCH $i = Sending: 5 LOGOUT Sent 10 bytes Read: * BYE somehost IMAP4rev1 server terminating connection 5 OK LOGOUT completed C:\>
Edited by Chady -- fixed formatting, added code tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mail::IMAPClient wont get messages
by rob_au (Abbot) on Jan 01, 2004 at 07:43 UTC | |
by Anonymous Monk on Jan 01, 2004 at 14:19 UTC | |
|
Re: Mail::IMAPClient wont get messages
by markov (Scribe) on Jan 01, 2004 at 11:21 UTC | |
by RichardH (Sexton) on Jan 01, 2004 at 14:23 UTC |