summaryrefslogtreecommitdiffstats
path: root/attach.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2018-10-14 16:18:53 -0700
committerKevin McCarthy <kevin@8t8.us>2018-10-15 13:57:50 -0700
commitffdf38d78d6d230b7045d48581c347c5b327e378 (patch)
treecd946af4672499d636b2cd91a3f5b806f13efbcb /attach.c
parentc619d5cbc428de3632c55bac2e79c7b06d6a030a (diff)
Convert mutt_compose_attachment to use BUFFER.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c54
1 files changed, 29 insertions, 25 deletions
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;