From: Kevin McCarthy Date: Fri, 7 Jun 2019 20:43:36 +0000 (-0700) Subject: Improve imap_append_message() error message handling. X-Git-Tag: mutt-1-12-1-rel~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f5e6bbb45d88b072aadeadc4515815345bbc189;p=mutt 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. --- diff --git a/imap/message.c b/imap/message.c index db779bd1..be6e4a7e 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1201,19 +1201,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) - { - char *pc; - - dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->buf)); - - pc = idata->buf + SEQLEN; - SKIPWS (pc); - pc = imap_next_word (pc); - mutt_error ("%s", pc); - mutt_sleep (1); - goto fail; - } + goto cmd_step_fail; for (last = EOF, sent = len = 0; (c = fgetc(fp)) != EOF; last = c) { @@ -1244,22 +1232,27 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) + goto cmd_step_fail; + + FREE (&mx.mbox); + return 0; + +cmd_step_fail: + dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", + idata->buf)); + if (rc != IMAP_CMD_BAD) { char *pc; - dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->buf)); - pc = idata->buf + SEQLEN; - SKIPWS (pc); - pc = imap_next_word (pc); - mutt_error ("%s", pc); - mutt_sleep (1); - goto fail; + pc = imap_next_word (idata->buf); /* skip sequence number or token */ + pc = imap_next_word (pc); /* skip response code */ + if (*pc) + { + mutt_error ("%s", pc); + mutt_sleep (1); + } } - FREE (&mx.mbox); - return 0; - fail: safe_fclose (&fp); FREE (&mx.mbox);