LinuxCommandLibrary

print.runmailcap

Execute commands defined in mailcap files

TLDR

Print action can be used to print any file on default run-mailcap tool

$ print [filename]
copy

With run-mailcap
$ run-mailcap --action=print [filename]
copy

SYNOPSIS

runmailcap --action=print [options] MIME_TYPE FILE [ARGUMENTS...]

PARAMETERS

--action=print
    Explicitly specifies the action to be performed, which in this context is 'print'. Other possible actions include 'view', 'compose', or 'edit'.

MIME_TYPE
    The MIME type of the file to be processed (e.g., application/pdf, image/png).

FILE
    The path to the file that needs to be printed.

ARGUMENTS...
    Additional arguments to be passed to the command defined in the mailcap entry.

--debug
    Prints extensive debugging information to standard error, useful for troubleshooting mailcap configuration issues.

--status
    Prints status messages indicating success or failure of the operation.

--noroot
    Prevents runmailcap from considering mailcap entries that are designated for root-only execution.

--no-fallback
    Disables the fallback mechanism to default handlers if no specific mailcap entry is found for the given MIME type and action.

DESCRIPTION


The command `print.runmailcap` refers to the specific use of the runmailcap utility to handle files for printing based on their MIME type and the system's mailcap configuration.

runmailcap is a utility that interprets mailcap files (typically located at /etc/mailcap and ~/.mailcap). These files serve as a database that maps various MIME (Multipurpose Internet Mail Extensions) types (e.g., application/pdf, image/jpeg, text/plain) to external programs capable of viewing, editing, or, in this case, printing them.

When invoked with the "print" action, runmailcap searches the mailcap configuration for an entry matching the given MIME type and the requested "print" action. If a suitable entry is found, it executes the associated command, passing the specified file to it. This mechanism allows applications to delegate the printing of diverse file formats to specialized helper programs, without needing to know the specifics of each file type's handling.

CAVEATS

  • Dependency on Mailcap Configuration: The functionality heavily relies on correctly configured mailcap files. Incorrect or missing entries can lead to errors or files not being handled as expected.
  • Security Risks: Commands specified in mailcap entries are executed with the user's permissions. Care must be taken to ensure that mailcap files are trusted and do not contain malicious entries, as this could pose a security risk.
  • No Universal Print Command: There is no single universal command for printing all file types. runmailcap delegates to various external programs (e.g., lpr, evince, gv), which must be installed and configured correctly.
  • Graphical Environment Requirement: Many printing helpers require a graphical environment to function, even if the printing process itself is to a physical printer.

MAILCAP FILE STRUCTURE

A mailcap file consists of one or more entries, each defining how to handle a specific MIME type. A typical entry follows the format:

MIME_type; command; field1; field2; ...

For instance: application/pdf; evince %s; test=test -n "$(which evince)"; print=lpr %s

Common fields include:

  • test: A shell command that must exit successfully for the entry to be used.
  • print: The command to be executed for printing the file (this is what --action=print looks for).
  • copiousoutput: Indicates the command produces a lot of output, which should be redirected to a pager.

Placeholders like %s (filename), %t (MIME type), and %{param} (header parameter) are used within the command string.

COMMON MAILCAP LOCATIONS

Mailcap files are typically read in a specific order:

  • ~/.mailcap: User-specific overrides.
  • /etc/mailcap: System-wide default configurations.
  • Other locations specified by the MAILCAPS environment variable.

This hierarchy allows users to customize behavior without modifying system-wide settings.

HISTORY

Mailcap files originated as part of the MIME (Multipurpose Internet Mail Extensions) standards in the early 1990s. They were designed to provide a standardized way for applications, particularly mail user agents (MUAs), to determine how to handle arbitrary media types (attachments) received via email. runmailcap emerged as a common utility to interpret these files, allowing systems to flexibly launch external viewers, editors, or printers for different MIME-typed data. While more integrated desktop environment mechanisms (like XDG MIME applications or GIO) have evolved, mailcap and runmailcap remain a fundamental, lightweight, and robust method for defining application associations on Unix-like systems, especially for command-line driven environments and older applications.

SEE ALSO

mailcap(5), update-mime(8), xdg-open(1), lpr(1), cups(7)

Copied to clipboard