]> granicus.if.org Git - neomutt/commitdiff
Convert remaining mutt_adv_mktemp() calls to use buffer version
authorKevin McCarthy <kevin@8t8.us>
Sun, 14 Apr 2019 16:20:46 +0000 (09:20 -0700)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Apr 2019 16:45:37 +0000 (17:45 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
mutt_body.c
postpone.c

index fb9943f74b760006323027d517dc1e4ab2f2a311..9a77875331be43aa89f71d9033b6df7dda9c2cc2 100644 (file)
@@ -50,25 +50,26 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src)
   if (!tgt || !src)
     return -1;
 
-  char tmp[PATH_MAX];
   struct Body *b = NULL;
-
   bool use_disp;
+  struct Buffer *tmp = mutt_buffer_pool_get();
 
   if (src->filename)
   {
     use_disp = true;
-    mutt_str_strfcpy(tmp, src->filename, sizeof(tmp));
+    mutt_buffer_strcpy(tmp, src->filename);
   }
   else
   {
     use_disp = false;
-    tmp[0] = '\0';
   }
 
-  mutt_adv_mktemp(tmp, sizeof(tmp));
-  if (mutt_save_attachment(fp, src, tmp, MUTT_SAVE_NO_FLAGS, NULL) == -1)
+  mutt_buffer_adv_mktemp(tmp);
+  if (mutt_save_attachment(fp, src, mutt_b2s(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
+  {
+    mutt_buffer_pool_release(&tmp);
     return -1;
+  }
 
   *tgt = mutt_body_new();
   b = *tgt;
@@ -78,7 +79,7 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src)
   b->parts = NULL;
   b->next = NULL;
 
-  b->filename = mutt_str_strdup(tmp);
+  b->filename = mutt_str_strdup(mutt_b2s(tmp));
   b->use_disp = use_disp;
   b->unlink = true;
 
@@ -112,6 +113,6 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src)
   }
 
   mutt_stamp_attachment(b);
-
+  mutt_buffer_pool_release(&tmp);
   return 0;
 }
index a0007bd9804c4d52ebdd414223ef50e27c2139f9..f5e69202851f4d632ad1696fbe2b3afd51a17b41 100644 (file)
@@ -581,7 +581,6 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr,
                           struct Email *e, bool resend)
 {
   struct Message *msg = NULL;
-  char file[PATH_MAX];
   struct Body *b = NULL;
   FILE *fp_body = NULL;
   int rc = -1;
@@ -680,16 +679,18 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr,
 
   s.fp_in = fp_body;
 
+  struct Buffer *file = mutt_buffer_pool_get();
+
   /* create temporary files for all attachments */
   for (b = newhdr->content; b; b = b->next)
   {
     /* what follows is roughly a receive-mode variant of
      * mutt_get_tmp_attachment () from muttlib.c */
 
-    file[0] = '\0';
+    mutt_buffer_reset(file);
     if (b->filename)
     {
-      mutt_str_strfcpy(file, b->filename, sizeof(file));
+      mutt_buffer_strcpy(file, b->filename);
       b->d_filename = mutt_str_strdup(b->filename);
     }
     else
@@ -718,8 +719,8 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr,
       mutt_param_delete(&b->parameter, "x-mutt-noconv");
     }
 
-    mutt_adv_mktemp(file, sizeof(file));
-    s.fp_out = mutt_file_fopen(file, "w");
+    mutt_buffer_adv_mktemp(file);
+    s.fp_out = mutt_file_fopen(mutt_b2s(file), "w");
     if (!s.fp_out)
       goto bail;
 
@@ -777,7 +778,7 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr,
     if (mutt_file_fclose(&s.fp_out) != 0)
       goto bail;
 
-    mutt_str_replace(&b->filename, file);
+    mutt_str_replace(&b->filename, mutt_b2s(file));
     b->unlink = true;
 
     mutt_stamp_attachment(b);
@@ -817,6 +818,7 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr,
 bail:
 
   /* that's it. */
+  mutt_buffer_pool_release(&file);
   if (fp_body != fp)
     mutt_file_fclose(&fp_body);
   if (msg)