1998-08-10 21:42:37 +02:00
|
|
|
\section{\module{mailcap} ---
|
|
|
|
Mailcap file handling.}
|
1998-07-23 19:59:49 +02:00
|
|
|
\declaremodule{standard}{mailcap}
|
|
|
|
|
|
|
|
\modulesynopsis{Mailcap file handling.}
|
|
|
|
|
1997-03-25 23:01:35 +01:00
|
|
|
|
|
|
|
Mailcap files are used to configure how MIME-aware applications such
|
|
|
|
as mail readers and Web browsers react to files with different MIME
|
|
|
|
types. (The name ``mailcap'' is derived from the phrase ``mail
|
|
|
|
capability''.) For example, a mailcap file might contain a line like
|
1997-12-29 17:55:50 +01:00
|
|
|
\samp{video/mpeg; xmpeg \%s}. Then, if the user encounters an email
|
1998-04-02 17:53:07 +02:00
|
|
|
message or Web document with the MIME type \mimetype{video/mpeg},
|
|
|
|
\samp{\%s} will be replaced by a filename (usually one belonging to a
|
|
|
|
temporary file) and the \program{xmpeg} program can be automatically
|
|
|
|
started to view the file.
|
1997-03-25 23:01:35 +01:00
|
|
|
|
1998-02-09 20:16:20 +01:00
|
|
|
The mailcap format is documented in \rfc{1524}, ``A User Agent
|
1998-02-10 22:42:27 +01:00
|
|
|
Configuration Mechanism For Multimedia Mail Format Information,'' but
|
1997-03-25 23:01:35 +01:00
|
|
|
is not an Internet standard. However, mailcap files are supported on
|
1998-01-13 20:03:36 +01:00
|
|
|
most \UNIX{} systems.
|
1997-03-25 23:01:35 +01:00
|
|
|
|
1998-04-02 17:53:07 +02:00
|
|
|
\begin{funcdesc}{findmatch}{caps, MIMEtype%
|
|
|
|
\optional{, key\optional{,
|
|
|
|
filename\optional{, plist}}}}
|
1997-03-25 23:01:35 +01:00
|
|
|
Return a 2-tuple; the first element is a string containing the command
|
|
|
|
line to be executed
|
|
|
|
(which can be passed to \code{os.system()}), and the second element is
|
|
|
|
the mailcap entry for a given MIME type. If no matching MIME
|
|
|
|
type can be found, \code{(None, None)} is returned.
|
|
|
|
|
1998-02-09 20:16:20 +01:00
|
|
|
\var{key} is the name of the field desired, which represents the type
|
|
|
|
of activity to be performed; the default value is 'view', since in the
|
1997-03-25 23:01:35 +01:00
|
|
|
most common case you simply want to view the body of the MIME-typed
|
|
|
|
data. Other possible values might be 'compose' and 'edit', if you
|
|
|
|
wanted to create a new body of the given MIME type or alter the
|
1998-02-09 20:16:20 +01:00
|
|
|
existing body data. See \rfc{1524} for a complete list of these
|
|
|
|
fields.
|
1997-03-25 23:01:35 +01:00
|
|
|
|
1998-04-02 17:53:07 +02:00
|
|
|
\var{filename} is the filename to be substituted for \samp{\%s} in the
|
1997-03-25 23:01:35 +01:00
|
|
|
command line; the default value is
|
1998-04-02 17:53:07 +02:00
|
|
|
\code{'/dev/null'} which is almost certainly not what you want, so
|
1997-03-25 23:01:35 +01:00
|
|
|
usually you'll override it by specifying a filename.
|
|
|
|
|
|
|
|
\var{plist} can be a list containing named parameters; the default
|
|
|
|
value is simply an empty list. Each entry in the list must be a
|
1997-12-29 17:55:50 +01:00
|
|
|
string containing the parameter name, an equals sign (\code{=}), and the
|
1997-03-25 23:01:35 +01:00
|
|
|
parameter's value. Mailcap entries can contain
|
1997-12-29 17:55:50 +01:00
|
|
|
named parameters like \code{\%\{foo\}}, which will be replaced by the
|
1997-03-25 23:01:35 +01:00
|
|
|
value of the parameter named 'foo'. For example, if the command line
|
1998-04-02 17:53:07 +02:00
|
|
|
\samp{showpartial \%\{id\}\ \%\{number\}\ \%\{total\}}
|
1997-03-25 23:01:35 +01:00
|
|
|
was in a mailcap file, and \var{plist} was set to \code{['id=1',
|
|
|
|
'number=2', 'total=3']}, the resulting command line would be
|
|
|
|
\code{"showpartial 1 2 3"}.
|
|
|
|
|
|
|
|
In a mailcap file, the "test" field can optionally be specified to
|
|
|
|
test some external condition (e.g., the machine architecture, or the
|
|
|
|
window system in use) to determine whether or not the mailcap line
|
|
|
|
applies. \code{findmatch()} will automatically check such conditions
|
|
|
|
and skip the entry if the check fails.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{getcaps}{}
|
|
|
|
Returns a dictionary mapping MIME types to a list of mailcap file
|
1997-12-29 17:55:50 +01:00
|
|
|
entries. This dictionary must be passed to the \code{findmatch()}
|
1997-03-25 23:01:35 +01:00
|
|
|
function. An entry is stored as a list of dictionaries, but it
|
|
|
|
shouldn't be necessary to know the details of this representation.
|
|
|
|
|
|
|
|
The information is derived from all of the mailcap files found on the
|
|
|
|
system. Settings in the user's mailcap file \file{\$HOME/.mailcap}
|
|
|
|
will override settings in the system mailcap files
|
|
|
|
\file{/etc/mailcap}, \file{/usr/etc/mailcap}, and
|
|
|
|
\file{/usr/local/etc/mailcap}.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
An example usage:
|
1998-02-13 07:58:54 +01:00
|
|
|
\begin{verbatim}
|
1997-03-25 23:01:35 +01:00
|
|
|
>>> import mailcap
|
|
|
|
>>> d=mailcap.getcaps()
|
|
|
|
>>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223')
|
|
|
|
('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'})
|
1998-02-13 07:58:54 +01:00
|
|
|
\end{verbatim}
|