summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2002-01-24 14:21:50 +0000
committerThomas Roessler <roessler@does-not-exist.org>2002-01-24 14:21:50 +0000
commit51da70b69f3cbaffbc7bcbb963bc06d9ef497049 (patch)
treec0d14123cf8c7d2ff5424370ddddb35a061c9bd7
parente9fc7674fbde304145bd1207dc03241182175a7a (diff)
Introduce mime_lookup. From Brian Foley and Ulf Erikson.
-rw-r--r--attach.c46
-rw-r--r--doc/manual.sgml.head22
-rw-r--r--doc/muttrc.man.head10
-rw-r--r--globals.h1
-rw-r--r--init.h2
-rw-r--r--protos.h2
-rw-r--r--rfc1524.c2
-rw-r--r--sendlib.c8
8 files changed, 84 insertions, 9 deletions
diff --git a/attach.c b/attach.c
index 684bb765..3a7bcbcd 100644
--- 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) ||
diff --git a/doc/manual.sgml.head b/doc/manual.sgml.head
index f05d11b4..33a5cbca 100644
--- a/doc/manual.sgml.head
+++ b/doc/manual.sgml.head
@@ -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;
diff --git a/doc/muttrc.man.head b/doc/muttrc.man.head
index 176f30dd..e6905701 100644
--- a/doc/muttrc.man.head
+++ b/doc/muttrc.man.head
@@ -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
diff --git a/globals.h b/globals.h
index 738cbfb5..b69a6dfb 100644
--- 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 3025ec62..b119d76f 100644
--- 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
diff --git a/protos.h b/protos.h
index 2f8ca873..c34223e1 100644
--- 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 *);
diff --git a/rfc1524.c b/rfc1524.c
index aa4df6c2..f4210699 100644
--- 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;
diff --git a/sendlib.c b/sendlib.c
index 3569b464..3cb4df91 100644
--- 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