From 95f0d4002c620178b5631656aa6f65ffe8f55e18 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Fri, 7 Jun 2019 13:43:36 -0700 Subject: [PATCH] Improve imap_append_message() error message handling If the rc is IMAP_CMD_BAD, then either idata->buf is stale or an error message has already been printed (in cmd_handle_untagged()). Use imap_next_word() to skip over the next two words instead of directly skipping over SEQLEN, in case the buffer is in a different format. We don't want to jump over the end of string. Skip the mutt_error() if there is nothing to print. Co-authored-by: Richard Russon --- imap/message.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/imap/message.c b/imap/message.c index 55f816c8d..3c33fe313 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1500,15 +1500,7 @@ int imap_append_message(struct Mailbox *m, struct Message *msg) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) - { - mutt_debug(LL_DEBUG1, "#1 command failed: %s\n", adata->buf); - - char *pc = adata->buf + SEQ_LEN; - SKIPWS(pc); - pc = imap_next_word(pc); - mutt_error("%s", pc); - goto fail; - } + goto cmd_step_fail; for (last = EOF, sent = len = 0; (c = fgetc(fp)) != EOF; last = c) { @@ -1539,17 +1531,20 @@ int imap_append_message(struct Mailbox *m, struct Message *msg) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) - { - mutt_debug(LL_DEBUG1, "#2 command failed: %s\n", adata->buf); - char *pc = adata->buf + SEQ_LEN; - SKIPWS(pc); - pc = imap_next_word(pc); - mutt_error("%s", pc); - goto fail; - } + goto cmd_step_fail; return 0; +cmd_step_fail: + mutt_debug(LL_DEBUG1, "imap_append_message(): command failed: %s\n", adata->buf); + if (rc != IMAP_CMD_BAD) + { + char *pc = imap_next_word(adata->buf); /* skip sequence number or token */ + pc = imap_next_word(pc); /* skip response code */ + if (*pc != '\0') + mutt_error("%s", pc); + } + fail: mutt_file_fclose(&fp); return -1; -- 2.40.0