Use m_tempfile and better errors msg
[apps/madmutt.git] / pattern.c
index 26b8375..1eee48c 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -7,28 +7,16 @@
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdarg.h>
-
 #include <lib-lib/lib-lib.h>
 
 #include <lib-mime/mime.h>
-
 #include <lib-ui/enter.h>
 #include <lib-ui/curses.h>
+#include <lib-mx/mx.h>
 
 #include "mutt.h"
 #include "alias.h"
 #include "handler.h"
-#include "mx.h"
 #include "keymap.h"
 #include "copy.h"
 
@@ -145,9 +133,9 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
       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);
       }
 
@@ -161,7 +149,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
         {
           mx_close_message (&msg);
           if (fp) {
-            fclose (fp);
+            m_fclose(&fp);
             unlink (tempfile);
           }
           return (0);
@@ -212,7 +200,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
     mx_close_message (&msg);
 
     if (option (OPTTHOROUGHSRC)) {
-      fclose (fp);
+      m_fclose(&fp);
       unlink (tempfile);
     }
   }
@@ -1153,7 +1141,7 @@ void mutt_check_simple (char *s, ssize_t len, const char *simple)
       m_strcpy(s, len, "~U");
     else {
       quote_simple (tmp, sizeof (tmp), s);
-      mutt_expand_fmt (s, len, simple, tmp);
+      m_file_fmt(s, len, simple, tmp);
     }
   }
 }