From b570c17766a2ef1c12cf6e6653a878a3f93a65ee Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 25 Sep 2013 17:13:00 +0200 Subject: [PATCH] deal with messages disappearing between being listed and fetched --- src/drv_imap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 4940b5b..bd940ae 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -1876,6 +1876,8 @@ imap_submit_load( imap_store_t *ctx, const char *buf, int tuids, struct imap_cmd /******************* imap_fetch_msg *******************/ +static void imap_fetch_msg_p2( imap_store_t *ctx, struct imap_cmd *gcmd, int response ); + static void imap_fetch_msg( store_t *ctx, message_t *msg, msg_data_t *data, void (*cb)( int sts, void *aux ), void *aux ) @@ -1885,12 +1887,25 @@ imap_fetch_msg( store_t *ctx, message_t *msg, msg_data_t *data, INIT_IMAP_CMD_X(imap_cmd_fetch_msg, cmd, cb, aux) cmd->gen.gen.param.uid = msg->uid; cmd->msg_data = data; - imap_exec( (imap_store_t *)ctx, &cmd->gen.gen, imap_done_simple_msg, + data->data = 0; + imap_exec( (imap_store_t *)ctx, &cmd->gen.gen, imap_fetch_msg_p2, "UID FETCH %d (%s%sBODY.PEEK[])", msg->uid, !(msg->status & M_FLAGS) ? "FLAGS " : "", (data->date== -1) ? "INTERNALDATE " : "" ); } +static void +imap_fetch_msg_p2( imap_store_t *ctx, struct imap_cmd *gcmd, int response ) +{ + struct imap_cmd_fetch_msg *cmd = (struct imap_cmd_fetch_msg *)gcmd; + + if (response == RESP_OK && !cmd->msg_data->data) { + /* The FETCH succeeded, but there is no message with this UID. */ + response = RESP_NO; + } + imap_done_simple_msg( ctx, gcmd, response ); +} + /******************* imap_set_flags *******************/ static void imap_set_flags_p2( imap_store_t *, struct imap_cmd *, int );