Commit ffdf38d7 authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Convert mutt_compose_attachment to use BUFFER.

parent c619d5cb
......@@ -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;
......
......@@ -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;
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment