]> granicus.if.org Git - neomutt/commitdiff
Introduce mime_lookup. From Brian Foley and Ulf Erikson.
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 24 Jan 2002 14:21:50 +0000 (14:21 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 24 Jan 2002 14:21:50 +0000 (14:21 +0000)
attach.c
doc/manual.sgml.head
doc/muttrc.man.head
globals.h
init.h
protos.h
rfc1524.c
sendlib.c

index 684bb765333a8cf162edff7a7acb1db052fa96db..3a7bcbcd46e168193262f6d86912bc1d746f6343 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -325,6 +325,41 @@ static int is_mmnoask (const char *buf)
   return (0);
 }
 
+void mutt_check_lookup_list (BODY *b, char *type, int len)
+{
+  LIST *t = MimeLookupList;
+  int i;
+
+  for (; t; t = t->next) {
+    i = mutt_strlen (t->data) - 1;
+    if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && 
+        ascii_strncasecmp (type, t->data, i) == 0) ||
+       ascii_strcasecmp (type, t->data) == 0) {
+
+    BODY tmp = {0};
+    int n;
+    if ((n = mutt_lookup_mime_type (&tmp, b->filename)) != TYPEOTHER) {
+      snprintf (type, len, "%s/%s",
+                n == TYPEAUDIO ? "audio" :
+                n == TYPEAPPLICATION ? "application" :
+                n == TYPEIMAGE ? "image" :
+                n == TYPEMESSAGE ? "message" :
+                n == TYPEMODEL ? "model" :
+                n == TYPEMULTIPART ? "multipart" :
+                n == TYPETEXT ? "text" :
+                n == TYPEVIDEO ? "video" : "other",
+                tmp.subtype);
+      dprint(1, (debugfile, "mutt_check_lookup_list: \"%s\" -> %s\n", 
+        b->filename, type));
+    }
+    if (tmp.subtype) 
+      safe_free ((void **) &tmp.subtype);
+    if (tmp.xtype) 
+      safe_free ((void **) &tmp.xtype);
+    }
+  }
+}
+
 int mutt_is_autoview (BODY *b, const char *type)
 {
   LIST *t = AutoViewList;
@@ -332,10 +367,12 @@ int mutt_is_autoview (BODY *b, const char *type)
   int i;
 
   if (!type)
-  {
     snprintf (_type, sizeof (_type), "%s/%s", TYPE (b), b->subtype);
-    type = _type;
-  }
+  else
+    strncpy (_type, type, sizeof(_type));
+
+  mutt_check_lookup_list (b, _type, sizeof(_type));
+  type = _type;
 
   if (mutt_needs_mailcap (b))
   {
@@ -346,8 +383,7 @@ int mutt_is_autoview (BODY *b, const char *type)
       return 1;
   }
 
-  for (; t; t = t->next)
-  {
+  for (; t; t = t->next) {
     i = mutt_strlen (t->data) - 1;
     if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && 
         ascii_strncasecmp (type, t->data, i) == 0) ||
index f05d11b441dd6b13863a9331625ab5f696a9d532..33a5cbca4d33ce4027dcdbcd9a1b40b99a4cc76a 100644 (file)
@@ -2809,6 +2809,24 @@ Next, mutt will check if any of the types have a defined
 that, Mutt will look for any text type.  As a last attempt, mutt will
 look for any type it knows how to handle.
 
+<sect1>MIME Lookup<label id="mime_lookup">
+<p>
+Mutt's mime&lowbar;lookup list specifies a list of mime-types that should not
+be treated according to their mailcap entry.  This option is designed to
+deal with binary types such as application/octet-stream.  When an attachment's
+mime-type is listed in mime&lowbar;lookup, then the extension of the filename will
+be compared to the list of extensions in the mime.types file.  The mime-type
+associated with this extension will then be used to process the attachment
+according to the rules in the mailcap file and according to any other configuration
+options (such as auto&lowbar;view) specified.  Common usage would be:
+<tscreen><verb>
+mime-lookup application/octet-stream application/X-Lotus-Manuscript
+</verb></tscreen>
+
+In addition, the unmime&lowbar;lookup command may be used to disable this feature
+for any particular mime-type if it had been set, for example, in a global
+muttrc.
+
 <sect>Reference
 <sect1>Command line options<label id="commandline">
 <p>
@@ -2909,6 +2927,10 @@ The following are the commands understood by mutt.
 <item>
 <tt><ref id="message-hook" name="message-hook"></tt> <em/pattern/ <em/command/
 <item>
+<tt><ref id="mime_lookup" name="mime&lowbar;lookup"></tt> <em/mimetype/ &lsqb; <em/mimetype/ ... &rsqb;
+<item>
+<tt><ref id="mime_lookup" name="unmime&lowbar;lookup"></tt> <em/mimetype/ &lsqb; <em/mimetype/ ... &rsqb;
+<item>
 <tt><ref id="color" name="mono"></tt> <em/object attribute/ &lsqb; <em/regexp/ &rsqb;
 <item>
 <tt><ref id="color" name="unmono"></tt> <em/index/ <em/pattern/ &lsqb; <em/pattern/ ... &rsqb;
index 176f30dd95ac80fb1cf5449c04d8d0b2f97e47a6..e690570181aa8d4dd06be6f5fb33b661dd463e83 100644 (file)
@@ -92,6 +92,16 @@ entry for the given MIME type with the
 .B copiousoutput
 flag set.  A subtype of \(lq\fB*\fP\(rq 
 matches any subtype, as does an empty subtype.
+.PP
+.nf
+\fBmime_lookup\fP \fItype\fP[\fB/\fP\fIsubtype\fP] [ ... ]
+\fBunmime_lookup\fP \fItype\fP[\fB/\fP\fIsubtype\fP] [ ... ]
+This command permits you to define a list of "data" MIME content
+types for which mutt will try to determine the actual file type from
+the file name, and not use a 
+.BR mailcap (5)
+entry given for the original MIME type.  For instance, you may add
+the \fBapplication/octet-stream\fP MIME type to this list.
 .TP
 \fBbind\fP \fImap\fP \fIkey\fP \fIfunction\fP
 This command binds the given \fIkey\fP for the given \fImap\fP to
index 738cbfb55052ad8d6f223da8da4ca5afdc5df084..b69a6dfb15c18bdf134b9c95e96aacf47110fe0b 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -118,6 +118,7 @@ WHERE LIST *AutoViewList INITVAL(0);
 WHERE LIST *AlternativeOrderList INITVAL(0);
 WHERE LIST *HeaderOrderList INITVAL(0);
 WHERE LIST *Ignore INITVAL(0);
+WHERE LIST *MimeLookupList INITVAL(0);
 WHERE LIST *UnIgnore INITVAL(0);
 WHERE LIST *MailLists INITVAL(0);
 WHERE LIST *SubscribedLists INITVAL(0);
diff --git a/init.h b/init.h
index 3025ec62493483f43d1880422272f873125eedfa..b119d76f08957ee6f17ea505ed8ac1265ba253f8 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2455,6 +2455,8 @@ struct command_t Commands[] = {
   { "mailboxes",       mutt_parse_mailboxes,   0 },
   { "message-hook",    mutt_parse_hook,        M_MESSAGEHOOK },
   { "mbox-hook",       mutt_parse_hook,        M_MBOXHOOK },
+  { "mime_lookup",     parse_list,     UL &MimeLookupList },
+  { "unmime_lookup",   parse_unlist,   UL &MimeLookupList },
   { "mono",            mutt_parse_mono,        0 },
   { "my_hdr",          parse_my_hdr,           0 },
 #ifdef HAVE_PGP
index 2f8ca873c36078b0edf2c68a2da87d3dd8173161..c34223e14576276cffe4e9dfde36eeeadf84f0b0 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -190,6 +190,7 @@ void mutt_free_parameter (PARAMETER **);
 void mutt_generate_header (char *, size_t, HEADER *, int);
 void mutt_help (int);
 void mutt_draw_tree (CONTEXT *);
+void mutt_check_lookup_list (BODY *, char *, int);
 void mutt_make_attribution (CONTEXT *ctx, HEADER *cur, FILE *out);
 void mutt_make_forward_subject (ENVELOPE *env, CONTEXT *ctx, HEADER *cur);
 void mutt_make_help (char *, size_t, char *, int, int);
@@ -288,6 +289,7 @@ int mutt_is_list_recipient (int, ADDRESS *, ADDRESS *);
 int mutt_is_subscribed_list (ADDRESS *);
 int mutt_is_text_type (int, char *);
 int mutt_is_valid_mailbox (const char *);
+int mutt_lookup_mime_type (BODY *, const char *);
 int mutt_messages_in_thread (CONTEXT *, HEADER *, int);
 int mutt_multi_choice (char *prompt, char *letters);
 int mutt_needs_mailcap (BODY *);
index aa4df6c2cd2ff4a766bdb6e45e3511946eab2d41..f42106999946a1ab6da43552dd444f96fc283fa8 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -392,6 +392,8 @@ int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
     return 0;
   }
 
+  mutt_check_lookup_list (a, type, SHORT_STRING);
+
   while (!found && *curr)
   {
     x = 0;
index 3569b4649103b9e339397addf4acb9d894740765..3cb4df91f102382b8f2cbd194290f8de607e6d42 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -959,7 +959,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b)
  * exists.
  */
 
-static int lookup_mime_type (BODY *att, const char *path)
+int mutt_lookup_mime_type (BODY *att, const char *path)
 {
   FILE *f;
   char *p, *q, *ct;
@@ -994,7 +994,7 @@ static int lookup_mime_type (BODY *att, const char *path)
        strfcpy (buf, PKGDATADIR"/mime.types", sizeof (buf));
        break;
       default:
-       dprint (1, (debugfile, "lookup_mime_type: Internal error, count = %d.\n", count));
+        dprint (1, (debugfile, "mutt_lookup_mime_type: Internal error, count = %d.\n", count));
        goto bye;       /* shouldn't happen */
     }
 
@@ -1376,7 +1376,7 @@ BODY *mutt_make_file_attach (const char *path)
 
 #if 0
   
-  if ((n = lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf), path)) != TYPEOTHER 
+  if ((n = mutt_lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf), path)) != TYPEOTHER 
       || *xbuf != '\0')
   {
     att->type = n;
@@ -1386,7 +1386,7 @@ BODY *mutt_make_file_attach (const char *path)
 
 #else
   
-  lookup_mime_type (att, path);
+  mutt_lookup_mime_type (att, path);
 
 #endif