]> granicus.if.org Git - mutt/commitdiff
Convert mutt_get_tmp_attachment to use BUFFER.
authorKevin McCarthy <kevin@8t8.us>
Sun, 14 Oct 2018 19:52:30 +0000 (12:52 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 15 Oct 2018 20:57:50 +0000 (13:57 -0700)
attach.c

index 2a2661f4c32fed2b50e47ebda7c47b45d652713b..89574f5009ae6c570383c4ab0246d0908fd0243b 100644 (file)
--- a/attach.c
+++ b/attach.c
 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;
 }