From 94022a6752ac61842bac77957364b288787be607 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 23 Nov 2019 13:51:20 +0100 Subject: [PATCH] catch server's failure to FETCH * the query is untypical enough to have caused problems with davmail (when we still used *:*) and mailo.com (until it got fixed), so better check that the result (not) returned by the server makes sense. --- src/drv_imap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 989b86e..dd0215f 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -2404,9 +2404,15 @@ imap_open_box_p3( imap_store_t *ctx, imap_cmd_t *gcmd, int response ) { imap_cmd_open_box_t *cmdp = (imap_cmd_open_box_t *)gcmd; - // This will happen if the box is empty. - if (!ctx->uidnext) + if (!ctx->uidnext) { + if (ctx->total_msgs) { + error( "IMAP error: querying server for highest UID failed\n" ); + imap_open_box_p4( ctx, cmdp, RESP_NO ); + return; + } + // This is ok, the box is simply empty. ctx->uidnext = 1; + } imap_open_box_p4( ctx, cmdp, response ); } @@ -2983,10 +2989,16 @@ imap_find_new_msgs_p3( imap_store_t *ctx, imap_cmd_t *gcmd, int response ) imap_cmd_find_new_t *cmdp = (imap_cmd_find_new_t *)gcmd; imap_cmd_find_new_t *cmd; - if (response != RESP_OK || ctx->uidnext <= cmdp->uid) { + if (response != RESP_OK) { imap_find_new_msgs_p4( ctx, gcmd, response ); return; } + if (!ctx->uidnext) { + // We are assuming that the new messages were not in fact instantly deleted. + error( "IMAP error: re-querying server for highest UID failed\n" ); + imap_find_new_msgs_p4( ctx, gcmd, RESP_NO ); + return; + } INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cmdp->callback, cmdp->callback_aux) cmd->out_msgs = cmdp->out_msgs; imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_find_new_msgs_p4,