From ab4573272541ab8e28e0792325fb63303135573b Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Mon, 10 Jun 2019 14:51:50 -0700 Subject: [PATCH] Allow imap_cmd_finish() to both expunge and fetch new mail. Since commit dd327606 changed check_status setting to use bit operators, and imap_check_mailbox() can call imap_cmd_finish() twice, there is no reason to delay the processing of new mail until a second call. imap_read_headers() deals with msn_end < msg_begin, so remove the (count > idata->max_msn) check. This will allow the reopen flag to be reset if somehow it's not the case. --- imap/command.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/imap/command.c b/imap/command.c index d76ce200..69ac0b02 100644 --- a/imap/command.c +++ b/imap/command.c @@ -289,10 +289,15 @@ int imap_exec (IMAP_DATA* idata, const char* cmdstr, int flags) return 0; } -/* imap_cmd_finish: Attempts to perform cleanup (eg fetch new mail if - * detected, do expunge). Called automatically by imap_cmd_step, but - * may be called at any time. Called by imap_check_mailbox just before - * the index is refreshed, for instance. */ +/* imap_cmd_finish + * + * If a reopen is allowed, it attempts to perform cleanup (eg fetch new + * mail if detected, do expunge). Called automatically by + * imap_cmd_step(), but may be called at any time. + * + * idata->check_status is set and will be used later by + * imap_check_mailbox(). + */ void imap_cmd_finish (IMAP_DATA* idata) { if (idata->status == IMAP_FATAL) @@ -306,29 +311,21 @@ void imap_cmd_finish (IMAP_DATA* idata) if (idata->reopen & IMAP_REOPEN_ALLOW) { - unsigned int count = idata->newMailCount; - - if (!(idata->reopen & IMAP_EXPUNGE_PENDING) && - (idata->reopen & IMAP_NEWMAIL_PENDING) - && count > idata->max_msn) - { - /* read new mail messages */ - dprint (2, (debugfile, "imap_cmd_finish: Fetching new mail\n")); - /* check_status: curs_main uses imap_check_mailbox to detect - * whether the index needs updating */ - idata->check_status |= IMAP_NEWMAIL_PENDING; - imap_read_headers (idata, idata->max_msn+1, count, 0); - } - else if (idata->reopen & IMAP_EXPUNGE_PENDING) + if (idata->reopen & IMAP_EXPUNGE_PENDING) { dprint (2, (debugfile, "imap_cmd_finish: Expunging mailbox\n")); imap_expunge_mailbox (idata); /* Detect whether we've gotten unexpected EXPUNGE messages */ - if ((idata->reopen & IMAP_EXPUNGE_PENDING) && - !(idata->reopen & IMAP_EXPUNGE_EXPECTED)) + if (!(idata->reopen & IMAP_EXPUNGE_EXPECTED)) idata->check_status |= IMAP_EXPUNGE_PENDING; idata->reopen &= ~(IMAP_EXPUNGE_PENDING | IMAP_EXPUNGE_EXPECTED); } + if (idata->reopen & IMAP_NEWMAIL_PENDING) + { + dprint (2, (debugfile, "imap_cmd_finish: Fetching new mail\n")); + imap_read_headers (idata, idata->max_msn+1, idata->newMailCount, 0); + idata->check_status |= IMAP_NEWMAIL_PENDING; + } } idata->status = 0; -- 2.40.0