diff -Naur fetchmail-5.9.6.orig/imap.c fetchmail-5.9.6/imap.c --- fetchmail-5.9.6.orig/imap.c Tue Jan 1 14:55:49 2002 +++ fetchmail-5.9.6/imap.c Thu Jan 3 10:49:49 2002 @@ -29,7 +29,7 @@ #define IMAP4 0 /* IMAP4 rev 0, RFC1730 */ #define IMAP4rev1 1 /* IMAP4 rev 1, RFC2060 */ -static int count, unseen, deletions, imap_version, preauth; +static int count = 0, recentcount = 0, unseen, deletions, imap_version, preauth; static int expunged, expunge_period, saved_timeout; static flag do_idle; static char capabilities[MSGBUFSIZE+1]; @@ -76,6 +76,10 @@ stage = STAGE_FETCH; } } + else if (strstr(buf, "RECENT")) + { + recentcount = atoi(buf+2); + } else if (strstr(buf, "PREAUTH")) preauth = TRUE; /* @@ -496,10 +500,14 @@ } /* - * count is already set here by the last EXPUNGE or any other imap - * command which returned EXISTS on detecting mailbox modification. + * recentcount is already set here by the last imap command which + * returned RECENT on detecting new mail. if recentcount is 0, wait + * for new mail. */ - if (count == 0 && do_idle) { + + /* this is a while loop because imap_idle() might return on other + * mailbox changes also */ + while (recentcount == 0 && do_idle) { ok = imap_idle(sock); if (ok) { @@ -512,6 +520,7 @@ } else { + count = 0; ok = gen_transact(sock, check_only ? "EXAMINE \"%s\"" : "SELECT \"%s\"", folder ? folder : "INBOX"); @@ -547,6 +556,7 @@ } *countp = count; + recentcount = 0; /* OK, now get a count of unseen messages and their indices */ if (!ctl->fetchall && count > 0)