📄 mimesupport.html
字号:
</p><p>Perhaps you wish to use lynx to view text/html files, and a pager onall other text formats, then you would use the following:</p><pre class="screen">text/html; lynx %stext/*; more</pre><p>This is the simplest form of a mailcap file.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id2688432"></a>3.2.聽Secure use of mailcap</h3></div></div></div><p>The interpretion of shell meta-characters embedded in MIME parameterscan lead to security problems in general. Mutt tries to quote parametersin expansion of %s syntaxes properly, and avoids risky characters bysubstituting them, see the <a href="reference.html#mailcap-sanitize" title="3.101.聽mailcap_sanitize">$mailcap_sanitize</a> variable.</p><p>Although mutt's procedures to invoke programs with mailcap seem to besafe, there are other applications parsing mailcap, maybe taking less careof it. Therefore you should pay attention to the following rules:</p><p><span class="emphasis"><em>Keep the %-expandos away from shell quoting.</em></span>Don't quote them with single or double quotes. Mutt does this foryou, the right way, as should any other program which interpretsmailcap. Don't put them into backtick expansions. Be highly carefulwith eval statements, and avoid them if possible at all. Trying to fixbroken behaviour with quotes introduces new leaks - there is noalternative to correct quoting in the first place.</p><p>If you have to use the %-expandos' values in context where you needquoting or backtick expansions, put that value into a shell variableand reference the shell variable where necessary, as in the followingexample (using <code class="literal">$charset</code> inside the backtick expansion is safe,since it is not itself subject to any further expansion):</p><p></p><pre class="screen">text/test-mailcap-bug; cat %s; copiousoutput; test=charset=%{charset} \ && test "`echo $charset | tr '[A-Z]' '[a-z]'`" != iso-8859-1</pre><p></p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id2688503"></a>3.3.聽Advanced mailcap Usage</h3></div></div></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2688509"></a>3.3.1.聽Optional Fields</h4></div></div></div><p>In addition to the required content-type and view command fields, youcan add semi-colon ';' separated fields to set flags and other options.Mutt recognizes the following optional fields:</p><div class="variablelist"><dl><dt><span class="term">copiousoutput</span></dt><dd><p>This flag tells Mutt that the command passes possibly large amounts oftext on stdout. This causes Mutt to invoke a pager (either the internalpager or the external pager defined by the pager variable) on the outputof the view command. Without this flag, Mutt assumes that the commandis interactive. One could use this to replace the pipe to <code class="literal">more</code>in the <code class="literal">lynx -dump</code> example in the Basic section:</p><pre class="screen">text/html; lynx -dump %s ; copiousoutput</pre><p>This will cause lynx to format the text/html output as text/plainand Mutt will use your standard pager to display the results.</p></dd><dt><span class="term">needsterminal</span></dt><dd><p>Mutt uses this flag when viewing attachments with <a href="mimesupport.html#auto-view" title="4.聽MIME Autoview">auto_view</a>, in order to decide whether it should honor the settingof the <a href="reference.html#wait-key" title="3.286.聽wait_key">$wait_key</a> variable ornot. When an attachment is viewed using an interactive program, and thecorresponding mailcap entry has a <span class="emphasis"><em>needsterminal</em></span> flag, Mutt will use<a href="reference.html#wait-key" title="3.286.聽wait_key">$wait_key</a> and the exit statusof the program to decide if it will ask you to press a key after theexternal program has exited. In all other situations it will not promptyou for a key.</p></dd><dt><span class="term">compose=<command></span></dt><dd><p>This flag specifies the command to use to create a new attachment of aspecific MIME type. Mutt supports this from the compose menu.</p></dd><dt><span class="term">composetyped=<command></span></dt><dd><p>This flag specifies the command to use to create a new attachment of aspecific MIME type. This command differs from the compose command inthat mutt will expect standard MIME headers on the data. This can beused to specify parameters, filename, description, etc. for a newattachment. Mutt supports this from the compose menu.</p></dd><dt><span class="term">print=<command></span></dt><dd><p>This flag specifies the command to use to print a specific MIME type.Mutt supports this from the attachment and compose menus.</p></dd><dt><span class="term">edit=<command></span></dt><dd><p>This flag specifies the command to use to edit a specific MIME type.Mutt supports this from the compose menu, and also uses it to composenew attachments. Mutt will default to the defined editor for textattachments.</p></dd><dt><span class="term">nametemplate=<template></span></dt><dd><p>This field specifies the format for the file denoted by %s in thecommand fields. Certain programs will require a certain file extension,for instance, to correctly view a file. For instance, lynx will onlyinterpret a file as <code class="literal">text/html</code> if the file ends in <code class="literal">.html</code>.So, you would specify lynx as a <code class="literal">text/html</code> viewer with a line inthe mailcap file like:</p><pre class="screen">text/html; lynx %s; nametemplate=%s.html</pre><p></p></dd><dt><span class="term">test=<command></span></dt><dd><p>This field specifies a command to run to test whether this mailcapentry should be used. The command is defined with the command expansionrules defined in the next section. If the command returns 0, then thetest passed, and Mutt uses this entry. If the command returns non-zero,then the test failed, and Mutt continues searching for the right entry.<span class="bold"><strong>Note:</strong></span> <span class="emphasis"><em>the content-type must match before Mutt performs the test.</em></span>For example:</p><pre class="screen">text/html; netscape -remote 'openURL(%s)' ; test=RunningXtext/html; lynx %s</pre><p>In this example, Mutt will run the program RunningX which will return 0if the X Window manager is running, and non-zero if it isn't. IfRunningX returns 0, then Mutt will call netscape to display thetext/html object. If RunningX doesn't return 0, then Mutt will go onto the next entry and use lynx to display the text/html object.</p></dd></dl></div><p></p></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2688764"></a>3.3.2.聽Search Order</h4></div></div></div><p>When searching for an entry in the mailcap file, Mutt will search forthe most useful entry for its purpose. For instance, if you areattempting to print an <code class="literal">image/gif</code>, and you have the followingentries in your mailcap file, Mutt will search for an entry with theprint command:</p><pre class="screen">image/*; xv %simage/gif; ; print= anytopnm %s | pnmtops | lpr; \ nametemplate=%s.gif</pre><p>Mutt will skip the <code class="literal">image/*</code> entry and use the <code class="literal">image/gif</code>entry with the print command.</p><p>In addition, you can use this with <a href="mimesupport.html#auto-view" title="4.聽MIME Autoview">auto_view</a> to denote two commands for viewing an attachment, one to be viewedautomatically, the other to be viewed interactively from the attachmentmenu. In addition, you can then use the test feature to determine whichviewer to use interactively depending on your environment.</p><pre class="screen">text/html; netscape -remote 'openURL(%s)' ; test=RunningXtext/html; lynx %s; nametemplate=%s.htmltext/html; lynx -dump %s; nametemplate=%s.html; copiousoutput</pre><p>For <a href="mimesupport.html#auto-view" title="4.聽MIME Autoview">auto_view</a>, Mutt will choose the thirdentry because of the copiousoutput tag. For interactive viewing, Muttwill run the program RunningX to determine if it should use the firstentry. If the program returns non-zero, Mutt will use the second entryfor interactive viewing.</p></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2688841"></a>3.3.3.聽Command Expansion</h4></div></div></div><p>The various commands defined in the mailcap files are passed to the<code class="literal">/bin/sh</code> shell using the system() function. Before thecommand is passed to <code class="literal">/bin/sh -c</code>, it is parsed to expandvarious special parameters with information from Mutt. The keywordsMutt expands are:</p><div class="variablelist"><dl><dt><span class="term">%s</span></dt><dd><p>As seen in the basic mailcap section, this variable is expandedto a filename specified by the calling program. This file containsthe body of the message to view/print/edit or where the composingprogram should place the results of composition. In addition, theuse of this keyword causes Mutt to not pass the body of the messageto the view/print/edit program on stdin.</p></dd><dt><span class="term">%t</span></dt><dd><p>Mutt will expand %t to the text representation of the contenttype of the message in the same form as the first parameter of themailcap definition line, ie <code class="literal">text/html</code> or<code class="literal">image/gif</code>.</p></dd><dt><span class="term">%{<parameter>}</span></dt><dd><p>Mutt will expand this to the value of the specified parameterfrom the Content-Type: line of the mail message. For instance, ifYour mail message contains:</p><pre class="screen">Content-Type: text/plain; charset=iso-8859-1</pre><p>then Mutt will expand %{charset} to iso-8859-1. The default metamailmailcap file uses this feature to test the charset to spawn an xtermusing the right charset to view the message.</p></dd><dt><span class="term">\%</span></dt><dd><p>This will be replaced by a %</p></dd></dl></div><p>Mutt does not currently support the %F and %n keywordsspecified in RFC 1524. The main purpose of these parameters is formultipart messages, which is handled internally by Mutt.</p></div></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id2688963"></a>3.4.聽Example mailcap files</h3></div></div></div><p>This mailcap file is fairly simple and standard:</p><pre class="programlisting"># I'm always running X :)video/*; xanim %s > /dev/nullimage/*; xv %s > /dev/null# I'm always running netscape (if my computer had more memory, maybe)text/html; netscape -remote 'openURL(%s)'</pre><p></p><p>This mailcap file shows quite a number of examples:</p><p></p><pre class="programlisting"># Use xanim to view all videos Xanim produces a header on startup,# send that to /dev/null so I don't see itvideo/*; xanim %s > /dev/null
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -