Re: Mail::Box::IMAP4
Tom Allison <[email protected]> Wed, 22 Sep 2004 05:20:55 -0400
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Message-ID | <[email protected]> |
Mark Overmeer wrote: > * Tom Allison ([email protected]) [040922 02:58]: > >>>I am using HTML::Mason as the basis of an IMAP webclient and was going >>>to see how well Mail::Box::IMAP4 and HTML::FromMail would fit into this. >> <..snip..> >> >>But $mgr assumes mbox format and not an IMAP connection. > > > The manager is not able to detect automatically that you are talking > about an imap folder: it looks on disk and finds not file nor directory > named 'INBOX', and therefore creates a default folder. > > The easiest way to open an IMAP folder would be: > > use Mail::Box::Manager > my $mgr = Mail::Box::Manager->new(); > my $folder = $mgr->open > ( 'INBOX' > , type => 'imap' > , password => 'bar' > , server_name => 'xyz' > , server_port => 143 > , username => 'foo' > ) or die; > > print $folder->nrMessages; > > or even > > my $folder = $mgr->open('imap://foo:bar@xyz:143/INBOX') or die; > > should work. > The IMAP client is relatively new, so please don't hesitate to > contact me if you encounter problems. SSL is not supported (yet) Mail::Box version is 2.055 if I read it correctly from the debian unstable package tree. use strict; use Mail::Box::IMAP4; use Mail::Box::Manager; use HTML::FromMail; use Mail::IMAPClient; use Data::Dumper; my $username = "xxxxxx"; my $password = "xxxxxx"; my $server = "xxxxxx.xxxxx.xxx"; my $imap = Mail::IMAPClient->new(Server => $server); $imap->User($username); $imap->Password($password); $imap->login; print "IsConnected\n" if $imap->IsConnected; print "IsAuthenticated\n" if $imap->IsAuthenticated; $imap->disconnect(); my $mgr = Mail::Box::Manager->new(); my $folder=$mgr->open('INBOX' , folder_types => 'imap' , username => $username , password => $password , server_name => $server , server_port => 143 ) || die $!; #line 34 print $folder->name; END { $imap->disconnect() if $imap->IsConnected; } ################# RETURNED IsConnected IsAuthenticated ERROR: Folder type imap is unknown, using autodetect. WARNING: Folder does not exist, failed opening mbox folder INBOX. No such file or directory at bin/mailbox.pl line 34. ( "my $folder=$mgr->open(..." ) Running a slightly altered script to get the proper name of the folders: ($imap is a Mail::IMAPClient opject that is logged in and authenticated) my $folder = Mail::Box::IMAP4->new(imap_client => $imap , join_connection => 1); print join("\n",$folder->listSubFolders()); $imap->disconnect(); undef $folder; shows that the correct folder name is INBOX Further analysis shows that print join("\n", $mgr->folderTypes),"\n"; does not return an imap foldertype (maildir mbox mh pop pop3) Inserting the string $mgr->registerType(imap=>'Mail::Box::IMAP4'); between the $mgr = ....->new() and $folder = $mgr->open(... seems to hang for ~60 seconds and then completes without error. But it does complete. It seems that the imap foldertype isn't getting picked up as one of the valid types in the instantiation of the Mail::Box::Manager. This might be resolved in later versions (2.055), I don't know. Since this is what I have to work with for right now I could either upgrade to CPAN (not preferred on my part) or is there a more effecient method of registering an IMAP? My assumption is that the ~60 second "hang" is a network timeout of some sort that I should be able to improve if I was sure which fine manual it's in (Mail::Box::IMAP4?).