]> granicus.if.org Git - mutt/commitdiff
Convert compose check_attachments() to use buffer pool.
authorKevin McCarthy <kevin@8t8.us>
Sun, 22 Sep 2019 02:41:28 +0000 (19:41 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 22 Sep 2019 02:41:28 +0000 (19:41 -0700)
Modify error message so that the filename comes last, to prevent a
long path from hiding the error message or prompt.

compose.c

index c64245b01793a01f17f2a2c3cc332682c3c3ea5b..93cb2012e87113c11a87e32fa656802e13d667ee 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -471,35 +471,62 @@ static void redraw_mix_line (LIST *chain)
 static int
 check_attachments(ATTACH_CONTEXT *actx)
 {
-  int i, r;
+  int i, r, rc = -1;
   struct stat st;
-  char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
+  BUFFER *pretty = NULL, *msg = NULL;
 
   for (i = 0; i < actx->idxlen; i++)
   {
-    strfcpy(pretty, actx->idx[i]->content->filename, sizeof(pretty));
     if (stat(actx->idx[i]->content->filename, &st) != 0)
     {
-      mutt_pretty_mailbox(pretty, sizeof (pretty));
-      mutt_error(_("%s [#%d] no longer exists!"),
-                pretty, i+1);
-      return -1;
+      if (!pretty)
+        pretty = mutt_buffer_pool_get ();
+      mutt_buffer_strcpy (pretty, actx->idx[i]->content->filename);
+      mutt_buffer_pretty_mailbox (pretty);
+      /* L10N:
+         This message is displayed in the compose menu when an attachment
+         doesn't stat.  %d is the attachment number and %s is the
+         attachment filename.
+         The filename is located last to avoid a long path hiding the
+         error message.
+      */
+      mutt_error (_("Attachment #%d no longer exists: %s"),
+                  i+1, mutt_b2s (pretty));
+      goto cleanup;
     }
 
     if (actx->idx[i]->content->stamp < st.st_mtime)
     {
-      mutt_pretty_mailbox(pretty, sizeof (pretty));
-      snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
-              pretty, i+1);
-
-      if ((r = mutt_yesorno(msg, MUTT_YES)) == MUTT_YES)
-       mutt_update_encoding(actx->idx[i]->content);
+      if (!pretty)
+        pretty = mutt_buffer_pool_get ();
+      mutt_buffer_strcpy (pretty, actx->idx[i]->content->filename);
+      mutt_buffer_pretty_mailbox (pretty);
+
+      if (!msg)
+        msg = mutt_buffer_pool_get ();
+      /* L10N:
+         This message is displayed in the compose menu when an attachment
+         is modified behind the scenes.  %d is the attachment number
+         and %s is the attachment filename.
+         The filename is located last to avoid a long path hiding the
+         prompt question.
+      */
+      mutt_buffer_printf (msg, _("Attachment #%d modified. Update encoding for %s?"),
+                          i+1, mutt_b2s (pretty));
+
+      if ((r = mutt_yesorno (mutt_b2s (msg), MUTT_YES)) == MUTT_YES)
+       mutt_update_encoding (actx->idx[i]->content);
       else if (r == -1)
-       return -1;
+       goto cleanup;
     }
   }
 
-  return 0;
+  rc = 0;
+
+cleanup:
+  mutt_buffer_pool_release (&pretty);
+  mutt_buffer_pool_release (&msg);
+  return rc;
 }
 
 static void draw_envelope_addr (int line, ADDRESS *addr)