Use m_tempfile instead of mktemp in attach/recvattach
[apps/madmutt.git] / recvattach.c
index 6c7956a..94ef9ab 100644 (file)
@@ -490,6 +490,7 @@ mutt_query_pipe_attachment (char *command, FILE * fp, BODY * body, int afilter)
 {
   char tfile[_POSIX_PATH_MAX];
   char warning[STRING + _POSIX_PATH_MAX];
+  int tempfd;
 
   if (afilter) {
     snprintf (warning, sizeof (warning),
@@ -499,20 +500,18 @@ mutt_query_pipe_attachment (char *command, FILE * fp, BODY * body, int afilter)
       CLEARLINE (LINES - 1);
       return;
     }
-    mutt_mktemp (tfile);
-  } else {
-    tfile[0] = '\0';
+    tempfd = m_tempfd(tfile, sizeof(tfile), NONULL(Tempdir), NULL);
   }
 
-  if (mutt_pipe_attachment (fp, body, command, tfile)) {
+  if (mutt_pipe_attachment (fp, body, command, tempfd)) {
     if (afilter) {
       mutt_unlink (body->filename);
       mutt_rename_file (tfile, body->filename);
       mutt_update_encoding (body);
       mutt_message _("Attachment filtered.");
     }
-  } else {
-    if (afilter && tfile[0])
+  } else if (afilter) {
+      close(tempfd);
       mutt_unlink (tfile);
   }
 }