]> Pileus Git - ~andy/fetchmail/commitdiff
Try to do IDLE (if enabled) even when there are no messages.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 28 Jun 2000 13:58:01 +0000 (13:58 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 28 Jun 2000 13:58:01 +0000 (13:58 -0000)
svn path=/trunk/; revision=2916

imap.c

diff --git a/imap.c b/imap.c
index 8b4c3a28d10e433912dac3c71fbba96846d07420..1f8d7cbaade47b031f937885b9c560ce5b9a97b1 100644 (file)
--- a/imap.c
+++ b/imap.c
@@ -1044,6 +1044,16 @@ static int internal_expunge(int sock)
     return(PS_SUCCESS);
 }
 
+static int imap_idle(int sock)
+/* start an RFC2177 IDLE */
+{
+    stage = STAGE_IDLE;
+    saved_timeout = mytimeout;
+    mytimeout = 0;
+
+    return (gen_transact(sock, "IDLE"));
+}
+
 static int imap_getrange(int sock, 
                         struct query *ctl, 
                         const char *folder, 
@@ -1069,12 +1079,8 @@ static int imap_getrange(int sock,
            ok = internal_expunge(sock);
        count = -1;
        if (do_idle)
-       {
-           stage = STAGE_IDLE;
-           saved_timeout = mytimeout;
-           mytimeout = 0;
-       }
-       if (ok || gen_transact(sock, do_idle ? "IDLE" : "NOOP"))
+           ok = imap_idle(sock);
+       if (ok || gen_transact(sock, "NOOP"))
        {
            report(stderr, _("re-poll failed\n"));
            return(ok);
@@ -1098,6 +1104,10 @@ static int imap_getrange(int sock,
        }
        else if (outlevel >= O_DEBUG)
            report(stdout, "%d messages waiting after first poll\n", count);
+
+       /* no messages?  then we may need to idle until we get some */
+       if (count == 0 && do_idle)
+           imap_idle(sock);
     }
 
     *countp = count;