<literal>mime.types</literal> file comes with the Mutt distribution, and
should contain most of the MIME types you are likely to use.</para>
<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
+ file you 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
WHERE char *MhFlagged;
WHERE char *MhReplied;
WHERE char *MhUnseen;
+WHERE char *MimeTypeQueryCmd;
WHERE char *MsgFmt;
#ifdef USE_SOCKET
t->orig_str = safe_strdup(s);
/* This could be more space efficient. However, being used on tiny
- * strings (Tochars and StChars), the overhead is not great. */
+ * strings (ToChars and StChars), the overhead is not great. */
t->chars = safe_calloc(slen, sizeof(char *));
d = t->segmented_str = safe_calloc(slen * 2, sizeof(char));
** is Usenet article, because MIME for news is nonstandard feature.
*/
#endif
+ { "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, OPT_MIME_TYPE_QUERY_FIRST, 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" },
/*
* struct MbCharTable - multibyte character table
*
* Allows for direct access to the individual multibyte characters in a
- * string. This is used for the Flagchars, Fromchars, StChars and Tochars
+ * string. This is used for the FlagChars, FromChars, StChars and ToChars
* option types.
*/
struct MbCharTable
OPT_ME_TOO,
OPT_MH_PURGE,
OPT_MIME_FORW_DECODE,
+ OPT_MIME_TYPE_QUERY_FIRST,
#ifdef USE_NNTP
OPT_MIME_SUBJECT, /**< encode subject line with RFC2047 */
#endif
#include "context.h"
#include "copy.h"
#include "envelope.h"
+#include "filter.h"
#include "format_flags.h"
#include "globals.h"
#include "header.h"
return body;
}
+static void run_mime_type_query(struct 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);
+}
+
struct Body *mutt_make_file_attach(const char *path)
{
struct Body *att = NULL;
att = mutt_new_body();
att->filename = safe_strdup(path);
+ if (MimeTypeQueryCmd && *MimeTypeQueryCmd && option(OPT_MIME_TYPE_QUERY_FIRST))
+ run_mime_type_query(att);
+
/* Attempt to determine the appropriate content-type based on the filename
* suffix.
*/
+ if (!att->subtype)
+ mutt_lookup_mime_type(att, path);
- mutt_lookup_mime_type(att, path);
+ if (!att->subtype && MimeTypeQueryCmd && *MimeTypeQueryCmd && !option(OPT_MIME_TYPE_QUERY_FIRST))
+ run_mime_type_query(att);
if ((info = mutt_get_content_info(path, att)) == NULL)
{