LinuxCommandLibrary

runmailcap

Execute commands based on MIME type

SYNOPSIS

runmailcap [options] [MIME-type] [filename] [--] [viewer-options]

PARAMETERS

-d, --debug
    Enable verbose debugging output to stderr.

-s, --no-stdout
    Suppress program output to stdout.

-p, --no-stderr
    Suppress program output to stderr.

-q, --query-command
    Output the command that would be run, but do not execute it.

-v, --view-command
    Similar to -q, but handles spaces in arguments correctly for shell execution.

-i, --interpret-command
    Output the command with all mailcap substitutions (%s, %t, etc.) resolved, but do not execute.

-n, --no-pager
    Do not use a pager even if the mailcap entry has 'needsterminal' set and a pager is defined.

-M, --mime-type type
    Force the MIME type to type, overriding autodetection if filename is provided.

-f, --file filename
    Specify the file to operate on. If omitted, filename is taken from the first non-option argument.

-F, --force-action action
    Force a specific action (e.g., 'view', 'compose', 'edit') instead of the default 'view'.

-k, --keep-extension
    Do not strip the extension from the filename before passing it to the command.

-l, --list-actions
    List all possible actions for the specified MIME type.

-a, --action action-name
    Execute a specific action defined in the mailcap file for the MIME type.

-b, --no-block
    Execute the command in the background, not waiting for it to exit.

-e, --edit
    Equivalent to -F edit, forces the 'edit' action.

-D, --dump-entry
    Dump the matching mailcap entry that would be used.

-g, --show-guess
    Show the guessed MIME type for the file.

-m, --show-mailcap
    Show the mailcap entries as they are processed during lookup.

-o, --optional-parameters params
    Pass additional optional parameters to the mailcap entry.

-w, --ask-user
    If multiple commands match, prompt the user to choose one interactively.

-t, --text-plain
    If no specific MIME type is found, treat the file as text/plain.

-x, --execute
    Explicitly execute the command (this is the default behavior).

-L, --language lang
    Specify a language for localized mailcap entries.

--
    Separates runmailcap options from arguments to be passed directly to the executed command.

DESCRIPTION

The runmailcap command is a utility designed to execute external programs based on the MIME (Multipurpose Internet Mail Extensions) type of a file. It works by parsing mailcap files, which define how various MIME types should be handled, typically for viewing, composing, or editing.

When given a MIME type and a filename, runmailcap searches through a predefined list of mailcap files (e.g., /etc/mailcap, ~/.mailcap, or those specified by the MAILCAPS environment variable) to find a suitable entry. Once a matching entry is found, it constructs and executes the corresponding command, passing the filename and any additional arguments.

This command is crucial in environments where applications (like email clients or web browsers) need to delegate the handling of specific file types to external viewers or editors, providing flexibility and extensibility in how different media types are managed on a Unix-like system.

CAVEATS

runmailcap executes arbitrary commands defined in mailcap files. Maliciously crafted mailcap entries or files could lead to arbitrary code execution if not properly secured. Users should be cautious about mailcap files obtained from untrusted sources.

The behavior is highly dependent on the correct configuration of mailcap files and the presence of the specified external programs. If a suitable viewer/editor is not found or the mailcap entry is incorrect, the command may fail or produce unexpected results.

MAILCAP FILES

runmailcap relies heavily on mailcap files, which are configuration files defining how different MIME types should be handled. These files are typically located at /etc/mailcap for system-wide defaults and ~/.mailcap for user-specific overrides. The MAILCAPS environment variable can also specify a colon-separated list of additional mailcap files. Each line in a mailcap file specifies a MIME type, a command to execute, and optional flags or parameters.

MIME TYPE DETECTION

While runmailcap can be explicitly told the MIME type, it can also attempt to guess the MIME type of a file based on its content or filename extension if not provided. This detection often relies on other system utilities like file(1) or internal heuristics, though the primary mechanism is to match the provided type against mailcap entries.

HISTORY

The concept of mailcap files and utilities like runmailcap emerged in the early 1990s as part of the MIME standard's development to address the need for flexible handling of diverse media types in email and other applications. It provides a standardized, declarative way for Unix-like systems to associate MIME types with helper applications, predating more modern desktop-environment-specific MIME handling systems like xdg-mime but remaining a foundational and widely used component in many terminal-based applications and mail clients.

SEE ALSO

mailcap(5), update-mime(1), mutt(1), less(1), xdg-open(1)

Copied to clipboard