{
    "mode": "man",
    "parameter": "mailcap",
    "section": "5",
    "url": "https://www.chedong.com/phpMan.php/man/mailcap/5/json",
    "generated": "2026-05-30T06:05:10Z",
    "sections": {
        "NAME": {
            "content": "mailcap - metamail capabilities file\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  mailcap file is read by the metamail program to determine how to display non-text at the\nlocal site.\n\nThe syntax of a mailcap file is quite simple, at least compared to termcap files.   Any  line\nthat  starts with \"#\" is a comment.  Blank lines are ignored.  Otherwise, each line defines a\nsingle mailcap entry for a single content type.  Long lines may be continued by  ending  them\nwith a backslash character, \\.\n\nEach individual mailcap entry consists of a content-type specification, a command to execute,\nand (possibly) a set of optional \"flag\" values.  For example, a  very  simple  mailcap  entry\n(which is actually a built-in default behavior for metamail) would look like this:\n\ntext/plain; cat %s\n\nThe optional flags can be used to specify additional information about the mail-handling com‐\nmand.  For example:\n\ntext/plain; cat %s; copiousoutput\n\ncan be used to indicate that the output of the 'cat' command may be voluminous, requiring ei‐\nther a scrolling window, a pager, or some other appropriate coping mechanism.\n\nThe \"type\" field (text/plain, in the above example) is simply any legal content type name, as\ndefined by informational RFC 1524.  In practice, this is almost any string.  It is the string\nthat  will  be  matched against the \"Content-type\" header (or the value passed in with -c) to\ndecide if this is the mailcap entry that matches the current message.  Additionally, the type\nfield  may  specify  a  subtype  (e.g. \"text/ISO-8859-1\") or a wildcard to match all subtypes\n(e.g. \"image/*\").\n\nThe \"command\" field is any UNIX command (\"cat %s\" in the above example), and is used to spec‐\nify  the  interpreter  for the given type of message.  It will be passed to the shell via the\nsystem(3) facility.  Semicolons and backslashes within the command must be quoted with  back‐\nslashes.   If the command contains \"%s\", those two characters will be replaced by the name of\na file that contains the body of the message. If it contains \"%t\", those two characters  will\nbe  replaced by the content-type field, including the subtype, if any.  (That is, if the con‐\ntent-type was \"image/pbm; opt1=something-else\", then \"%t\" would be replaced by  \"image/pbm\".)\nIf  the command field contains  \"%{\" followed by a parameter name and a closing \"}\", then all\nthose characters will be replaced by the value of the named parameter, if any, from the  Con‐\ntent-type  header.   Thus, in the previous example, \"%{opt1}\" will be replaced by \"something-\nelse\".  Finally, if the command contains \"\\%\", those two characters will  be  replaced  by  a\nsingle  %  character.   (In fact, the backslash can be used to quote any character, including\nitself.)\n\nIf no \"%s\" appears in the command field, then instead of placing the message body in a tempo‐\nrary file, metamail will pass the body to the command on the standard input.  This is helpful\nin saving /tmp file space, but can be problematic for window-oriented applications under some\nwindow systems such as MGR.\n\nTwo  special  codes can appear in the viewing command for objects of type multipart (any sub‐\ntype).  These are \"%n\" and \"%F\".  %n will be replaced by the number of parts within the  mul‐\ntipart object.  %F will be replaced by a series of arguments, two for each part, giving first\nthe content-type and then the name of the temporary file where  the  decoded  part  has  been\nstored.   In  addition,  for each file created by %F, a second file is created, with the same\nname followed by \"H\", which contains the header information for that body  part.   This  will\nnot be needed by most multipart handlers, but it is there if you ever need it.\n\nThe \"notes=xxx\" field is an uninterpreted string that is used to specify the name of the per‐\nson who installed this entry in the mailcap file.  (The \"xxx\" may be  replaced  by  any  text\nstring.)\n\nThe  \"test=xxx\"  field  is a command that is executed to determine whether or not the mailcap\nline actually applies.  That is, if the content-type field matches the  content-type  on  the\nmessage,  but  a \"test=\" field is present, then the test must succeed before the mailcap line\nis considered to \"match\" the message being viewed.  The command may be any UNIX command,  us‐\ning the same syntax and the same %-escapes as for the viewing command, as described above.  A\ncommand is considered to succeed if it exits with a zero exit status, and to fail otherwise.\n\nThe \"print=xxx\" field is a command that is executed to print the data instead of  display  it\ninteractively.   This  behavior  is  usually a consequence of invoking metamail with the \"-h\"\nswitch.\n\nThe \"textualnewlines\" field can be used in the rather obscure case where  metamail's  default\nrules  for treating newlines in base64-encoded data are unsatisfactory.  By default, metamail\nwill translate CRLF to the local newline character in decoded base64 output if  the  content-\ntype  is \"text\" (any subtype), but will not do so otherwise.  A mailcap entry with a field of\n\"textualnewlines=1\" will force such translation for the specified content-type, while \"textu‐\nalnewlines=0\"  will  guarantee that the translation does not take place even for textual con‐\ntent-types.\n\nThe \"compose\" field may be used to specify a program that can be used to compose a  new  body\nor  body part in the given format.  Its intended use is to support mail composing agents that\nsupport the composition of multiple types of mail using external composing  agents.  As  with\nthe  view-command,  the  compose  command will be executed after replacing certain escape se‐\nquences starting with \"%\".  In particular, %s should be replaced by the name  of  a  file  to\nwhich  the  composed  data is to be written by the specified composing program, thus allowing\nthe calling program (e.g. metamail) to tell the called program where to  store  the  composed\ndata.   If  %s  does  not appear, then the composed data will be assumed to be written by the\ncomposing programs to standard output.   The result of the composing program may be data that\nis NOT yet suitable for mail transport -- that is, a Content-Transfer-Encoding may still need\nto be applied to the data.\n\nThe \"composetyped\" field is similar to the \"compose\" field, but is to be used when  the  com‐\nposing  program  needs to specify the Content-type header field to be applied to the composed\ndata.  The \"compose\" field is simpler, and is preferred for use with existing  (non-mail-ori‐\nented)  programs for composing data in a given format.  The \"composetyped\" field is necessary\nwhen the Content-type information must include auxiliary parameters, and the composition pro‐\ngram  must  then know enough about mail formats to produce output that includes the mail type\ninformation, and to apply any necessary Content-Transfer-Encoding.   Conceptually,  \"compose\"\nspecifies  a  program  that  simply outputs the specified type of data in its raw form, while\n\"composetyped\" specifies a program that outputs the data as a MIME object, with all necessary\nContent-* headers already in place.\n\n",
            "subsections": [
                {
                    "name": "needsterminal",
                    "content": "If  this  flag  is  given, the named interpreter needs to interact with the user on a\nterminal.  In some environments (e.g. a window-oriented mail reader under  X11)  this\nwill  require the creation of a new terminal emulation window, while in most environ‐\nments it will not.  If the mailcap entry specifies \"needsterminal\"  and  metamail  is\nnot  running  on  a  terminal  (as  determined  by  isatty(3), the -x option, and the\nMMNOTTTY environment variable) then metamail will try to run the command  in  a  new\nterminal emulation window.  Currently, metamail knows how to create new windows under\nthe X11, SunTools, and WM window systems.\n"
                },
                {
                    "name": "copiousoutput",
                    "content": "This flag should be given whenever the interpreter is capable of producing more  than\na few lines of output on stdout, and does no interaction with the user.  If the mail‐\ncap entry specifies copiousoutput, and pagination has been  requested  via  the  \"-p\"\ncommand,  then the output of the command being executed will be piped through a pagi‐\nnation program (\"more\" by default, but this can be overridden with the METAMAILPAGER\nenvironment variable).\n"
                }
            ]
        },
        "BUILT-IN CONTENT-TYPE SUPPORT": {
            "content": "The  metamail  program  has  built-in support for a few key content-types.  In particular, it\nsupports the text type, the multipart and multipart/alternative type, and the  message/rfc822\ntypes.   This  support  is  incomplete for many subtypes -- for example, it only supports US-\nASCII text in general.  This kind of built-in support can be OVERRIDDEN by an  entry  in  any\nmailcap  file  on the user's search path.  Metamail also has rudimentary built-in support for\ntypes that are totally unrecognized -- i.e. for which no mailcap entry  or  built-in  handler\nexists.   For  such unrecognized types, metamail will write a file with a \"clean\" copy of the\ndata -- i.e. a copy in which all mail headers have been  removed,  and  in  which  any  7-bit\ntransport encoding has been decoded.\n",
            "subsections": []
        },
        "FILES": {
            "content": "$HOME/.mailcap:/etc/mailcap:/usr/share/etc/mailcap:/usr/local/etc/mailcap -- default path for\nmailcap files.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "run-mailcap(1), mailcap.order(5), update-mime(8)\n\nRFC 1524 (<http://tools.ietf.org/html/rfc1524>)\n\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)\n\nPermission to use, copy, modify, and distribute this material for any purpose and without fee\nis hereby granted, provided that the above copyright notice and this permission notice appear\nin all copies, and that the name of Bellcore not be used in advertising or publicity pertain‐\ning  to  this material without the specific, prior written permission of an authorized repre‐\nsentative of Bellcore.  BELLCORE MAKES NO REPRESENTATIONS ABOUT THE ACCURACY  OR  SUITABILITY\nOF  THIS  MATERIAL  FOR  ANY PURPOSE.  IT IS PROVIDED \"AS IS\", WITHOUT ANY EXPRESS OR IMPLIED\nWARRANTIES.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Nathaniel S. Borenstein\n\n\n\nBellcore Prototype                            Release 2                                   MAILCAP(5)",
            "subsections": []
        }
    },
    "summary": "mailcap - metamail capabilities file",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "run-mailcap",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/run-mailcap/1/json"
        },
        {
            "name": "mailcap.order",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/mailcap.order/5/json"
        },
        {
            "name": "update-mime",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/update-mime/8/json"
        }
    ]
}