summaryrefslogtreecommitdiffstats
path: root/attach.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2018-10-14 12:52:30 -0700
committerKevin McCarthy <kevin@8t8.us>2018-10-15 13:57:50 -0700
commitc619d5cbc428de3632c55bac2e79c7b06d6a030a (patch)
tree32a33f32f1b793930ba4392c281a80e74682b9a5 /attach.c
parent57caae48aac7f3428df58a3754aa990841e6fc96 (diff)
Convert mutt_get_tmp_attachment to use BUFFER.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/attach.c b/attach.c
index 2a2661f4..89574f50 100644
--- a/attach.c
+++ b/attach.c
@@ -46,38 +46,46 @@
int mutt_get_tmp_attachment (BODY *a)
{
char type[STRING];
- char tempfile[_POSIX_PATH_MAX];
- rfc1524_entry *entry = rfc1524_new_entry();
+ BUFFER *tempfile = NULL;
+ rfc1524_entry *entry = NULL;
FILE *fpin = NULL, *fpout = NULL;
struct stat st;
if(a->unlink)
return 0;
+ tempfile = mutt_buffer_pool_get ();
+ entry = rfc1524_new_entry();
+
snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype);
rfc1524_mailcap_lookup(a, type, entry, 0);
- rfc1524_expand_filename(entry->nametemplate, a->filename,
- tempfile, sizeof(tempfile));
-
+ mutt_buffer_rfc1524_expand_filename (entry->nametemplate, a->filename, tempfile);
+
rfc1524_free_entry(&entry);
if(stat(a->filename, &st) == -1)
+ {
+ mutt_buffer_pool_release (&tempfile);
return -1;
+ }
- if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w"))) /* __FOPEN_CHECKED__ */
+ if((fpin = fopen(a->filename, "r")) && /* __FOPEN_CHECKED__ */
+ (fpout = safe_fopen(mutt_b2s (tempfile), "w")))
{
mutt_copy_stream (fpin, fpout);
- mutt_str_replace (&a->filename, tempfile);
+ mutt_str_replace (&a->filename, mutt_b2s (tempfile));
a->unlink = 1;
if(a->stamp >= st.st_mtime)
mutt_stamp_attachment(a);
}
else
- mutt_perror(fpin ? tempfile : a->filename);
+ mutt_perror(fpin ? mutt_b2s (tempfile) : a->filename);
if(fpin) safe_fclose (&fpin);
if(fpout) safe_fclose (&fpout);
+
+ mutt_buffer_pool_release (&tempfile);
return a->unlink ? 0 : -1;
}