run-mailcap
Execute command specified in mailcap file
TLDR
Invoke individual actions/programs on run-mailcap
Turn on extra information
Ignore any "copiousoutput" directive and forward output to stdout
Display the found command without actually executing it
SYNOPSIS
run-mailcap [OPTIONS] <MIMETYPE> <FILE> [ARGUMENTS...]
PARAMETERS
--debug
Display detailed debugging information about the process.
--view
Perform the 'view' action. This is the default action if none is specified.
--compose
Perform the 'compose' action, typically for creating new content of the specified type.
--print
Perform the 'print' action, to send the file to a printer.
--edit
Perform the 'edit' action, to open the file in an editor.
--raw
Do not interpret special '%s' or other '%'-sequences in the mailcap command, passing them literally.
--action=ACTION
Specify the desired action to perform (e.g., 'view', 'compose', 'print', 'edit'). Overrides default.
--no-warn
Suppress warnings if no suitable program or mailcap entry is found for the given MIME type.
--norun
Print the command that would be executed, but do not actually run it. Useful for debugging.
--remove-ext
Remove the filename extension from the file before passing it to the program (often used with '%s').
--no-email-view
Do not use generic 'text/plain' viewers for email body parts, even if the mailcap entry allows it.
--force-mime=MIMETYPE
Force the input file to be treated as the specified MIME type, overriding any autodetection.
DESCRIPTION
run-mailcap is a crucial Linux command-line utility designed to handle non-text files in a MIME-aware manner. It serves as an interpreter for
mailcap configuration files, which specify how different MIME types (e.g., image/jpeg, application/pdf) should be processed or displayed.
When invoked, run-mailcap reads through a hierarchical set of mailcap files, typically starting with the user-specific ~/.mailcap, followed by system-wide files like /etc/mailcap. It searches for an entry that matches the given MIME type and action (such as view, compose, print, or edit). Upon finding a match, it constructs and executes an external command specified in that mailcap entry, passing the file as an argument.
This utility is widely used by applications that need to interact with various file formats, including email clients, web browsers, and file managers. For instance, an email client might use run-mailcap to open an attached PDF document in a PDF viewer, or a web browser could use it to launch an external application for a specific media type. Its primary purpose is to abstract away the details of handling diverse file formats by relying on a centralized, configurable system.
CAVEATS
Security Risk: run-mailcap executes arbitrary commands defined in mailcap files. Users should exercise caution, especially with custom ~/.mailcap configurations or when processing files from untrusted sources, as malicious entries could execute harmful commands.
External Dependencies: Its functionality heavily relies on external programs being installed and accessible in the system's PATH. If a configured viewer/editor is missing, run-mailcap will fail to open the file.
Mailcap Complexity: The underlying mailcap file format can be intricate, involving conditional logic and special sequences. Misconfigurations can lead to unexpected behavior or security vulnerabilities.
MAILCAP FILE ORDER
run-mailcap typically consults multiple mailcap files in a specific order to determine the appropriate command. It usually checks the user-specific ~/.mailcap first, followed by system-wide files like /etc/mailcap. The first matching entry found for a given MIME type and action is used, providing a mechanism for user overrides.
SPECIAL SEQUENCES IN MAILCAP ENTRIES
mailcap entries can include special percent ('%') sequences that act as placeholders for information to be passed to the executed command. Common sequences include %s (for the filename), %t (for the MIME type), and %F (for a list of filenames). Understanding these sequences is crucial for correctly configuring mailcap entries and ensuring the external program receives the necessary arguments.
HISTORY
The mailcap specification (RFC 1524), which run-mailcap implements, dates back to 1993. It was created to provide a standardized, configurable way for MIME-aware applications (like early email clients and web browsers) to handle diverse non-textual data types. run-mailcap emerged as a common utility to utilize these configuration files, simplifying the process of invoking external viewers or editors based on a file's MIME type. Its development is intertwined with the evolution of desktop environments and internet applications that required robust MIME handling capabilities.
SEE ALSO
mailcap(5), update-mime-database(8), xdg-open(1)