posts:node: Add a post on Node and npm
[blog.git] / posts / mailcap.mdwn
1 Mailcap files, defined in [RFC 1524][rfc1524], allow you to tell you
2 mail clients, web browsers, and other programs how you want to view
3 and edit various MIME types.  Since interaction with your mailcap
4 files often occurs deep within the bowels of your program, I've
5 written up a very simple [[Python]] script to test your mailcap
6 entries: [[mailcap-test.py]].  Enjoy!
7
8 Related utilities include [xdg-open][], [mimeopen][], and
9 [sensible-utils][].
10
11 Quoting
12 -------
13
14 Quoting in mailcap files is a tricky issue.  From the [Mutt][] man
15 page:
16
17 > Secure use of mailcap
18 >
19 > The interpretion of shell meta-characters embedded in MIME
20 > parameters can lead to security problems in general. Mutt tries to
21 > quote parameters in expansion of `%s` syntaxes properly, and avoids
22 > risky characters by substituting them, see the `mailcap_sanitize`
23 > variable.
24 >
25 > Although mutt's procedures to invoke programs with mailcap seem to
26 > be safe, there are other applications parsing mailcap, maybe taking
27 > less care of it. Therefore you should pay attention to the following
28 > rules:
29 >
30 > *Keep the %-expandos away from shell quoting.* Don't quote them with
31 > single or double quotes. Mutt does this for you, the right way, as
32 > should any other program which interprets mailcap. Don't put them
33 > into backtick expansions. Be highly careful with eval statements,
34 > and avoid them if possible at all. Trying to fix broken behaviour
35 > with quotes introduces new leaks - there is no alternative to
36 > correct quoting in the first place.
37 >
38 > If you have to use the %-expandos' values in context where you need
39 > quoting or backtick expansions, put that value into a shell variable
40 > and reference the shell variable where necessary, as in the
41 > following example (using $charset inside the backtick expansion is
42 > safe, since it is not itself subject to any further expansion):
43 >
44 >     text/test-mailcap-bug; cat %s; copiousoutput; test=charset=%{charset} \
45 >         && test "`echo $charset | tr '[A-Z]' '[a-z]'`" != iso-8859-1
46
47 [rfc1524]: http://tools.ietf.org/html/rfc1524
48 [xdg-open]: http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html
49 [mimeopen]: http://search.cpan.org/dist/File-MimeInfo/mimeopen
50 [sensible-utils]: http://packages.debian.org/sid/sensible-utils
51 [Mutt]: http://www.mutt.org/doc/manual/manual-5.html
52
53 [[!tag tags/code]]
54 [[!tag tags/linux]]
55 [[!tag tags/programming]]
56 [[!tag tags/python]]