remove some mutt_mktemp
authorPierre Habouzit <madcoder@debian.org>
Fri, 24 Nov 2006 23:24:40 +0000 (00:24 +0100)
committerPierre Habouzit <madcoder@debian.org>
Fri, 24 Nov 2006 23:24:40 +0000 (00:24 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
16 files changed:
attach.c
commands.c
handler.c
headers.c
help.c
imap/imap.c
imap/message.c
lib-crypt/crypt.c
lib-mime/rfc3676.c
lib-mx/mbox.c
nntp/nntp.c
pattern.c
pop/pop.c
recvcmd.c
send.c
sendlib.c

index 9114d86..febe91e 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -450,9 +450,9 @@ int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr,
       /* recv case */
       m_strcpy(pagerfile, sizeof(pagerfile), a->filename);
       mutt_adv_mktemp (NULL, pagerfile, sizeof (pagerfile));
       /* recv case */
       m_strcpy(pagerfile, sizeof(pagerfile), a->filename);
       mutt_adv_mktemp (NULL, pagerfile, sizeof (pagerfile));
-    }
-    else
+    } else {
       mutt_mktemp (pagerfile);
       mutt_mktemp (pagerfile);
+    }
   }
 
   if (use_mailcap) {
   }
 
   if (use_mailcap) {
index 88d4a11..85ff46a 100644 (file)
@@ -55,11 +55,10 @@ int mutt_display_message (HEADER * cur)
   mutt_parse_mime_message (Context, cur);
   mutt_message_hook (Context, cur, M_MESSAGEHOOK);
 
   mutt_parse_mime_message (Context, cur);
   mutt_message_hook (Context, cur, M_MESSAGEHOOK);
 
-  mutt_mktemp (tempfile);
-  if ((fpout = safe_fopen (tempfile, "w")) == NULL) {
+  fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (!fpout) {
     mutt_error _("Could not create temporary file!");
     mutt_error _("Could not create temporary file!");
-
-    return (0);
+    return 0;
   }
 
   if (DisplayFilter && *DisplayFilter) {
   }
 
   if (DisplayFilter && *DisplayFilter) {
index e49d973..cc0a3c1 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1388,10 +1388,9 @@ int mutt_body_handler (BODY * b, STATE * s)
       if (!plaintext) {
         /* decode to a tempfile, saving the original destination */
         fp = s->fpout;
       if (!plaintext) {
         /* decode to a tempfile, saving the original destination */
         fp = s->fpout;
-        mutt_mktemp (tempfile);
-        if ((s->fpout = safe_fopen (tempfile, "w")) == NULL) {
+        s->fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+        if (!s->fpout) {
           mutt_error _("Unable to open temporary file!");
           mutt_error _("Unable to open temporary file!");
-
           goto bail;
         }
         /* decoding the attachment changes the size and offset, so save a copy
           goto bail;
         }
         /* decoding the attachment changes the size and offset, so save a copy
@@ -1407,9 +1406,9 @@ int mutt_body_handler (BODY * b, STATE * s)
         s->prefix = NULL;
 
         decode = 1;
         s->prefix = NULL;
 
         decode = 1;
-      }
-      else
+      } else {
         b->type = TYPETEXT;
         b->type = TYPETEXT;
+      }
 
       mutt_decode_attachment (b, s);
 
 
       mutt_decode_attachment (b, s);
 
index 2446041..f158c12 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -29,8 +29,8 @@ void mutt_edit_headers (const char *editor,
   struct stat st;
   string_list_t *cur, **last = NULL, *tmp;
 
   struct stat st;
   string_list_t *cur, **last = NULL, *tmp;
 
-  mutt_mktemp (path);
-  if ((ofp = safe_fopen (path, "w")) == NULL) {
+  ofp = m_tempfile(path, sizeof(path), NONULL(Tempdir), NULL);
+  if (!ofp) {
     mutt_perror (path);
     return;
   }
     mutt_perror (path);
     return;
   }
diff --git a/help.c b/help.c
index 0fa80c1..584e80b 100644 (file)
--- a/help.c
+++ b/help.c
@@ -272,43 +272,41 @@ static void dump_unbound (FILE * f,
 
 void mutt_help (int menu)
 {
 
 void mutt_help (int menu)
 {
-  char t[_POSIX_PATH_MAX];
-  char buf[SHORT_STRING];
-  const char *desc;
-  FILE *f;
-  struct binding_t *funcs;
-
-  mutt_mktemp (t);
-
-  funcs = km_get_table (menu);
-  desc = mutt_getnamebyvalue (menu, Menus);
-  if (!desc)
-    desc = _("<UNKNOWN>");
+    char tmp[_POSIX_PATH_MAX];
+    char buf[SHORT_STRING];
+    const char *desc;
+    FILE *f;
+    struct binding_t *funcs;
+
+    funcs = km_get_table (menu);
+    desc = mutt_getnamebyvalue (menu, Menus);
+    if (!desc)
+        desc = _("<UNKNOWN>");
+
+    do {
+        f = m_tempfile(tmp, sizeof(tmp), NONULL(Tempdir), NULL);
+        if (!f) {
+            mutt_perror(tmp);
+            return;
+        }
 
 
-  do {
-    if ((f = safe_fopen (t, "w")) == NULL) {
-      mutt_perror (t);
-      return;
-    }
+        dump_menu(f, menu);
+        if (menu != MENU_EDITOR && menu != MENU_PAGER) {
+            fputs(_("\nGeneric bindings:\n\n"), f);
+            dump_menu(f, MENU_GENERIC);
+        }
 
 
-    dump_menu (f, menu);
-    if (menu != MENU_EDITOR && menu != MENU_PAGER) {
-      fputs (_("\nGeneric bindings:\n\n"), f);
-      dump_menu (f, MENU_GENERIC);
-    }
+        fputs(_("\nUnbound functions:\n\n"), f);
+        if (funcs)
+            dump_unbound(f, funcs, Keymaps[menu], NULL);
 
 
-    fputs (_("\nUnbound functions:\n\n"), f);
-    if (funcs)
-      dump_unbound (f, funcs, Keymaps[menu], NULL);
-    if (menu != MENU_PAGER)
-      dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
+        if (menu != MENU_PAGER)
+            dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
 
 
-    fclose (f);
+        fclose(f);
 
 
-    snprintf (buf, sizeof (buf), _("Help for %s"), desc);
-  }
-  while
-    (mutt_do_pager (buf, t,
-                    M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP, NULL)
-     == OP_REFORMAT_WINCH);
+        snprintf(buf, sizeof (buf), _("Help for %s"), desc);
+    } while (mutt_do_pager(buf, tmp,
+                           M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP,
+                           NULL) == OP_REFORMAT_WINCH);
 }
 }
index 4b557fe..c214ddf 100644 (file)
@@ -1598,15 +1598,16 @@ static int imap_open_new_message (MESSAGE * msg,
                                   CONTEXT * dest __attribute__ ((unused)),
                                   HEADER * hdr __attribute__ ((unused)))
 {
                                   CONTEXT * dest __attribute__ ((unused)),
                                   HEADER * hdr __attribute__ ((unused)))
 {
-  char tmp[_POSIX_PATH_MAX];
+    char tmp[_POSIX_PATH_MAX];
 
 
-  mutt_mktemp (tmp);
-  if ((msg->fp = safe_fopen (tmp, "w")) == NULL) {
-    mutt_perror (tmp);
-    return (-1);
-  }
-  msg->path = m_strdup(tmp);
-  return 0;
+    msg->fp = m_tempfile(tmp, sizeof(tmp), NONULL(Tempdir), NULL);
+    if (!msg->fp) {
+        mutt_perror(tmp);
+        return -1;
+    }
+
+    msg->path = m_strdup(tmp);
+    return 0;
 }
 
 /* this ugly kludge is required since the last int to
 }
 
 /* this ugly kludge is required since the last int to
index 930f4d3..6c1fce7 100644 (file)
@@ -83,13 +83,13 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend)
 
   /* instead of downloading all headers and then parsing them, we parse them
    * as they come in. */
 
   /* instead of downloading all headers and then parsing them, we parse them
    * as they come in. */
-  mutt_mktemp (tempfile);
-  if (!(fp = safe_fopen (tempfile, "w+"))) {
-    mutt_error (_("Could not create temporary file %s"), tempfile);
-    mutt_sleep (2);
+  fp = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (!fp) {
+    mutt_error(_("Could not create temporary file"));
+    mutt_sleep(2);
     return -1;
   }
     return -1;
   }
-  unlink (tempfile);
+  unlink(tempfile);
 
   /* make sure context has room to hold the mailbox */
   while ((msgend) >= idata->ctx->hdrmax)
 
   /* make sure context has room to hold the mailbox */
   while ((msgend) >= idata->ctx->hdrmax)
@@ -376,12 +376,11 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
     mutt_message _("Fetching message...");
 
   cache->uid = HEADER_DATA (h)->uid;
     mutt_message _("Fetching message...");
 
   cache->uid = HEADER_DATA (h)->uid;
-  mutt_mktemp (path);
-  cache->path = m_strdup(path);
-  if (!(msg->fp = safe_fopen (path, "w+"))) {
-    p_delete(&cache->path);
+  msg->fp = m_tempfile(path, sizeof(path), NONULL(Tempdir), NULL);
+  if (!msg->fp) {
     return -1;
   }
     return -1;
   }
+  cache->path = m_strdup(path);
 
   /* mark this header as currently inactive so the command handler won't
    * also try to update it. HACK until all this code can be moved into the
 
   /* mark this header as currently inactive so the command handler won't
    * also try to update it. HACK until all this code can be moved into the
index f677789..b133add 100644 (file)
@@ -341,9 +341,9 @@ void crypt_extract_keys_from_messages (HEADER * h)
   address_t *tmp = NULL;
   FILE *fpout;
 
   address_t *tmp = NULL;
   FILE *fpout;
 
-  mutt_mktemp (tempfname);
-  if (!(fpout = safe_fopen (tempfname, "w"))) {
-    mutt_perror (tempfname);
+  fpout = m_tempfile(tempfname, sizeof(tempfname), NONULL(Tempdir), NULL);
+  if (!fpout) {
+    mutt_error(_("Could not create temporary file"));
     return;
   }
 
     return;
   }
 
index 404b02b..133fe3c 100644 (file)
@@ -224,13 +224,14 @@ void rfc3676_space_stuff (HEADER* hdr) {
 
   if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
     return;
 
   if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
     return;
-  mutt_mktemp (tmpf);
-  if ((out = safe_fopen (tmpf, "w+")) == NULL) {
-    fclose (in);
+
+  out = m_tempfile(tmpf, sizeof(tmpf), NONULL(Tempdir), NULL);
+  if (!out) {
+    fclose(in);
     return;
   }
 
     return;
   }
 
-  while (fgets (buf, sizeof (buf), in)) {
+  while (fgets(buf, sizeof (buf), in)) {
     if (m_strncmp("From ", buf, 4) == 0 || buf[0] == ' ') {
       fputc (' ', out);
     }
     if (m_strncmp("From ", buf, 4) == 0 || buf[0] == ' ') {
       fputc (' ', out);
     }
index 26b5580..14f00a9 100644 (file)
@@ -546,7 +546,7 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
     return (-1);
 
   /* Create a temporary file to write the new version of the mailbox in. */
     return (-1);
 
   /* Create a temporary file to write the new version of the mailbox in. */
-  fp = m_tempfile (tempfile, _POSIX_PATH_MAX, NONULL(Tempdir), NULL);
+  fp = m_tempfile(tempfile, _POSIX_PATH_MAX, NONULL(Tempdir), NULL);
   if (fp == NULL) {
     mutt_error _("Could not create temporary file!");
     mutt_sleep (5);
   if (fp == NULL) {
     mutt_error _("Could not create temporary file!");
     mutt_sleep (5);
@@ -610,7 +610,6 @@ static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused))
           unlink (tempfile);
           goto bail;
         }
           unlink (tempfile);
           goto bail;
         }
-
       }
 
       /* save the new offset for this message.  we add `offset' because the
       }
 
       /* save the new offset for this message.  we add `offset' because the
index 2141454..a2388d9 100644 (file)
@@ -437,8 +437,8 @@ static int nntp_read_header (CONTEXT * ctx, const char *msgid,
   int ret;
   HEADER *h = ctx->hdrs[ctx->msgcount];
 
   int ret;
   HEADER *h = ctx->hdrs[ctx->msgcount];
 
-  mutt_mktemp (tempfile);
-  if (!(f = safe_fopen (tempfile, "w+")))
+  f = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (!f)
     return -1;
 
   if (!msgid)
     return -1;
 
   if (!msgid)
@@ -915,12 +915,11 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   p_delete(&cache->path);
 
   cache->index = ctx->hdrs[msgno]->index;
   p_delete(&cache->path);
 
   cache->index = ctx->hdrs[msgno]->index;
-  mutt_mktemp (path);
-  cache->path = m_strdup(path);
-  if (!(msg->fp = safe_fopen (path, "w+"))) {
-    p_delete(&cache->path);
+  msg->fp = m_tempfile(path, sizeof(path), NONULL(Tempdir), NULL);
+  if (!msg->fp) {
     return -1;
   }
     return -1;
   }
+  cache->path = m_strdup(path);
 
   if (ctx->hdrs[msgno]->article_num == 0)
     snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
 
   if (ctx->hdrs[msgno]->article_num == 0)
     snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
index 3233a92..c8dff19 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -133,9 +133,9 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
       p_clear(&s, 1);
       s.fpin = msg->fp;
       s.flags = M_CHARCONV;
       p_clear(&s, 1);
       s.fpin = msg->fp;
       s.flags = M_CHARCONV;
-      mutt_mktemp (tempfile);
-      if ((s.fpout = safe_fopen (tempfile, "w+")) == NULL) {
-        mutt_perror (tempfile);
+      s.fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+      if (!s.fpout) {
+        mutt_error(_("Could not create temporary file"));
         return (0);
       }
 
         return (0);
       }
 
index 3f3ee0f..be2d105 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -45,9 +45,9 @@ static pop_query_status pop_read_header (POP_DATA * pop_data, HEADER * h)
   char buf[LONG_STRING];
   char tempfile[_POSIX_PATH_MAX];
 
   char buf[LONG_STRING];
   char tempfile[_POSIX_PATH_MAX];
 
-  mutt_mktemp (tempfile);
-  if (!(f = safe_fopen (tempfile, "w+"))) {
-    mutt_perror (tempfile);
+  f = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (!f) {
+    mutt_error(_("Could not create temporary file"));
     return PFD_FUNCT_ERROR;
   }
 
     return PFD_FUNCT_ERROR;
   }
 
@@ -349,11 +349,10 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
     bar.msg = _("Fetching message...");
     mutt_progress_bar (&bar, 0);
 
     bar.msg = _("Fetching message...");
     mutt_progress_bar (&bar, 0);
 
-    mutt_mktemp (path);
-    msg->fp = safe_fopen (path, "w+");
+    msg->fp = m_tempfile(path, sizeof(path), NONULL(Tempdir), NULL);
     if (!msg->fp) {
     if (!msg->fp) {
-      mutt_perror (path);
-      mutt_sleep (2);
+      mutt_error(_("Could not create temporary file"));
+      mutt_sleep(2);
       return -1;
     }
 
       return -1;
     }
 
index cf0aa4f..a8e4b6b 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -443,9 +443,9 @@ static void attach_forward_bodies (FILE * fp, HEADER * hdr,
   tmphdr->env = envelope_new();
   mutt_make_forward_subject (tmphdr->env, Context, parent);
 
   tmphdr->env = envelope_new();
   mutt_make_forward_subject (tmphdr->env, Context, parent);
 
-  mutt_mktemp (tmpbody);
-  if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) {
-    mutt_error (_("Can't open temporary file %s."), tmpbody);
+  tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(Tempdir), NULL);
+  if (!tmpfp) {
+    mutt_error(_("Could not create temporary file"));
     return;
   }
 
     return;
   }
 
@@ -611,9 +611,9 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr __attribute__ ((unused)
 
     /* no MIME encapsulation */
 
 
     /* no MIME encapsulation */
 
-    mutt_mktemp (tmpbody);
-    if (!(tmpfp = safe_fopen (tmpbody, "w"))) {
-      mutt_error (_("Can't create %s."), tmpbody);
+    tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(Tempdir), NULL);
+    if (!tmpfp) {
+      mutt_error(_("Could not create temporary file"));
       header_delete(&tmphdr);
       return;
     }
       header_delete(&tmphdr);
       return;
     }
@@ -859,9 +859,9 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr,
     return;
   }
 
     return;
   }
 
-  mutt_mktemp (tmpbody);
-  if ((tmpfp = safe_fopen (tmpbody, "w")) == NULL) {
-    mutt_error (_("Can't create %s."), tmpbody);
+  tmpfp = m_tempfile(tmpbody, sizeof(tmpbody), NONULL(Tempdir), NULL);
+  if (!tmpfp) {
+    mutt_error(_("Could not create temporary file"));
     header_delete(&tmphdr);
     return;
   }
     header_delete(&tmphdr);
     return;
   }
diff --git a/send.c b/send.c
index 736e0c0..ce83c0c 100644 (file)
--- a/send.c
+++ b/send.c
@@ -971,9 +971,9 @@ static int send_message (HEADER * msg)
   int i;
 
   /* Write out the message in MIME form. */
   int i;
 
   /* Write out the message in MIME form. */
-  mutt_mktemp (tempfile);
-  if ((tempfp = safe_fopen (tempfile, "w")) == NULL)
-    return (-1);
+  tempfp = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (!tempfp)
+    return -1;
 
 #ifdef MIXMASTER
   mutt_write_rfc822_header (tempfp, msg->env, msg->content, 0,
 
 #ifdef MIXMASTER
   mutt_write_rfc822_header (tempfp, msg->env, msg->content, 0,
@@ -1065,7 +1065,6 @@ int ci_send_message (int flags, /* send mode */
                      CONTEXT * ctx,     /* current mailbox */
                      HEADER * cur)
 {                               /* current message */
                      CONTEXT * ctx,     /* current mailbox */
                      HEADER * cur)
 {                               /* current message */
-  char buffer[LONG_STRING];
   char fcc[_POSIX_PATH_MAX] = "";       /* where to copy this message */
   FILE *tempfp = NULL;
   BODY *pbody;
   char fcc[_POSIX_PATH_MAX] = "";       /* where to copy this message */
   FILE *tempfp = NULL;
   BODY *pbody;
@@ -1177,12 +1176,11 @@ int ci_send_message (int flags, /* send mode */
     }
 
     if (!tempfile) {
     }
 
     if (!tempfile) {
-      mutt_mktemp (buffer);
-      tempfp = safe_fopen (buffer, "w+");
+      char buffer[_POSIX_PATH_MAX];
+      tempfp = m_tempfile(buffer, sizeof(buffer), NONULL(Tempdir), NULL);
       msg->content->filename = m_strdup(buffer);
       msg->content->filename = m_strdup(buffer);
-    }
-    else {
-      tempfp = safe_fopen (tempfile, "a+");
+    } else {
+      tempfp = safe_fopen(tempfile, "a+");
       msg->content->filename = m_strdup(tempfile);
     }
 
       msg->content->filename = m_strdup(tempfile);
     }
 
index c406c38..042ca3a 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -923,9 +923,9 @@ void mutt_message_to_7bit (BODY * a, FILE * fp)
     a->length = sb.st_size;
   }
 
     a->length = sb.st_size;
   }
 
-  mutt_mktemp (temp);
-  if (!(fpout = safe_fopen (temp, "w+"))) {
-    mutt_perror ("fopen");
+  fpout = m_tempfile(temp, sizeof(temp), NONULL(Tempdir), NULL);
+  if (!fpout) {
+    mutt_error(_("Could not create temporary file"));
     goto cleanup;
   }
 
     goto cleanup;
   }
 
@@ -988,9 +988,9 @@ static void transform_to_7bit (BODY * a, FILE * fpin)
       a->noconv = 1;
       a->force_charset = 1;
 
       a->noconv = 1;
       a->force_charset = 1;
 
-      mutt_mktemp (buff);
-      if ((s.fpout = safe_fopen (buff, "w")) == NULL) {
-        mutt_perror ("fopen");
+      s.fpout = m_tempfile(buff, sizeof(buff), NONULL(Tempdir), NULL);
+      if (!s.fpout) {
+        mutt_error(_("Could not create temporary file"));
         return;
       }
       s.fpin = fpin;
         return;
       }
       s.fpin = fpin;
@@ -2068,8 +2068,8 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to,
   if (!fp)
     fp = msg->fp;
 
   if (!fp)
     fp = msg->fp;
 
-  mutt_mktemp (tempfile);
-  if ((f = safe_fopen (tempfile, "w")) != NULL) {
+  f = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  if (f) {
     int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
 
     if (!option (OPTBOUNCEDELIVERED))
     int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
 
     if (!option (OPTBOUNCEDELIVERED))
@@ -2087,8 +2087,8 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to,
     mutt_copy_bytes (fp, f, h->content->length);
     fclose (f);
 
     mutt_copy_bytes (fp, f, h->content->length);
     fclose (f);
 
-    ret = mutt_invoke_mta (env_from, to, NULL, NULL, tempfile,
-                           h->content->encoding == ENC8BIT);
+    ret = mutt_invoke_mta(env_from, to, NULL, NULL, tempfile,
+                          h->content->encoding == ENC8BIT);
   }
 
   if (msg)
   }
 
   if (msg)
@@ -2160,11 +2160,11 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid,
    * the message body begins with "From "   
    */
   if (f.magic == M_MMDF || f.magic == M_MBOX) {
    * the message body begins with "From "   
    */
   if (f.magic == M_MMDF || f.magic == M_MBOX) {
-    mutt_mktemp (tempfile);
-    if ((tempfp = safe_fopen (tempfile, "w+")) == NULL) {
-      mutt_perror (tempfile);
+    tempfp = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+    if (!tempfp) {
+      mutt_error(_("Could not create temporary file"));
       mx_close_mailbox (&f, NULL);
       mx_close_mailbox (&f, NULL);
-      return (-1);
+      return -1;
     }
   }
 
     }
   }