goto no_error;
} while
/*
- * Only re-poll if we either had some actual forwards and
- * either allowed deletions and had no errors.
+ * Only repoll if we either had some actual forwards
+ * or are idling for new mails and had no errors.
* Otherwise it is far too easy to get into infinite loops.
*/
- (dispatches && ctl->server.base_protocol->retry && !ctl->keep && !ctl->errcount);
+ (ctl->server.base_protocol->retry && (dispatches || ctl->idle) && !ctl->errcount);
}
/* XXX: From this point onwards, preserve err unless a new error has occurred */
static int expunge_period = 1;
/* mailbox variables initialized in imap_getrange() */
-static int count = 0, recentcount = 0, unseen = 0, deletions = 0;
+static int count = 0, oldcount = 0, recentcount = 0, unseen = 0, deletions = 0;
static unsigned int startcount = 1;
static int expunged = 0;
static unsigned int *unseen_messages;
report(stderr, GT_("bogus message count!"));
return(PS_PROTOCOL);
}
+ if ((recentcount = count - oldcount) < 0)
+ recentcount = 0;
/*
* Nasty kluge to handle RFC2177 IDLE. If we know we're idling
stage = STAGE_FETCH;
}
}
+ /* we now compute recentcount as a difference between
+ * new and old EXISTS, hence disable RECENT check */
+# if 0
else if (strstr(buf, " RECENT"))
{
recentcount = atoi(buf+2);
}
+# endif
else if (strstr(buf, " EXPUNGE"))
{
/* the response "* 10 EXPUNGE" means that the currently
{
if (count > 0)
count--;
- /* Some servers do not report RECENT after an EXPUNGE.
- * For such servers, assume that the mail being
- * expunged is a recent one. For other servers, we
- * should get an updated RECENT report later and this
- * assumption will have no effect. */
+ if (oldcount > 0)
+ oldcount--;
+ /* We do expect an EXISTS response immediately
+ * after this, so this updation of recentcount is
+ * just a precaution! */
if (recentcount > 0)
recentcount--;
actual_deletions++;
int *countp, int *newp, int *bytes)
/* get range of messages to be fetched */
{
- int ok, oldcount;
+ int ok;
char buf[MSGBUFSIZE+1], *cp;
/* find out how many messages are waiting */
* end_mailbox_poll().
*
* recentcount is already set here by the last imap command which
- * returned RECENT on detecting new mail. if recentcount is 0, wait
+ * returned EXISTS on detecting new mail. if recentcount is 0, wait
* for new mail.
*
* this is a while loop because imap_idle() might return on other
* mailbox changes also */
- oldcount = count;
- while (count <= oldcount && recentcount == 0 && do_idle) {
- oldcount = count;
+ while (recentcount == 0 && do_idle) {
smtp_close(ctl, 1);
ok = imap_idle(sock);
if (ok)
}
}
/* if recentcount is 0, return no mail */
- if (recentcount == 0 && count <= oldcount)
+ if (recentcount == 0)
count = 0;
if (outlevel >= O_DEBUG)
report(stdout, ngettext("%d message waiting after re-poll\n",
}
else
{
- count = 0;
+ oldcount = count = 0;
ok = gen_transact(sock,
check_only ? "EXAMINE \"%s\"" : "SELECT \"%s\"",
folder ? folder : "INBOX");
}
}
- *countp = count;
+ *countp = oldcount = count;
recentcount = 0;
startcount = 1;