From: Kevin McCarthy Date: Sun, 22 Sep 2019 02:41:28 +0000 (-0700) Subject: Convert compose check_attachments() to use buffer pool. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f89f5308e8a89212df35d9c527d4088c3d01d47;p=mutt Convert compose check_attachments() to use buffer pool. Modify error message so that the filename comes last, to prevent a long path from hiding the error message or prompt. --- diff --git a/compose.c b/compose.c index c64245b0..93cb2012 100644 --- 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)