simplify some mime things
authorPierre Habouzit <madcoder@debian.org>
Fri, 30 Mar 2007 22:40:22 +0000 (00:40 +0200)
committerPierre Habouzit <madcoder@debian.org>
Fri, 30 Mar 2007 22:40:22 +0000 (00:40 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
globals.h
init.c
init.h
lib-lua/lua-token.sh
lib-mime/Makefile.am
lib-mime/mime.cpkg
lib-mime/rfc1524.c
mutt.h

index 310479b..921a8bf 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -49,7 +49,6 @@ WHERE char *ImapUser INITVAL (NULL);
 WHERE char *Inbox;
 WHERE char *Ispell;
 WHERE char *Locale;
 WHERE char *Inbox;
 WHERE char *Ispell;
 WHERE char *Locale;
-WHERE char *MailcapPath;
 WHERE char *Maildir;
 
 #ifdef USE_HCACHE
 WHERE char *Maildir;
 
 #ifdef USE_HCACHE
diff --git a/init.c b/init.c
index 8ac9bba..a897897 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1935,15 +1935,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     Spoolfile = m_strdup(buffer);
   }
 
     Spoolfile = m_strdup(buffer);
   }
 
-  if ((p = getenv ("MAILCAPS")))
-    MailcapPath = m_strdup(p);
-  else {
-    /* Default search path from RFC1524 */
-    MailcapPath =
-      m_strdup("~/.mailcap:" PKGDATADIR "/mailcap:" SYSCONFDIR
-                   "/mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap");
-  }
-
   if ((p = getenv ("REPLYTO")) != NULL) {
     BUFFER buf, token;
 
   if ((p = getenv ("REPLYTO")) != NULL) {
     BUFFER buf, token;
 
diff --git a/init.h b/init.h
index c3943fa..95c5285 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1105,22 +1105,6 @@ struct option_t MuttVars[] = {
    ** .pp
    ** \fBNote:\fP This does not apply to IMAP mailboxes, see $$imap_mail_check.
    */
    ** .pp
    ** \fBNote:\fP This does not apply to IMAP mailboxes, see $$imap_mail_check.
    */
-  {"mailcap_path", DT_STR, R_NONE, UL &MailcapPath, "" },
-  /*
-   ** .pp
-   ** This variable specifies which files to consult when attempting to
-   ** display MIME bodies not directly supported by Madmutt.
-   */
-  {"mailcap_sanitize", DT_BOOL, R_NONE, OPTMAILCAPSANITIZE, "yes" },
-  /*
-   ** .pp
-   ** If \fIset\fP, Madmutt will restrict possible characters in mailcap \fT%\fP expandos
-   ** to a well-defined set of safe characters.  This is the safe setting,
-   ** but we are not sure it doesn't break some more advanced MIME stuff.
-   ** .pp
-   ** \fBDON'T CHANGE THIS SETTING UNLESS YOU ARE REALLY SURE WHAT YOU ARE
-   ** DOING!\fP
-   */
 #ifdef USE_HCACHE
   {"header_cache", DT_PATH, R_NONE, UL &HeaderCache, "" },
   /*
 #ifdef USE_HCACHE
   {"header_cache", DT_PATH, R_NONE, UL &HeaderCache, "" },
   /*
index 9ca1422..6600270 100644 (file)
@@ -130,6 +130,8 @@ exit 0
 ## hcache_backend
 ## homedir
 ## hostname
 ## hcache_backend
 ## homedir
 ## hostname
+## mailcap_path
+## mailcap_sanitize
 ## no
 ## quit
 ## send_charset
 ## no
 ## quit
 ## send_charset
index b47ba4c..c976c05 100644 (file)
@@ -15,5 +15,9 @@ noinst_HEADERS    = mime.h mime-types.h
 mime-token.c mime-token.h: mime-token.def mime-token.sh
        sh mime-token.sh $@ < $<
 
 mime-token.c mime-token.h: mime-token.def mime-token.sh
        sh mime-token.sh $@ < $<
 
+DEFS=-DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
+       -DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \
+       -DHAVE_CONFIG_H=1 -DPKGDOCDIR=\"$(docdir)\"
+
 include $(top_builddir)/tools/cpkg2c.mk
 -include $(top_builddir)/tools/cflags.mk
 include $(top_builddir)/tools/cpkg2c.mk
 -include $(top_builddir)/tools/cflags.mk
index 7c74059..332bc1f 100644 (file)
@@ -54,6 +54,15 @@ const char *BodyEncodings[] = {
 
 rx_t *SpamList = NULL, *NoSpamList = NULL;
 
 
 rx_t *SpamList = NULL, *NoSpamList = NULL;
 
+static char *mailcap_init(void)
+{
+    /* Default search path from RFC1524 */
+    const char *path = "~/.mailcap:" PKGDATADIR "/mailcap:"
+        SYSCONFDIR "/mailcap:/etc/mailcap:"
+        "/usr/etc/mailcap:/usr/local/etc/mailcap";
+    return m_strdup(getenv("MAILCAPS") ?: path);
+}
+
 @package Mime {
     /*
      ** .pp
 @package Mime {
     /*
      ** .pp
@@ -65,6 +74,24 @@ rx_t *SpamList = NULL, *NoSpamList = NULL;
      */
     string_t spam_separator = m_strdup(",");
 
      */
     string_t spam_separator = m_strdup(",");
 
+    /*
+     ** .pp
+     ** This variable specifies which files to consult when attempting to
+     ** display MIME bodies not directly supported by Madmutt.
+     */
+    string_t mailcap_path   = mailcap_init();
+
+    /*
+     ** .pp
+     ** If \fIset\fP, Madmutt will restrict possible characters in mailcap \fT%\fP expandos
+     ** to a well-defined set of safe characters.  This is the safe setting,
+     ** but we are not sure it doesn't break some more advanced MIME stuff.
+     ** .pp
+     ** \fBDON'T CHANGE THIS SETTING UNLESS YOU ARE REALLY SURE WHAT YOU ARE
+     ** DOING!\fP
+     */
+    bool mailcap_sanitize   = 1;
+
     void spam(rx_t rx, const string_t tpl) {
         rx_set_template(rx, tpl);
         rx_list_remove(&NoSpamList, rx);
     void spam(rx_t rx, const string_t tpl) {
         rx_set_template(rx, tpl);
         rx_list_remove(&NoSpamList, rx);
index fdbf182..7f6ceb3 100644 (file)
@@ -58,8 +58,6 @@ void rfc1524_entry_wipe(rfc1524_entry *p)
 /* returns 1 if Mutt can't display this type of data, 0 otherwise */
 int rfc1524_mailcap_isneeded(BODY * m)
 {
 /* 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:
     switch (m->type) {
       case TYPEMULTIPART:
       case TYPEMESSAGE:
@@ -69,15 +67,17 @@ int rfc1524_mailcap_isneeded(BODY * m)
         return !(mutt_is_application_pgp(m) || mutt_is_application_smime(m));
 
       case TYPETEXT:
         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)
+        switch (mime_which_token(m->subtype, -1)) {
+          case MIME_PLAIN:
+          case MIME_RFC822_HEADERS:
+          case MIME_ENRICHED:
             return 0;
             return 0;
-        break;
+          default:
+            return 1;
+        }
+      default:
+        return 1;
     }
     }
-
-    return 1;
 }
 
 /* The command semantics include the following:
 }
 
 /* The command semantics include the following:
@@ -103,7 +103,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype,
 
     m_strcpy(type, sizeof(type), mtype);
 
 
     m_strcpy(type, sizeof(type), mtype);
 
-    if (option(OPTMAILCAPSANITIZE))
+    if (Mime.mailcap_sanitize)
         mutt_sanitize_filename(type, 0);
 
     while (command[x] && x < clen && y < ssizeof(buf)) {
         mutt_sanitize_filename(type, 0);
 
     while (command[x] && x < clen && y < ssizeof(buf)) {
@@ -128,7 +128,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype,
                 m_strcpy(pval, sizeof(pval),
                          parameter_getval(a->parameter, param));
 
                 m_strcpy(pval, sizeof(pval),
                          parameter_getval(a->parameter, param));
 
-                if (option(OPTMAILCAPSANITIZE))
+                if (Mime.mailcap_sanitize)
                     mutt_sanitize_filename(pval, 0);
 
                 y += mutt_quote_filename(buf + y, sizeof(buf) - y, pval);
                     mutt_sanitize_filename(pval, 0);
 
                 y += mutt_quote_filename(buf + y, sizeof(buf) - y, pval);
@@ -346,60 +346,46 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type,
 }
 
 
 }
 
 
-/************** READ MARK **********************/
-
 /*
  * rfc1524_mailcap_lookup attempts to find the given type in the
  * list of mailcap files.  On success, this returns the entry information
  * in *entry, and returns 1.  On failure (not found), returns 0.
  * If entry == NULL just return 1 if the given type is found.
  */
 /*
  * rfc1524_mailcap_lookup attempts to find the given type in the
  * list of mailcap files.  On success, this returns the entry information
  * in *entry, and returns 1.  On failure (not found), returns 0.
  * If entry == NULL just return 1 if the given type is found.
  */
-int rfc1524_mailcap_lookup (BODY * a, char *type, rfc1524_entry * entry,
-                            int opt)
+int rfc1524_mailcap_lookup(BODY *a, char *type, rfc1524_entry *entry, int opt)
 {
 {
-  char path[_POSIX_PATH_MAX];
-  int x;
-  int found = FALSE;
-  char *curr = MailcapPath;
-
-  /* rfc1524 specifies that a path of mailcap files should be searched.
-   * joy.  They say 
-   * $HOME/.mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap, etc
-   * and overriden by the MAILCAPS environment variable, and, just to be nice, 
-   * we'll make it specifiable in .muttrc
-   */
-  if (!curr || !*curr) {
-    mutt_error _("No mailcap path specified");
+    const char *p = Mime.mailcap_path;
 
 
-    return 0;
-  }
+    mutt_check_lookup_list(a, type, STRING);
 
 
-  mutt_check_lookup_list (a, type, STRING);
+    for (;;) {
+        const char *q;
+        char path[_POSIX_PATH_MAX];
 
 
-  while (!found && *curr) {
-    x = 0;
-    while (*curr && *curr != ':' && x < ssizeof (path) - 1) {
-      path[x++] = *curr;
-      curr++;
-    }
-    if (*curr)
-      curr++;
+        while (*p == ':')
+            p++;
 
 
-    if (!x)
-      continue;
+        if (!*p)
+            break;
 
 
-    path[x] = '\0';
-    mutt_expand_path(path, sizeof(path));
+        q = strchrnul(p, ':');
+        m_strncpy(path, sizeof(path), p, q - p);
+        mutt_expand_path(path, sizeof(path));
 
 
-    found = rfc1524_mailcap_parse (a, path, type, entry, opt);
-  }
+        if (rfc1524_mailcap_parse(a, path, type, entry, opt))
+            return 1;
 
 
-  if (entry && !found)
-    mutt_error (_("mailcap entry for type %s not found"), type);
+        p = q;
+    }
+
+    if (entry)
+        mutt_error(_("mailcap entry for type %s not found"), type);
 
 
-  return found;
+    return 0;
 }
 
 }
 
+/************** READ MARK **********************/
+
 
 /* This routine will create a _temporary_ filename matching the
  * name template given if this needs to be done.
 
 /* This routine will create a _temporary_ filename matching the
  * name template given if this needs to be done.
diff --git a/mutt.h b/mutt.h
index 28f8287..ed3a739 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -272,7 +272,6 @@ enum {
   OPTIMPLICITAUTOVIEW,
   OPTINCLUDEONLYFIRST,
   OPTKEEPFLAGGED,
   OPTIMPLICITAUTOVIEW,
   OPTINCLUDEONLYFIRST,
   OPTKEEPFLAGGED,
-  OPTMAILCAPSANITIZE,
   OPTMAILDIRTRASH,
   OPTMARKERS,
   OPTMARKOLD,
   OPTMAILDIRTRASH,
   OPTMARKERS,
   OPTMARKOLD,