diff -Naur fetchmail-5.9.6.orig/imap.c fetchmail-5.9.6/imap.c --- fetchmail-5.9.6.orig/imap.c Mon Dec 31 14:40:11 2001 +++ fetchmail-5.9.6/imap.c Tue Jan 1 14:55:49 2002 @@ -486,19 +486,26 @@ * just after deletion. */ ok = 0; - if (deletions && expunge_period != 1) + if (deletions) { ok = internal_expunge(sock); - count = -1; - if (do_idle) - ok = imap_idle(sock); - if (ok || gen_transact(sock, "NOOP")) - { - report(stderr, GT_("re-poll failed\n")); - return(ok); + if (ok) + { + report(stderr, GT_("expunge failed\n")); + return(ok); + } } - else if (count == -1) /* no EXISTS response to NOOP/IDLE */ - { - count = 0; + + /* + * count is already set here by the last EXPUNGE or any other imap + * command which returned EXISTS on detecting mailbox modification. + */ + if (count == 0 && do_idle) { + ok = imap_idle(sock); + if (ok) + { + report(stderr, GT_("re-poll failed\n")); + return(ok); + } } if (outlevel >= O_DEBUG) report(stdout, GT_("%d messages waiting after re-poll\n"), count);