]> granicus.if.org Git - neomutt/commitdiff
Improve imap_append_message() error message handling
authorKevin McCarthy <kevin@8t8.us>
Fri, 7 Jun 2019 20:43:36 +0000 (13:43 -0700)
committerRichard Russon <rich@flatcap.org>
Sun, 16 Jun 2019 00:20:16 +0000 (01:20 +0100)
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 <rich@flatcap.org>
imap/message.c

index 55f816c8dc75f6d6bd17868a7fc8a3111873a540..3c33fe31386af705bdfd340f568c31b1801a2b62 100644 (file)
@@ -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;