<para>
If Mutt can not determine the MIME type by the extension of the file you
-attach, it will look at the file. If the file is free of binary
-information, Mutt will assume that the file is plain text, and mark it
-as <literal>text/plain</literal>. If the file contains binary
+attach, it will run the command specified in
+<link linkend="mime-type-query-command">$mime_type_query_command</link>.
+If that command is not specified, Mutt will look at the file. If the file
+is free of binary information, Mutt will assume that the file is plain text,
+and mark it as <literal>text/plain</literal>. If the file contains binary
information, then Mutt will mark it as
<literal>application/octet-stream</literal>. You can change the MIME
type that Mutt assigns to an attachment by using the
WHERE char *MhFlagged;
WHERE char *MhReplied;
WHERE char *MhUnseen;
+WHERE char *MimeTypeQueryCmd;
WHERE char *MsgFmt;
#ifdef USE_SOCKET
** menu, attachments which cannot be decoded in a reasonable manner will
** be attached to the newly composed message if this option is \fIset\fP.
*/
+ { "mime_type_query_command", DT_STR, R_NONE, UL &MimeTypeQueryCmd, UL "" },
+ /*
+ ** .pp
+ ** This specifies a command to run, to determine the mime type of a
+ ** new attachment when composing a message. Unless
+ ** $$mime_type_query_first is set, this will only be run if the
+ ** attachment's extension is not found in the mime.types file.
+ ** .pp
+ ** The string may contain a ``%s'', which will be substituted with the
+ ** attachment filename. Mutt will add quotes around the string substituted
+ ** for ``%s'' automatically according to shell quoting rules, so you should
+ ** avoid adding your own. If no ``%s'' is found in the string, Mutt will
+ ** append the attachment filename to the end of the string.
+ ** .pp
+ ** The command should output a single line containing the
+ ** attachment's mime type.
+ ** .pp
+ ** Suggested values are ``xdg-mime query filetype'' or
+ ** ``file -bi''.
+ */
+ { "mime_type_query_first", DT_BOOL, R_NONE, OPTMIMETYPEQUERYFIRST, 0 },
+ /*
+ ** .pp
+ ** When \fIset\fP, the $$mime_type_query_command will be run before the
+ ** mime.types lookup.
+ */
#ifdef MIXMASTER
{ "mix_entry_format", DT_STR, R_NONE, UL &MixEntryFormat, UL "%4n %c %-16s %a" },
/*
OPTMETOO,
OPTMHPURGE,
OPTMIMEFORWDECODE,
+ OPTMIMETYPEQUERYFIRST,
OPTNARROWTREE,
OPTPAGERSTOP,
OPTPIPEDECODE,
return (body);
}
+static void run_mime_type_query (BODY *att)
+{
+ FILE *fp, *fperr;
+ char cmd[HUGE_STRING];
+ char *buf = NULL;
+ size_t buflen;
+ int dummy = 0;
+ pid_t thepid;
+
+ mutt_expand_file_fmt (cmd, sizeof(cmd), MimeTypeQueryCmd, att->filename);
+
+ if ((thepid = mutt_create_filter (cmd, NULL, &fp, &fperr)) < 0)
+ {
+ mutt_error (_("Error running \"%s\"!"), cmd);
+ return;
+ }
+
+ if ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL)
+ {
+ if (strchr(buf, '/'))
+ mutt_parse_content_type (buf, att);
+ FREE (&buf);
+ }
+
+ safe_fclose (&fp);
+ safe_fclose (&fperr);
+ mutt_wait_filter (thepid);
+}
+
BODY *mutt_make_file_attach (const char *path)
{
BODY *att;
att = mutt_new_body ();
att->filename = safe_strdup (path);
+ if (MimeTypeQueryCmd && *MimeTypeQueryCmd &&
+ option (OPTMIMETYPEQUERYFIRST))
+ run_mime_type_query (att);
+
/* Attempt to determine the appropriate content-type based on the filename
* suffix.
*/
- mutt_lookup_mime_type (att, path);
+ if (!att->subtype)
+ mutt_lookup_mime_type (att, path);
+
+ if (!att->subtype &&
+ MimeTypeQueryCmd && *MimeTypeQueryCmd &&
+ !option (OPTMIMETYPEQUERYFIRST))
+ run_mime_type_query (att);
if ((info = mutt_get_content_info (path, att)) == NULL)
{