update_crypt_info(rd);
+ /* Since this is rather long lived, we don't use the pool */
+ struct Buffer fname = mutt_buffer_make(PATH_MAX);
+
while (loop)
{
#ifdef USE_NNTP
char *prompt = _("Attach file");
int numfiles = 0;
char **files = NULL;
- buf[0] = '\0';
- if ((mutt_enter_fname_full(prompt, buf, sizeof(buf), false, true,
- &files, &numfiles, MUTT_SEL_MULTI) == -1) ||
- (*buf == '\0'))
+ mutt_buffer_reset(&fname);
+ if ((mutt_buffer_enter_fname_full(prompt, &fname, false, true, &files,
+ &numfiles, MUTT_SEL_MULTI) == -1) ||
+ mutt_buffer_is_empty(&fname))
{
break;
}
case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
#endif
{
+ mutt_buffer_reset(&fname);
char *prompt = _("Open mailbox to attach message from");
- buf[0] = '\0';
#ifdef USE_NNTP
OptNews = false;
if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->mailbox->magic == MUTT_NNTP))
#endif
{
- mutt_str_strfcpy(buf, mailbox_path(Context->mailbox), sizeof(buf));
- mutt_pretty_mailbox(buf, sizeof(buf));
+ mutt_buffer_strcpy(&fname, mailbox_path(Context->mailbox));
+ mutt_buffer_pretty_mailbox(&fname);
}
- if ((mutt_enter_fname(prompt, buf, sizeof(buf), true) == -1) || (buf[0] == '\0'))
+ if ((mutt_buffer_enter_fname(prompt, &fname, true) == -1) ||
+ mutt_buffer_is_empty(&fname))
+ {
break;
+ }
#ifdef USE_NNTP
if (OptNews)
- nntp_expand_path(buf, sizeof(buf), &CurrentNewsSrv->conn->account);
+ nntp_expand_path(fname.data, fname.dsize, &CurrentNewsSrv->conn->account);
else
#endif
- mutt_expand_path(buf, sizeof(buf));
+ mutt_buffer_expand_path(&fname);
#ifdef USE_IMAP
- if (imap_path_probe(buf, NULL) != MUTT_IMAP)
+ if (imap_path_probe(mutt_b2s(&fname), NULL) != MUTT_IMAP)
#endif
#ifdef USE_POP
- if (pop_path_probe(buf, NULL) != MUTT_POP)
+ if (pop_path_probe(mutt_b2s(&fname), NULL) != MUTT_POP)
#endif
#ifdef USE_NNTP
- if (!OptNews && (nntp_path_probe(buf, NULL) != MUTT_NNTP))
+ if (!OptNews && (nntp_path_probe(mutt_b2s(&fname), NULL) != MUTT_NNTP))
#endif
/* check to make sure the file exists and is readable */
- if (access(buf, R_OK) == -1)
+ if (access(mutt_b2s(&fname), R_OK) == -1)
{
- mutt_perror(buf);
+ mutt_perror(mutt_b2s(&fname));
break;
}
menu->redraw = REDRAW_FULL;
- struct Mailbox *m = mx_path_resolve(buf);
+ struct Mailbox *m = mx_path_resolve(mutt_b2s(&fname));
struct Context *ctx = mx_mbox_open(m, MUTT_READONLY);
if (!ctx)
{
- mutt_error(_("Unable to open mailbox %s"), buf);
+ mutt_error(_("Unable to open mailbox %s"), mutt_b2s(&fname));
mailbox_free(&m);
break;
}
src = CUR_ATTACH->content->d_filename;
else
src = CUR_ATTACH->content->filename;
- mutt_str_strfcpy(buf, mutt_path_basename(NONULL(src)), sizeof(buf));
- int ret = mutt_get_field(_("Send attachment with name: "), buf, sizeof(buf), MUTT_FILE);
+ mutt_buffer_strcpy(&fname, mutt_path_basename(NONULL(src)));
+ int ret = mutt_buffer_get_field(_("Send attachment with name: "), &fname, MUTT_FILE);
if (ret == 0)
{
/* As opposed to RENAME_FILE, we don't check buf[0] because it's
* valid to set an empty string here, to erase what was set */
- mutt_str_replace(&CUR_ATTACH->content->d_filename, buf);
+ mutt_str_replace(&CUR_ATTACH->content->d_filename, mutt_b2s(&fname));
menu->redraw = REDRAW_CURRENT;
}
break;
case OP_COMPOSE_RENAME_FILE:
CHECK_COUNT;
- mutt_str_strfcpy(buf, CUR_ATTACH->content->filename, sizeof(buf));
- mutt_pretty_mailbox(buf, sizeof(buf));
- if ((mutt_get_field(_("Rename to: "), buf, sizeof(buf), MUTT_FILE) == 0) &&
- (buf[0] != '\0'))
+ mutt_buffer_strcpy(&fname, CUR_ATTACH->content->filename);
+ mutt_buffer_pretty_mailbox(&fname);
+ if ((mutt_buffer_get_field(_("Rename to: "), &fname, MUTT_FILE) == 0) &&
+ !mutt_buffer_is_empty(&fname))
{
struct stat st;
if (stat(CUR_ATTACH->content->filename, &st) == -1)
{
/* L10N: "stat" is a system call. Do "man 2 stat" for more information. */
- mutt_error(_("Can't stat %s: %s"), buf, strerror(errno));
+ mutt_error(_("Can't stat %s: %s"), mutt_b2s(&fname), strerror(errno));
break;
}
- mutt_expand_path(buf, sizeof(buf));
- if (mutt_file_rename(CUR_ATTACH->content->filename, buf))
+ mutt_buffer_expand_path(&fname);
+ if (mutt_file_rename(CUR_ATTACH->content->filename, mutt_b2s(&fname)))
break;
- mutt_str_replace(&CUR_ATTACH->content->filename, buf);
+ mutt_str_replace(&CUR_ATTACH->content->filename, mutt_b2s(&fname));
menu->redraw = REDRAW_CURRENT;
if (CUR_ATTACH->content->stamp >= st.st_mtime)
case OP_COMPOSE_NEW_MIME:
{
- buf[0] = '\0';
- if ((mutt_get_field(_("New file: "), buf, sizeof(buf), MUTT_FILE) != 0) ||
- (buf[0] == '\0'))
+ mutt_buffer_reset(&fname);
+ if ((mutt_buffer_get_field(_("New file: "), &fname, MUTT_FILE) != 0) ||
+ mutt_buffer_is_empty(&fname))
{
continue;
}
- mutt_expand_path(buf, sizeof(buf));
+ mutt_buffer_expand_path(&fname);
/* Call to lookup_mime_type () ? maybe later */
char type[256] = { 0 };
}
struct AttachPtr *ap = mutt_mem_calloc(1, sizeof(struct AttachPtr));
/* Touch the file */
- FILE *fp = mutt_file_fopen(buf, "w");
+ FILE *fp = mutt_file_fopen(mutt_b2s(&fname), "w");
if (!fp)
{
- mutt_error(_("Can't create file %s"), buf);
+ mutt_error(_("Can't create file %s"), mutt_b2s(&fname));
FREE(&ap);
continue;
}
mutt_file_fclose(&fp);
- ap->content = mutt_make_file_attach(buf);
+ ap->content = mutt_make_file_attach(mutt_b2s(&fname));
if (!ap->content)
{
mutt_error(_("What we have here is a failure to make an attachment"));
break;
case OP_COMPOSE_WRITE_MESSAGE:
- buf[0] = '\0';
+ mutt_buffer_reset(&fname);
if (Context)
{
- mutt_str_strfcpy(buf, mailbox_path(Context->mailbox), sizeof(buf));
- mutt_pretty_mailbox(buf, sizeof(buf));
+ mutt_buffer_strcpy(&fname, mailbox_path(Context->mailbox));
+ mutt_buffer_pretty_mailbox(&fname);
}
if (actx->idxlen)
e->content = actx->idx[0]->content;
- if ((mutt_enter_fname(_("Write message to mailbox"), buf, sizeof(buf), true) != -1) &&
- (buf[0] != '\0'))
+ if ((mutt_buffer_enter_fname(_("Write message to mailbox"), &fname, true) != -1) &&
+ !mutt_buffer_is_empty(&fname))
{
- mutt_message(_("Writing message to %s ..."), buf);
- mutt_expand_path(buf, sizeof(buf));
+ mutt_message(_("Writing message to %s ..."), mutt_b2s(&fname));
+ mutt_buffer_expand_path(&fname);
if (e->content->next)
e->content = mutt_make_multipart(e->content);
- if (mutt_write_fcc(buf, e, NULL, false, NULL, NULL) < 0)
+ if (mutt_write_fcc(mutt_b2s(&fname), e, NULL, false, NULL, NULL) < 0)
e->content = mutt_remove_multipart(e->content);
else
mutt_message(_("Message written"));
}
}
+ mutt_buffer_dealloc(&fname);
+
#ifdef USE_AUTOCRYPT
/* This is a fail-safe to make sure the bit isn't somehow turned
* on. The user could have disabled the option after setting SEC_AUTOCRYPT,