<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter><title>Using Mailcap</title>
<para>

	This chapter describes the support for mailcap (rfc1524) in ELinks.  It
	does not describe the mailcap format. There are plenty of documents on
	the web that does this. Google and thou shall find. ;)

</para>

<sect1><title>A short intro to mailcap</title>
<para>

	Mailcap is a file format defined in rfc 1524. It is purpose is to
	inform multiple mail reading user agent (MUA) programs about the
	locally-installed facilities for handling mail in various formats.  It
	is designed to work with the Multipurpose Internet Mail Extensions,
	known as MIME.

</para>
<para>

	ELinks supports MIME quite well already so why support mailcap ? It can
	be seen as an alternative or simply as a supplement for setting up mime
	handler. Mailcap files are present at most UNIX systems
	(<filename>/etc/mailcap</filename>) so this makes it possible for
	ELinks to know how to handle a great variety of file formats with
	little configuration.

</para>
<para>

	To be able to use mailcap it has to be compiled into ELinks. This is
	the default. If you don't need mailcap support just configure ELinks
	with the flag: <option>--disable-mailcap</option>.

</para>

</sect1>

<sect1><title>Parameters</title>
<para>

	The code has been ported from mutt and thereby inherits some of it's
	various features and limitation.

</para>
<para>

	The following parameters are not supported. Since they do not make much
	sense for non-MUA:
	
</para>
<variablelist>
	<varlistentry>
		<term>
		<varname>%n</varname>
		</term>
		<listitem>
		<para>
		is the integer number of sub-parts in the multipart
		</para>
		</listitem>
	</varlistentry>

	<varlistentry>
		<term>
		<varname>%F</varname>
		</term>
		<listitem>
		<para>	
		is "content-type filename" repeated for each sub-part
		</para>
		</listitem>
	</varlistentry>

	<varlistentry>
		<term>
		<varname>%{parameter}</varname>
		</term>
		<listitem>
		<para>
		is replaced by the parameter value from the content-type field
		</para>
		</listitem>
	</varlistentry>
</variablelist>
<para>

	The following parameters are supported:

</para>
<variablelist>
	<varlistentry>
		<term>
		<varname>%s</varname>
		</term>
		<listitem>
		<para>
		is the filename that contains the data.
		</para>
		</listitem>
	</varlistentry>
	<varlistentry>
		<term>
		<varname>%f</varname>
		</term>
		<listitem>
		<para>
		is the content type, like text/plain
		</para>
		</listitem>
	</varlistentry>
</variablelist>
</sect1>

<sect1><title>Reading of mailcap files</title>
<para>

	Mailcap files will be read when starting ELinks. The mailcap files to
	use will be found from the a mailcap path a colon seperated list of
	files similar to $PATH environment variable. The mailcap path will be
	determined in the following way:

</para>
<itemizedlist mark="bullet">

	<listitem><para>
	From the value of the <option>protocol.mailcap.path</option> option in
	<filename>elinks.conf</filename> For example:
	<screen>
        set protocol.mailcap.path = "~/.mailcap:/usr/local/etc/mailcap"
	</screen>
	</para></listitem>

	<listitem><para>
	From <envar>MAILCAP</envar> environment variable
	</para></listitem>

	<listitem><para>
	If non of the above is defined the mailcap path defaults to
	<option>"~/.mailcap:/etc/mailcap"</option>
	</para></listitem>

</itemizedlist>
</sect1>

<sect1><title>Fields</title>
<para>

	Since mailcap handling is primarily for displaying of resources all
	fields like <option>edit</option>, <option>print</option>,
	<option>compose</option> etc. is ignored.

</para>
<note>
<para>

	Test commands are supported but unfortunately it's not possible to
	provide the file when running the test. So any test that requires a
	file will be considered failed and the handler will not be used.

</para>
</note>
<para>

	Unfortunately there are no 'native' support for the
	<option>copiousoutput</option> field. The field basicly mean 'needs
	pager'. So it is handled by appending a pipe and a pager program to the
	command. The pager program will be read from the <envar>PAGER</envar>
	environment variable.  If this fails test are made for common pager
	programs (<filename>/usr/bin/pager</filename>,
	<filename>/usr/bin/less</filename> and
	<filename>/usr/bin/more</filename> in that order). So if you define
	<command>png2ascii</command> as your handler for <type>image/png</type>
	and specify <option>copiousoutput</option> then the executed command
	will be <command>png2ascii | /usr/bin/less</command> if
	<command>less</command> is your pager or present on your system.

</para>
</sect1>

<sect1><title>Mailcap configuration</title>
<para>

	Apart from the <option>protocol.mailcap.path</option> option you can
	configure if mailcap support should be disabled. The default being that
	it is enabled. To disable it just put:

</para>
<screen>
        set protocol.mailcap.enable = 0
</screen>
<para>

	in <filename>elinks.conf</filename>.

</para>
<para>

	It is also possible to control wether ELinks should ask you before
	opening a file. The option is a boolian and can be set like this:

</para>
<screen>
        set protocol.mailcap.ask = 1
</screen>
<para>

	if you would like to be asked before opening a file.

</para>
</sect1>

<sect1><title>Some sample mailcap entries</title>
<screen>
# Use xv if X is running
image/*;                xv %s ; test=test -n "$DISPLAY";

# Convert images to text using the netpbm tools
image/*;                (anytopnm %s | pnmscale -xysize 200 150 | \
				pnminvert | ppmtopgm | pgmtopbm | \
				pbmtoascii -1x2 ) 2&gt;&amp;1 ; copiousoutput

# Various multimedia files
audio/mpeg;             xmms '%s'; test=test -n "$DISPLAY";
application/pdf;        xpdf '%s'; test=test -n "$DISPLAY";
application/postscript; ps2ascii %s ; copiousoutput
</screen>
</sect1>
</chapter>
