RUN-MAILCAP(1)

๐Ÿ“ฆ
version 3.77ubuntu1 ยท 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’… RUN-MAILCAP โ€” ok bestie, let's open some files

Soooo the vibe here is: run-mailcap, plus its lil alias squad โ€” view, see, edit, compose, and print โ€” all exist to run programs for you based on what's written in the mailcap file. It's giving "the middleman you didn't know you needed." ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

run-mailcap --action=ACTION [--option[=value]] [MIME-TYPE:[ENCODING:]]FILE [...]

Okay so real talk: see, edit, compose and print? They're literally just aliases that default to the view, edit, compose and print actions respectively. Same program, different lewk. ๐Ÿ’…


๐ŸŒธ DESCRIPTION ๐ŸŒธ

run-mailcap (or literally any of its aliases, they all work) takes the action you give it and uses it to process each mime-type/file, one at a time, in turn. No skipping. We do them all.

Every file gets described as its mime-type, its encoding (think compression, bestie), and its filename โ€” all glued together with colons. That's the format, periodt.

  • If you leave out the mime-type, it tries to figure it out by matching the file's extension against the ones sitting in the mime.types files. ๐Ÿ”
  • If that comes up empty, it makes one last attempt by running the file command โ€” if it's available, no promises.
  • If you leave out the encoding, it gets determined from the file's extensions too. Easy.

The encodings it supports right now are:

  • gzip โ€” .gz
  • bzip2 โ€” .bz2
  • xz โ€” .xz
  • zstd โ€” .zst[d]
  • compress โ€” .Z

And here's a cute one: a filename of - means "standard input" ๐ŸŒˆ โ€” but if you do that, you must specify a mime-type. Non-negotiable, bestie.

Both the user's files (~/.mailcap; ~/.mime.types) and the system files (/etc/mailcap; /etc/mime.types) get searched in turn for the info. User stuff, then system stuff. Both get a moment. ๐Ÿซถ


๐ŸŽ€ EXAMPLES ๐ŸŽ€

see picture.jpg
print output.ps.gz
compose text/html:index.htm
extract-mail-attachment msg.txt | see image/tiff:gzip:-

Look at that last one โ€” piping straight into see with a fully spelled out mime-type, encoding AND - for stdin. She understood the assignment. ๐Ÿ˜ญ


๐Ÿ’– OPTIONS ๐Ÿ’–

Heads up: every single option is in the form --<opt>=<value>. That's just how we do it here.

  • --action=<action> โ€” does the specified action on the files. The valid actions are view, cat (this one only uses "copiousoutput" rules and sends output to STDOUT), compose, composetyped, edit, and print. And if you don't specify an action at all? Then the action gets decided by how the program was called. Mystery! ๐Ÿ™ˆ
  • --debug โ€” turns on extra information so you can actually see what's going on. It's giving detective mode. ๐Ÿ”
  • --nopager โ€” ignores any "copiousoutput" directive and just sends the output to STDOUT. No pager, no drama.
  • --norun โ€” shows you the found command without actually running it. A little preview, a little teaser. โœจ

๐Ÿ”ฅ SECURITY ๐Ÿ”ฅ

Okay bestie, listen up, this part is important.

A temporary symbolic link to the file gets opened if the file name matches this Perl regular expression:

"[^[:alnum:],.:/@%^+=_-]"

Why? To protect against the injection of shell commands ๐Ÿ’€ and to make sure the name can always be displayed in the current locale. Two birds.

On top of that, the file is opened using its absolute path, which prevents the injection of command-line arguments โ€” for instance, using file names that start with dashes. Yes, that's a real thing people try. We see you. ๐Ÿ‘€


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

file(1) mailcap(5) mailcap.order(5) update-mime(8)


๐Ÿฆ‹ AUTHOR ๐Ÿฆ‹

run-mailcap (and all its aliases, the whole crew) was written by Brian White <bcwhite@pobox.com>. Shoutout. ๐Ÿซถ


run-mailcap (and its aliases) is in the public domain โ€” which the page describes as the only true "free". Iconic. Ate. No notes.


And that's the whole thing, bestie ๐Ÿ’– This page comes to you from the Debian Project, dated 1st Jan 2008. Go forth and let the mailcap file decide your destiny. Mwah. ๐Ÿ’…๐ŸŒธ

๐Ÿ“ฆ where this page comes from