mime.types(5)

๐Ÿ“ฆ
version 2.4.19 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– mime.types โ€” the vibe-coded file-type decoder ring ๐Ÿ’–

okay bestie, sit DOWN, because this is mime.types(5), a manual page from OpenPrinting all about the CUPS mime type description file, and honestly? it's giving "quietly runs your entire printing pipeline" and I'm obsessed ๐ŸŽ€


โœจ NAME โœจ

mime.types โ€” the mime type description file for cups, aka the little text file that tells CUPS what all your files actually are ๐Ÿฆ‹


๐ŸŒธ DESCRIPTION ๐ŸŒธ

so the mime.types file is literally where the recognized file types live. that's it. that's the whole job. ๐Ÿ‘‘

and if you want MORE file types? no problem, because extra ones get specified in files with the .types extension sitting inside the CUPS configuration directory. slay.

every single line in mime.types is one of three things: a comment, a blank line, or a rule line. comment lines start with the # character (yes, the humble hashtag, iconic). rule lines start with the MIME media type and are optionally followed by a series of file recognition rules:

mime/type [ rule ... rule ]

and if your rule is really-really-really long? bestie you can extend rules over multiple lines using the backslash character (\):

mime/type [ really-really-really-long-rule ... \
  rule ]

the MIME media types you specify in that mime/type field are case-insensitive, and they get sorted in ascending alphanumeric order for the purposes of matching. want the whole tea? peek at the "TYPE MATCHING AND PRIORITY" section below, it's all there ๐Ÿ’…

also you can group rules using parenthesis, join them using + for a logical AND, join them using , or whitespace for a logical OR, and negate them using !. logic gate era fr fr ๐Ÿ”ฅ

๐Ÿงš RULES ๐Ÿงš

rules come in two forms โ€” a filename extension all by itself, and functions with test values inside parenthesis. here's every function you get, no gatekeeping:

  • match("pattern") โ€” true if the filename matches the given shell wildcard pattern. classic. reliable. we stan. โญ
  • ascii(offset,length) โ€” true if the length bytes starting at offset are valid printable ASCII (CR, NL, TAB, BS, 32-126). and heads up: length cannot exceed 8192 bytes. no cap, that's the limit ๐Ÿซถ
  • printable(offset,length) โ€” true if the length bytes starting at offset are printable 8-bit chars (CR, NL, TAB, BS, 32-126, 128-254). same rule though: length cannot exceed 8192 bytes ๐Ÿ’œ
  • priority(number) โ€” specifies the relative priority of this MIME media type. the default priority is 100. larger values have higher priority while smaller values have lower priority. it's giving ranked choice voting ngl ๐Ÿ“Š
  • string(offset,"string") โ€” true if the bytes starting at offset are identical to string. exact match energy.
  • istring(offset,"string") โ€” true if the bytes starting at offset match string without respect to case. the chill, case-insensitive twin of string ๐Ÿ˜Œ
  • char(offset,value) โ€” true if the byte at offset is identical to value.
  • short(offset,value) โ€” true if the 16-bit big-endian integer at offset is identical to value.
  • int(offset,value) โ€” true if the 32-bit big-endian integer at offset is identical to value.
  • locale("string") โ€” true if current locale matches string. hometown pride but for locales ๐ŸŒ
  • contains(offset,length,"string") โ€” true if the bytes starting at offset for length bytes contains string. and yes, length cannot exceed 8192 bytes. same ceiling, every time ๐ŸŽ€

๐ŸŽ€ STRING CONSTANTS ๐ŸŽ€

string constants can be specified inside quotes ("") for strings containing whitespace, and angle brackets (<>) for hexadecimal strings. pick your fighter ๐Ÿ’…

๐Ÿ‘‘ TYPE MATCHING AND PRIORITY ๐Ÿ‘‘

when CUPS needs to determine the MIME media type of a given file, it checks every MIME media type defined in the .types files. when two or more types match a given file, the type chosen will depend on the type name and priority โ€” with higher-priority types being used over lower-priority ones. and if the types have the same priority? the type names are sorted alphanumerically in ascending order and the first type is chosen. tiebreaker arc ๐Ÿ˜ญ

for example, if two types "text/bar" and "text/foo" are defined as matching the extension "doc", normally the type "text/bar" will be chosen since its name is alphanumerically smaller than "text/foo". however, if "text/foo" also defines a higher priority than "text/bar", "text/foo" will be chosen instead. plot twist, but make it deterministic โœจ


๐Ÿ“ FILES ๐Ÿ“

  • /etc/cups โ€” Typical CUPS configuration directory.

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

define two MIME media types for raster data, with one being a subset with higher priority:

application/vnd.cups-raster  string(0,"RaSt") string(0,"tSaR") \
                              string(0,"RaS2") string(0,"2SaR") \
                              string(0,"RaS3") string(0,"3SaR")

image/pwg-raster              string(0,"RaS2") + \
                              string(4,PwgRaster<00>) priority(150)

see how the second one is out here using + for AND and flexing that priority(150)? main character behavior, honestly ๐Ÿ”ฅ


๐Ÿ’€ SEE ALSO ๐Ÿ’€

cups-files.conf(5), cupsd.conf(5), cupsd(8), cupsfilter(8), mime.convs(5), CUPS Online Help (http://localhost:631/help)

go read them, bestie, the whole cinematic universe is connected ๐Ÿฆ‹


Copyright ยฉ 2020-2024 by OpenPrinting.


okay that's the whole page, no notes ๐Ÿ’– lowkey this one ate and left no crumbs. iykyk ๐ŸŽ€

and that's a wrap on the CUPS era, bestie โ€” this page came straight out of the 2021-02-28 release of CUPS (the OpenPrinting edition, obviously ๐Ÿ‘‘). go forth and correctly identify your file types, you absolute icon ๐Ÿ’…โœจ๐ŸŒธ

๐Ÿ“ฆ where this page comes from