]> Pileus Git - ~andy/fetchmail/commitdiff
Merge Fabrice Bellet's patch to fix recentcount/count after IMAP
authorMatthias Andree <matthias.andree@gmx.de>
Fri, 10 Sep 2004 12:06:52 +0000 (12:06 -0000)
committerMatthias Andree <matthias.andree@gmx.de>
Fri, 10 Sep 2004 12:06:52 +0000 (12:06 -0000)
EXPUNGE, to fix a hang after EXPUNGE for servers that don't update the
number of RECENT and EXISTS messages such as Dovecot 0.99.10.
Fixes Red Hat bug #113492.

Credits:
Fabrice Bellet (patch)
Timo Sirainen (patch assistance)
Alexandre Oliva (bug report)

References:
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=113492
http://bugzilla.redhat.com/bugzilla/attachment.cgi?id=100788&action=view
http://lists.ccil.org/pipermail/fetchmail-friends/2004-June/008840.html

svn path=/trunk/; revision=3938

NEWS
imap.c

diff --git a/NEWS b/NEWS
index d902dad8e9f658158ae1b96f69cbcc25edc497cc..c03432b03e6829981eef132968f9be1f7c0aa3e7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@
 * Added Andrey Lelikov's recupe for Hotmail and Lycos Webmail.
 * Switched to automake. (Matthias Andree)
 * Build fixes for HESIOD and resolv.h trouble on FreeBSD. (Matthias Andree)
+* Fabrice Bellet's fix for Red Hat bug #113492, fetchmail hangs in IMAP
+  mode after EXPUNGE when the server (Dovecot 0.99.10) doesn't update
+  RECENT and EXISTS counts. (Matthias Andree)
 
 fetchmail-6.2.5 (Wed Oct 15 18:39:22 EDT 2003), 23079 lines:
 
diff --git a/imap.c b/imap.c
index af930b48940c40ef097997c7551c72d0271e5915..ff727e7e95ac48c4a1284ec98544562df8a649b8 100644 (file)
--- a/imap.c
+++ b/imap.c
@@ -32,6 +32,7 @@ extern char *strstr(const char *, const char *);      /* needed on sysV68 R3V7.1. */
 #define IMAP4rev1      1       /* IMAP4 rev 1, RFC2060 */
 
 static int count = 0, recentcount = 0, unseen = 0, deletions = 0;
+static int recentcount_ok = 0;
 static unsigned int startcount = 1;
 static int expunged, expunge_period, saved_timeout = 0;
 static int imap_version, preauth;
@@ -103,8 +104,15 @@ static int imap_ok(int sock, char *argbuf)
        /* a space is required to avoid confusion with the \Recent flag */
        else if (strstr(buf, " RECENT"))
        {
+            recentcount_ok = 1;
            recentcount = atoi(buf+2);
        }
+        else if (strstr(buf, "EXPUNGE") && !strstr(buf, "OK"))
+        {
+            count -= atoi(buf+2);
+            if (count < 0)
+                count = 0;
+        }
        else if (strstr(buf, "PREAUTH"))
            preauth = TRUE;
        /*
@@ -547,9 +555,16 @@ static int internal_expunge(int sock)
 {
     int        ok;
 
+    recentcount_ok = 0;
+
     if ((ok = gen_transact(sock, "EXPUNGE")))
        return(ok);
 
+    /* some servers do not report RECENT after an EXPUNGE. in this case, 
+     * the previous value of recentcount is just ignored. */
+    if (!recentcount_ok)
+        recentcount = 0;
+
     expunged += deletions;
     deletions = 0;
 
@@ -650,10 +665,6 @@ static int imap_getrange(int sock,
         * for new mail.
         */
 
-       /* some servers do not report RECENT after an EXPUNGE. this check
-        * forces an incorrect recentcount to be ignored. */
-       if (recentcount > count)
-           recentcount = 0;
        /* this is a while loop because imap_idle() might return on other
         * mailbox changes also */
        while (recentcount == 0 && do_idle) {