oops, I did it again: simplify a lot of code :]
[apps/madmutt.git] / lib-mime / rfc1524.c
index c2c8058..5b6eb50 100644 (file)
  * rfc1524.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
+#include <lib-lib/lib-lib.h>
 
 #include <lib-sys/unix.h>
 
 #include "mime.h"
 #include "attach.h"
 
+void rfc1524_entry_wipe(rfc1524_entry *p)
+{
+    p_delete(&p->command);
+    p_delete(&p->testcommand);
+    p_delete(&p->composecommand);
+    p_delete(&p->composetypecommand);
+    p_delete(&p->editcommand);
+    p_delete(&p->printcommand);
+    p_delete(&p->nametemplate);
+    p_delete(&p->convert);
+}
+
+/* returns 1 if Mutt can't display this type of data, 0 otherwise */
+int rfc1524_mailcap_isneeded(BODY * m)
+{
+    int tok;
+
+    switch (m->type) {
+      case TYPEMULTIPART:
+      case TYPEMESSAGE:
+        return 0;
+
+      case TYPEAPPLICATION:
+        return !(mutt_is_application_pgp(m) || mutt_is_application_smime(m));
+
+      case TYPETEXT:
+        tok = mime_which_token(m->subtype, -1);
+        if (tok == MIME_PLAIN
+        ||  tok == MIME_RFC822_HEADERS
+        ||  tok == MIME_ENRICHED)
+            return 0;
+        break;
+    }
+
+    return 1;
+}
+
 /* The command semantics include the following:
  * %s is the filename that contains the mail body data
  * %t is the content type, like text/plain
@@ -106,7 +126,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype,
                 param[z] = '\0';
 
                 m_strcpy(pval, sizeof(pval),
-                         mutt_get_parameter(param, a->parameter));
+                         parameter_getval(a->parameter, param));
 
                 if (option(OPTMAILCAPSANITIZE))
                     mutt_sanitize_filename(pval, 0);
@@ -281,7 +301,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type,
                     ssize_t len   = m_strlen(value) + STRING;
                     char *testcmd = p_new(char, len);
 
-                    strcpy(testcmd, value);
+                    m_strcpy(testcmd, len, value);
                     rfc1524_expand_command(a, a->filename, type, testcmd, len);
                     found = !mutt_system(testcmd);
                     p_delete(&testcmd);
@@ -318,7 +338,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type,
             rfc1524_entry_init(entry);
         }
     }                           /* while (!found && (buf = mutt_read_line ())) */
-    fclose (fp);
+    m_fclose(&fp);
 
   error:
     p_delete(&buf);
@@ -354,7 +374,7 @@ int rfc1524_mailcap_lookup (BODY * a, char *type, rfc1524_entry * entry,
     return 0;
   }
 
-  mutt_check_lookup_list (a, type, SHORT_STRING);
+  mutt_check_lookup_list (a, type, STRING);
 
   while (!found && *curr) {
     x = 0;
@@ -417,9 +437,8 @@ int rfc1524_expand_filename (char *nametemplate,
       m_strcpy(newfile, nflen, oldfile);
   }
   else if (!oldfile) {
-    mutt_expand_fmt (newfile, nflen, nametemplate, "mutt");
-  }
-  else {                        /* oldfile && nametemplate */
+    m_file_fmt(newfile, nflen, nametemplate, "mutt");
+  } else {                        /* oldfile && nametemplate */
 
 
     /* first, compare everything left from the "%s"