Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I connected to the Gmail IMAP server using Mail::IMAPClient.

In Mail::IMAPClient I don't see a way to just idle and wait for new messages. I'd like to assign a callback to just do something when a new message is recieved.

Is there another way to stay attached to a SMTP sever and just idle waiting for new messages? Then when a message is received, trigger an action via a callback?
#!/usr/bin/perl use strict; use warnings; use Mail::IMAPClient; use IO::Socket::SSL; # Connect to the IMAP server via SSL my $socket = IO::Socket::SSL->new( PeerAddr => 'imap.gmail.com', PeerPort => 993, ) or die "socket(): $@"; # Build up a client attached to the SSL socket. # Login is automatic as usual when we provide User and Password my $client = Mail::IMAPClient->new( Socket => $socket, User => 'xxx@gmail.com', Password => 'xxxxxx', ) or die "new(): $@"; # Do something just to see that it's all ok print "I'm authenticated\n" if $client->IsAuthenticated(); my @folders = $client->folders(); print join("\n* ", 'Folders:', @folders), "\n"; # Say bye $client->logout();

Replies are listed 'Best First'.
Re: IMAP Client New Mail Callback
by sflitman (Hermit) on May 09, 2009 at 07:13 UTC
    Yeah, you don't want to waste sockets or bandwidths with TCP keep alive packets. Instead, connect at a reasonable (pseudorandom) interval. That way you're polling the server and being a good netizen.

    HTH,
    SSF

Re: IMAP Client New Mail Callback
by afoken (Chancellor) on May 09, 2009 at 15:01 UTC

    IMAP IDLE

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: IMAP Client New Mail Callback
by Anonymous Monk on May 09, 2009 at 06:10 UTC
    No. SMTP/IMAP don't work like that.
Re: IMAP Client New Mail Callback
by hpavc (Acolyte) on May 10, 2009 at 02:51 UTC
    I couldn't find any examples of Mail::IMAPClient->idle easily, I have tried to impliment it for similar functionality like other mail clients do in the past without much luck. Though I gave up too easy.

      I too have been unable to find an example of how to set up a callback that is run when the client receives a new msg notification from the server.

      Can anyone help?

      R.

      --

      Robin Bowes | http://robinbowes.com