From: Kevin McCarthy Date: Sun, 14 Oct 2018 23:18:53 +0000 (-0700) Subject: Convert mutt_compose_attachment to use BUFFER. X-Git-Tag: mutt-1-11-rel~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffdf38d78d6d230b7045d48581c347c5b327e378;p=mutt Convert mutt_compose_attachment to use BUFFER. --- diff --git a/attach.c b/attach.c index 89574f50..904ec786 100644 --- a/attach.c +++ b/attach.c @@ -95,28 +95,29 @@ int mutt_get_tmp_attachment (BODY *a) int mutt_compose_attachment (BODY *a) { char type[STRING]; - char command[STRING]; - char newfile[_POSIX_PATH_MAX] = ""; + BUFFER *command = mutt_buffer_pool_get (); + BUFFER *newfile = mutt_buffer_pool_get (); + BUFFER *tempfile = mutt_buffer_pool_get (); rfc1524_entry *entry = rfc1524_new_entry (); short unlink_newfile = 0; int rc = 0; - + snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); if (rfc1524_mailcap_lookup (a, type, entry, MUTT_COMPOSE)) { if (entry->composecommand || entry->composetypecommand) { - if (entry->composetypecommand) - strfcpy (command, entry->composetypecommand, sizeof (command)); + mutt_buffer_strcpy (command, entry->composetypecommand); else - strfcpy (command, entry->composecommand, sizeof (command)); - if (rfc1524_expand_filename (entry->nametemplate, - a->filename, newfile, sizeof (newfile))) + mutt_buffer_strcpy (command, entry->composecommand); + + if (mutt_buffer_rfc1524_expand_filename (entry->nametemplate, + a->filename, newfile)) { dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", - a->filename, newfile)); - if (safe_symlink (a->filename, newfile) == -1) + a->filename, mutt_b2s (newfile))); + if (safe_symlink (a->filename, mutt_b2s (newfile)) == -1) { if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) goto bailout; @@ -125,10 +126,10 @@ int mutt_compose_attachment (BODY *a) unlink_newfile = 1; } else - strfcpy(newfile, a->filename, sizeof(newfile)); + mutt_buffer_strcpy (newfile, a->filename); - if (rfc1524_expand_command (a, newfile, type, - command, sizeof (command))) + if (mutt_buffer_rfc1524_expand_command (a, mutt_b2s (newfile), type, + command)) { /* For now, editing requires a file, no piping */ mutt_error _("Mailcap compose entry requires %%s"); @@ -138,14 +139,13 @@ int mutt_compose_attachment (BODY *a) int r; mutt_endwin (NULL); - if ((r = mutt_system (command)) == -1) - mutt_error (_("Error running \"%s\"!"), command); + if ((r = mutt_system (mutt_b2s (command))) == -1) + mutt_error (_("Error running \"%s\"!"), mutt_b2s (command)); if (r != -1 && entry->composetypecommand) { BODY *b; FILE *fp, *tfp; - char tempfile[_POSIX_PATH_MAX]; if ((fp = safe_fopen (a->filename, "r")) == NULL) { @@ -177,8 +177,8 @@ int mutt_compose_attachment (BODY *a) /* Remove headers by copying out data to another file, then * copying the file back */ fseeko (fp, b->offset, 0); - mutt_mktemp (tempfile, sizeof (tempfile)); - if ((tfp = safe_fopen (tempfile, "w")) == NULL) + mutt_buffer_mktemp (tempfile); + if ((tfp = safe_fopen (mutt_b2s (tempfile), "w")) == NULL) { mutt_perror _("Failure to open file to strip headers."); goto bailout; @@ -187,7 +187,7 @@ int mutt_compose_attachment (BODY *a) safe_fclose (&fp); safe_fclose (&tfp); mutt_unlink (a->filename); - if (mutt_rename_file (tempfile, a->filename) != 0) + if (mutt_rename_file (mutt_b2s (tempfile), a->filename) != 0) { mutt_perror _("Failure to rename file."); goto bailout; @@ -201,18 +201,22 @@ int mutt_compose_attachment (BODY *a) } else { - rfc1524_free_entry (&entry); mutt_message (_("No mailcap compose entry for %s, creating empty file."), type); - return 1; + rc = 1; + goto bailout; } rc = 1; - - bailout: - + +bailout: + if(unlink_newfile) - unlink(newfile); + unlink(mutt_b2s (newfile)); + + mutt_buffer_pool_release (&command); + mutt_buffer_pool_release (&newfile); + mutt_buffer_pool_release (&tempfile); rfc1524_free_entry (&entry); return rc; diff --git a/rfc1524.c b/rfc1524.c index 87678bbf..311d5e05 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -595,7 +595,7 @@ int rfc1524_expand_filename (const char *nametemplate, * safe_fopen(). */ -int mutt_rename_file (char *oldfile, char *newfile) +int mutt_rename_file (const char *oldfile, const char *newfile) { FILE *ofp, *nfp; diff --git a/rfc1524.h b/rfc1524.h index a3f3a828..5c1bd6ed 100644 --- a/rfc1524.h +++ b/rfc1524.h @@ -39,7 +39,7 @@ void rfc1524_free_entry (rfc1524_entry **); int rfc1524_expand_command (BODY *, const char *, const char *, char *, int); int rfc1524_expand_filename (const char *, const char *, char *, size_t); int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int); -int mutt_rename_file (char *, char *); +int mutt_rename_file (const char *, const char *); /* Temporary BUFFER transition functions */