Use m_tempfile and better errors msg
[apps/madmutt.git] / postpone.c
index 9b4e0a6..5fda6ce 100644 (file)
@@ -8,31 +8,24 @@
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/stat.h>
-
 #include <lib-lib/lib-lib.h>
 
 #include <lib-mime/mime.h>
 
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
+#include <lib-ui/curses.h>
+#include <lib-mx/mx.h>
+
+#include <lib-sys/unix.h>
 
 #include "mutt.h"
 #include "handler.h"
 #include "sort.h"
 #include "thread.h"
-#include "mx.h"
 #include <lib-crypt/crypt.h>
 
 #include <imap/imap.h>
-#include <imap/mx_imap.h>
 
 static struct mapping_t PostponeHelp[] = {
   {N_("Exit"),  OP_EXIT},
@@ -611,11 +604,10 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
       parameter_delval(&b->parameter, "x-mutt-noconv");
     }
 
-    mutt_adv_mktemp (NULL, file, sizeof (file));
-    if ((s.fpout = safe_fopen (file, "w")) == NULL)
+    s.fpout = m_tempfile(file, sizeof(file), NONULL(Tempdir), file);
+    if (!s.fpout)
       goto bail;
 
-
     if (mutt_is_application_pgp (b) & (ENCRYPT | SIGN)) {
 
       mutt_body_handler (b, &s);
@@ -629,7 +621,7 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
     else
       mutt_decode_attachment (b, &s);
 
-    if (safe_fclose (&s.fpout) != 0)
+    if (m_fclose(&s.fpout) != 0)
       goto bail;
 
     m_strreplace(&b->filename, file);
@@ -663,7 +655,7 @@ bail:
 
   /* that's it. */
   if (bfp != fp)
-    fclose (bfp);
+    m_fclose(&bfp);
   if (msg)
     mx_close_message (&msg);