Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-mailbox.html" /> | |
13 | <link rel="prev" href="module-email.html" /> | |
14 | <link rel="parent" href="netdata.html" /> | |
15 | <link rel="next" href="module-mailbox.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>12.3 mailcap -- Mailcap file handling.</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="12.2.13 Examples" | |
25 | href="node597.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="12. Internet Data Handling" | |
28 | href="netdata.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="12.4 mailbox " | |
31 | href="module-mailbox.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="node597.html">12.2.13 Examples</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-mailbox.html">12.4 mailbox </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0014300000000000000000"> | |
56 | 12.3 <tt class="module">mailcap</tt> -- | |
57 | Mailcap file handling.</A> | |
58 | </H1> | |
59 | <A NAME="module-mailcap"></A> | |
60 | <P> | |
61 | ||
62 | <P> | |
63 | Mailcap files are used to configure how MIME-aware applications such | |
64 | as mail readers and Web browsers react to files with different MIME | |
65 | types. (The name ``mailcap'' is derived from the phrase ``mail | |
66 | capability''.) For example, a mailcap file might contain a line like | |
67 | "<tt class="samp">video/mpeg; xmpeg %s</tt>". Then, if the user encounters an email | |
68 | message or Web document with the MIME type <span class="mimetype">video/mpeg</span>, | |
69 | "<tt class="samp">%s</tt>" will be replaced by a filename (usually one belonging to a | |
70 | temporary file) and the <b class="program">xmpeg</b> program can be automatically | |
71 | started to view the file. | |
72 | ||
73 | <P> | |
74 | The mailcap format is documented in <a class="rfc" id='rfcref-91011' xml:id='rfcref-91011' | |
75 | href="http://www.faqs.org/rfcs/rfc1524.html">RFC 1524</a>, ``A User Agent | |
76 | Configuration Mechanism For Multimedia Mail Format Information,'' but | |
77 | is not an Internet standard. However, mailcap files are supported on | |
78 | most <span class="Unix">Unix</span> systems. | |
79 | ||
80 | <P> | |
81 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
82 | <td><nobr><b><tt id='l2h-3961' xml:id='l2h-3961' class="function">findmatch</tt></b>(</nobr></td> | |
83 | <td><var>caps, MIMEtype</var><big>[</big><var>, key</var><big>[</big><var>, | |
84 | filename</var><big>[</big><var>, plist</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
85 | <dd> | |
86 | Return a 2-tuple; the first element is a string containing the command | |
87 | line to be executed | |
88 | (which can be passed to <tt class="function">os.system()</tt>), and the second element is | |
89 | the mailcap entry for a given MIME type. If no matching MIME | |
90 | type can be found, <code>(None, None)</code> is returned. | |
91 | ||
92 | <P> | |
93 | <var>key</var> is the name of the field desired, which represents the type | |
94 | of activity to be performed; the default value is 'view', since in the | |
95 | most common case you simply want to view the body of the MIME-typed | |
96 | data. Other possible values might be 'compose' and 'edit', if you | |
97 | wanted to create a new body of the given MIME type or alter the | |
98 | existing body data. See <a class="rfc" id='rfcref-91013' xml:id='rfcref-91013' | |
99 | href="http://www.faqs.org/rfcs/rfc1524.html">RFC 1524</a> for a complete list of these | |
100 | fields. | |
101 | ||
102 | <P> | |
103 | <var>filename</var> is the filename to be substituted for "<tt class="samp">%s</tt>" in the | |
104 | command line; the default value is | |
105 | <code>'/dev/null'</code> which is almost certainly not what you want, so | |
106 | usually you'll override it by specifying a filename. | |
107 | ||
108 | <P> | |
109 | <var>plist</var> can be a list containing named parameters; the default | |
110 | value is simply an empty list. Each entry in the list must be a | |
111 | string containing the parameter name, an equals sign ("<tt class="character">=</tt>"), | |
112 | and the parameter's value. Mailcap entries can contain | |
113 | named parameters like <code>%{foo}</code>, which will be replaced by the | |
114 | value of the parameter named 'foo'. For example, if the command line | |
115 | "<tt class="samp">showpartial %{id} %{number} %{total}</tt>"was in a mailcap file, and <var>plist</var> was set to <code>['id=1', | |
116 | 'number=2', 'total=3']</code>, the resulting command line would be | |
117 | <code>'showpartial 1 2 3'</code>. | |
118 | ||
119 | <P> | |
120 | In a mailcap file, the ``test'' field can optionally be specified to | |
121 | test some external condition (such as the machine architecture, or the | |
122 | window system in use) to determine whether or not the mailcap line | |
123 | applies. <tt class="function">findmatch()</tt> will automatically check such | |
124 | conditions and skip the entry if the check fails. | |
125 | </dl> | |
126 | ||
127 | <P> | |
128 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
129 | <td><nobr><b><tt id='l2h-3962' xml:id='l2h-3962' class="function">getcaps</tt></b>(</nobr></td> | |
130 | <td><var></var>)</td></tr></table></dt> | |
131 | <dd> | |
132 | Returns a dictionary mapping MIME types to a list of mailcap file | |
133 | entries. This dictionary must be passed to the <tt class="function">findmatch()</tt> | |
134 | function. An entry is stored as a list of dictionaries, but it | |
135 | shouldn't be necessary to know the details of this representation. | |
136 | ||
137 | <P> | |
138 | The information is derived from all of the mailcap files found on the | |
139 | system. Settings in the user's mailcap file <span class="file">$HOME/.mailcap</span> | |
140 | will override settings in the system mailcap files | |
141 | <span class="file">/etc/mailcap</span>, <span class="file">/usr/etc/mailcap</span>, and | |
142 | <span class="file">/usr/local/etc/mailcap</span>. | |
143 | </dl> | |
144 | ||
145 | <P> | |
146 | An example usage: | |
147 | <div class="verbatim"><pre> | |
148 | >>> import mailcap | |
149 | >>> d=mailcap.getcaps() | |
150 | >>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223') | |
151 | ('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'}) | |
152 | </pre></div> | |
153 | ||
154 | <DIV CLASS="navigation"> | |
155 | <div class='online-navigation'> | |
156 | <p></p><hr /> | |
157 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
158 | <tr> | |
159 | <td class='online-navigation'><a rel="prev" title="12.2.13 Examples" | |
160 | href="node597.html"><img src='../icons/previous.png' | |
161 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
162 | <td class='online-navigation'><a rel="parent" title="12. Internet Data Handling" | |
163 | href="netdata.html"><img src='../icons/up.png' | |
164 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
165 | <td class='online-navigation'><a rel="next" title="12.4 mailbox " | |
166 | href="module-mailbox.html"><img src='../icons/next.png' | |
167 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
168 | <td align="center" width="100%">Python Library Reference</td> | |
169 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
170 | href="contents.html"><img src='../icons/contents.png' | |
171 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
172 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
173 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
174 | <td class='online-navigation'><a rel="index" title="Index" | |
175 | href="genindex.html"><img src='../icons/index.png' | |
176 | border='0' height='32' alt='Index' width='32' /></A></td> | |
177 | </tr></table> | |
178 | <div class='online-navigation'> | |
179 | <b class="navlabel">Previous:</b> | |
180 | <a class="sectref" rel="prev" href="node597.html">12.2.13 Examples</A> | |
181 | <b class="navlabel">Up:</b> | |
182 | <a class="sectref" rel="parent" href="netdata.html">12. Internet Data Handling</A> | |
183 | <b class="navlabel">Next:</b> | |
184 | <a class="sectref" rel="next" href="module-mailbox.html">12.4 mailbox </A> | |
185 | </div> | |
186 | </div> | |
187 | <hr /> | |
188 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
189 | </DIV> | |
190 | <!--End of Navigation Panel--> | |
191 | <ADDRESS> | |
192 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
193 | </ADDRESS> | |
194 | </BODY> | |
195 | </HTML> |