{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.MIME
   Copyright   : Copyright (C) 2011-2020 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

Mime type lookup.
-}
module Text.Pandoc.MIME ( MimeType, getMimeType, getMimeTypeDef,
                          extensionFromMimeType, mediaCategory ) where
import Data.List (isPrefixOf, isSuffixOf)
import qualified Data.Map as M
import qualified Data.Text as T
import Data.Maybe (fromMaybe, listToMaybe)
import Data.Tuple (swap)
import System.FilePath

type MimeType = T.Text

-- | Determine mime type appropriate for file path.
getMimeType :: FilePath -> Maybe MimeType
getMimeType :: FilePath -> Maybe MimeType
getMimeType FilePath
fp
  -- ODT
  | FilePath
fp FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
"layout-cache" =
        MimeType -> Maybe MimeType
forall a. a -> Maybe a
Just MimeType
"application/binary"
  | FilePath
"Formula-" FilePath -> FilePath -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` FilePath
fp Bool -> Bool -> Bool
&& FilePath
"/" FilePath -> FilePath -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` FilePath
fp =
        MimeType -> Maybe MimeType
forall a. a -> Maybe a
Just MimeType
"application/vnd.oasis.opendocument.formula"
  -- generic
  | Bool
otherwise = MimeType -> Map MimeType MimeType -> Maybe MimeType
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (MimeType -> MimeType
T.toLower (MimeType -> MimeType) -> MimeType -> MimeType
forall a b. (a -> b) -> a -> b
$ Int -> MimeType -> MimeType
T.drop Int
1 (MimeType -> MimeType) -> MimeType -> MimeType
forall a b. (a -> b) -> a -> b
$ FilePath -> MimeType
T.pack (FilePath -> MimeType) -> FilePath -> MimeType
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
takeExtension FilePath
fp) Map MimeType MimeType
mimeTypes

-- | Determime mime type appropriate for file path, defaulting to
-- “application/octet-stream” if nothing else fits.
getMimeTypeDef :: FilePath -> MimeType
getMimeTypeDef :: FilePath -> MimeType
getMimeTypeDef = MimeType -> Maybe MimeType -> MimeType
forall a. a -> Maybe a -> a
fromMaybe MimeType
"application/octet-stream" (Maybe MimeType -> MimeType)
-> (FilePath -> Maybe MimeType) -> FilePath -> MimeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Maybe MimeType
getMimeType

extensionFromMimeType :: MimeType -> Maybe T.Text
extensionFromMimeType :: MimeType -> Maybe MimeType
extensionFromMimeType MimeType
mimetype =
  MimeType -> Map MimeType MimeType -> Maybe MimeType
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ((Char -> Bool) -> MimeType -> MimeType
T.takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
';') MimeType
mimetype) Map MimeType MimeType
reverseMimeTypes
  -- note:  we just look up the basic mime type, dropping the content-encoding etc.

-- | Determine general media category for file path, e.g.
--
-- prop> mediaCategory "foo.jpg" = Just "image"
mediaCategory :: FilePath -> Maybe T.Text
mediaCategory :: FilePath -> Maybe MimeType
mediaCategory FilePath
fp = FilePath -> Maybe MimeType
getMimeType FilePath
fp Maybe MimeType -> (MimeType -> Maybe MimeType) -> Maybe MimeType
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [MimeType] -> Maybe MimeType
forall a. [a] -> Maybe a
listToMaybe ([MimeType] -> Maybe MimeType)
-> (MimeType -> [MimeType]) -> MimeType -> Maybe MimeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MimeType -> MimeType -> [MimeType]
T.splitOn MimeType
"/"

reverseMimeTypes :: M.Map MimeType T.Text
reverseMimeTypes :: Map MimeType MimeType
reverseMimeTypes = [(MimeType, MimeType)] -> Map MimeType MimeType
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(MimeType, MimeType)] -> Map MimeType MimeType)
-> [(MimeType, MimeType)] -> Map MimeType MimeType
forall a b. (a -> b) -> a -> b
$ ((MimeType, MimeType) -> (MimeType, MimeType))
-> [(MimeType, MimeType)] -> [(MimeType, MimeType)]
forall a b. (a -> b) -> [a] -> [b]
map (MimeType, MimeType) -> (MimeType, MimeType)
forall a b. (a, b) -> (b, a)
swap [(MimeType, MimeType)]
mimeTypesList

mimeTypes :: M.Map T.Text MimeType
mimeTypes :: Map MimeType MimeType
mimeTypes = [(MimeType, MimeType)] -> Map MimeType MimeType
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(MimeType, MimeType)]
mimeTypesList

-- | Collection of common mime types.
-- Except for first entry, list borrowed from
-- <https://github.com/Happstack/happstack-server/blob/master/src/Happstack/Server/FileServe/BuildingBlocks.hs happstack-server>
mimeTypesList :: [(T.Text, MimeType)]
mimeTypesList :: [(MimeType, MimeType)]
mimeTypesList =
           [(MimeType
"cpt",MimeType
"image/x-corelphotopaint")
           ,(MimeType
"gz",MimeType
"application/x-gzip")
           ,(MimeType
"cabal",MimeType
"application/x-cabal")
           ,(MimeType
"%",MimeType
"application/x-trash")
           ,(MimeType
"323",MimeType
"text/h323")
           ,(MimeType
"3gp",MimeType
"video/3gpp")
           ,(MimeType
"7z",MimeType
"application/x-7z-compressed")
           ,(MimeType
"abw",MimeType
"application/x-abiword")
           ,(MimeType
"ai",MimeType
"application/postscript")
           ,(MimeType
"aif",MimeType
"audio/x-aiff")
           ,(MimeType
"aifc",MimeType
"audio/x-aiff")
           ,(MimeType
"aiff",MimeType
"audio/x-aiff")
           ,(MimeType
"alc",MimeType
"chemical/x-alchemy")
           ,(MimeType
"art",MimeType
"image/x-jg")
           ,(MimeType
"asc",MimeType
"text/plain")
           ,(MimeType
"asf",MimeType
"video/x-ms-asf")
           ,(MimeType
"asn",MimeType
"chemical/x-ncbi-asn1")
           ,(MimeType
"aso",MimeType
"chemical/x-ncbi-asn1-binary")
           ,(MimeType
"asx",MimeType
"video/x-ms-asf")
           ,(MimeType
"atom",MimeType
"application/atom")
           ,(MimeType
"atomcat",MimeType
"application/atomcat+xml")
           ,(MimeType
"atomsrv",MimeType
"application/atomserv+xml")
           ,(MimeType
"au",MimeType
"audio/basic")
           ,(MimeType
"avi",MimeType
"video/x-msvideo")
           ,(MimeType
"b",MimeType
"chemical/x-molconn-Z")
           ,(MimeType
"bak",MimeType
"application/x-trash")
           ,(MimeType
"bat",MimeType
"application/x-msdos-program")
           ,(MimeType
"bcpio",MimeType
"application/x-bcpio")
           ,(MimeType
"bib",MimeType
"text/x-bibtex")
           ,(MimeType
"bin",MimeType
"application/octet-stream")
           ,(MimeType
"bmp",MimeType
"image/x-ms-bmp")
           ,(MimeType
"boo",MimeType
"text/x-boo")
           ,(MimeType
"book",MimeType
"application/x-maker")
           ,(MimeType
"bsd",MimeType
"chemical/x-crossfire")
           ,(MimeType
"c",MimeType
"text/x-csrc")
           ,(MimeType
"c++",MimeType
"text/x-c++src")
           ,(MimeType
"c3d",MimeType
"chemical/x-chem3d")
           ,(MimeType
"cab",MimeType
"application/x-cab")
           ,(MimeType
"cac",MimeType
"chemical/x-cache")
           ,(MimeType
"cache",MimeType
"chemical/x-cache")
           ,(MimeType
"cap",MimeType
"application/cap")
           ,(MimeType
"cascii",MimeType
"chemical/x-cactvs-binary")
           ,(MimeType
"cat",MimeType
"application/vnd.ms-pki.seccat")
           ,(MimeType
"cbin",MimeType
"chemical/x-cactvs-binary")
           ,(MimeType
"cbr",MimeType
"application/x-cbr")
           ,(MimeType
"cbz",MimeType
"application/x-cbz")
           ,(MimeType
"cc",MimeType
"text/x-c++src")
           ,(MimeType
"cdf",MimeType
"application/x-cdf")
           ,(MimeType
"cdr",MimeType
"image/x-coreldraw")
           ,(MimeType
"cdt",MimeType
"image/x-coreldrawtemplate")
           ,(MimeType
"cdx",MimeType
"chemical/x-cdx")
           ,(MimeType
"cdy",MimeType
"application/vnd.cinderella")
           ,(MimeType
"cef",MimeType
"chemical/x-cxf")
           ,(MimeType
"cer",MimeType
"chemical/x-cerius")
           ,(MimeType
"chm",MimeType
"chemical/x-chemdraw")
           ,(MimeType
"chrt",MimeType
"application/x-kchart")
           ,(MimeType
"cif",MimeType
"chemical/x-cif")
           ,(MimeType
"class",MimeType
"application/java-vm")
           ,(MimeType
"cls",MimeType
"text/x-tex")
           ,(MimeType
"cmdf",MimeType
"chemical/x-cmdf")
           ,(MimeType
"cml",MimeType
"chemical/x-cml")
           ,(MimeType
"cod",MimeType
"application/vnd.rim.cod")
           ,(MimeType
"com",MimeType
"application/x-msdos-program")
           ,(MimeType
"cpa",MimeType
"chemical/x-compass")
           ,(MimeType
"cpio",MimeType
"application/x-cpio")
           ,(MimeType
"cpp",MimeType
"text/x-c++src")
           ,(MimeType
"cpt",MimeType
"application/mac-compactpro")
           ,(MimeType
"crl",MimeType
"application/x-pkcs7-crl")
           ,(MimeType
"crt",MimeType
"application/x-x509-ca-cert")
           ,(MimeType
"csf",MimeType
"chemical/x-cache-csf")
           ,(MimeType
"csh",MimeType
"application/x-csh")
           ,(MimeType
"csm",MimeType
"chemical/x-csml")
           ,(MimeType
"csml",MimeType
"chemical/x-csml")
           ,(MimeType
"css",MimeType
"text/css")
           ,(MimeType
"csv",MimeType
"text/csv")
           ,(MimeType
"ctab",MimeType
"chemical/x-cactvs-binary")
           ,(MimeType
"ctx",MimeType
"chemical/x-ctx")
           ,(MimeType
"cu",MimeType
"application/cu-seeme")
           ,(MimeType
"cub",MimeType
"chemical/x-gaussian-cube")
           ,(MimeType
"cxf",MimeType
"chemical/x-cxf")
           ,(MimeType
"cxx",MimeType
"text/x-c++src")
           ,(MimeType
"d",MimeType
"text/x-dsrc")
           ,(MimeType
"dat",MimeType
"chemical/x-mopac-input")
           ,(MimeType
"dcr",MimeType
"application/x-director")
           ,(MimeType
"deb",MimeType
"application/x-debian-package")
           ,(MimeType
"dif",MimeType
"video/dv")
           ,(MimeType
"diff",MimeType
"text/x-diff")
           ,(MimeType
"dir",MimeType
"application/x-director")
           ,(MimeType
"djv",MimeType
"image/vnd.djvu")
           ,(MimeType
"djvu",MimeType
"image/vnd.djvu")
           ,(MimeType
"dl",MimeType
"video/dl")
           ,(MimeType
"dll",MimeType
"application/x-msdos-program")
           ,(MimeType
"dmg",MimeType
"application/x-apple-diskimage")
           ,(MimeType
"dms",MimeType
"application/x-dms")
           ,(MimeType
"doc",MimeType
"application/msword")
           ,(MimeType
"dot",MimeType
"application/msword")
           ,(MimeType
"dv",MimeType
"video/dv")
           ,(MimeType
"dvi",MimeType
"application/x-dvi")
           ,(MimeType
"dx",MimeType
"chemical/x-jcamp-dx")
           ,(MimeType
"dxr",MimeType
"application/x-director")
           ,(MimeType
"emb",MimeType
"chemical/x-embl-dl-nucleotide")
           ,(MimeType
"embl",MimeType
"chemical/x-embl-dl-nucleotide")
           ,(MimeType
"emf",MimeType
"image/x-emf")
           ,(MimeType
"emz",MimeType
"application/x-msmetafile")
           ,(MimeType
"eml",MimeType
"message/rfc822")
           ,(MimeType
"ent",MimeType
"chemical/x-ncbi-asn1-ascii")
           ,(MimeType
"eot",MimeType
"application/vnd.ms-fontobject")
           ,(MimeType
"eps",MimeType
"application/eps")
           ,(MimeType
"etx",MimeType
"text/x-setext")
           ,(MimeType
"exe",MimeType
"application/x-msdos-program")
           ,(MimeType
"ez",MimeType
"application/andrew-inset")
           ,(MimeType
"fb",MimeType
"application/x-maker")
           ,(MimeType
"fbdoc",MimeType
"application/x-maker")
           ,(MimeType
"fch",MimeType
"chemical/x-gaussian-checkpoint")
           ,(MimeType
"fchk",MimeType
"chemical/x-gaussian-checkpoint")
           ,(MimeType
"fig",MimeType
"application/x-xfig")
           ,(MimeType
"flac",MimeType
"application/x-flac")
           ,(MimeType
"fli",MimeType
"video/fli")
           ,(MimeType
"fm",MimeType
"application/x-maker")
           ,(MimeType
"frame",MimeType
"application/x-maker")
           ,(MimeType
"frm",MimeType
"application/x-maker")
           ,(MimeType
"fs",MimeType
"text/plain")
           ,(MimeType
"gal",MimeType
"chemical/x-gaussian-log")
           ,(MimeType
"gam",MimeType
"chemical/x-gamess-input")
           ,(MimeType
"gamin",MimeType
"chemical/x-gamess-input")
           ,(MimeType
"gau",MimeType
"chemical/x-gaussian-input")
           ,(MimeType
"gcd",MimeType
"text/x-pcs-gcd")
           ,(MimeType
"gcf",MimeType
"application/x-graphing-calculator")
           ,(MimeType
"gcg",MimeType
"chemical/x-gcg8-sequence")
           ,(MimeType
"gen",MimeType
"chemical/x-genbank")
           ,(MimeType
"gf",MimeType
"application/x-tex-gf")
           ,(MimeType
"gif",MimeType
"image/gif")
           ,(MimeType
"gjc",MimeType
"chemical/x-gaussian-input")
           ,(MimeType
"gjf",MimeType
"chemical/x-gaussian-input")
           ,(MimeType
"gl",MimeType
"video/gl")
           ,(MimeType
"glsl",MimeType
"text/plain")
           ,(MimeType
"gnumeric",MimeType
"application/x-gnumeric")
           ,(MimeType
"gpt",MimeType
"chemical/x-mopac-graph")
           ,(MimeType
"gsf",MimeType
"application/x-font")
           ,(MimeType
"gsm",MimeType
"audio/x-gsm")
           ,(MimeType
"gtar",MimeType
"application/x-gtar")
           ,(MimeType
"h",MimeType
"text/x-chdr")
           ,(MimeType
"h++",MimeType
"text/x-c++hdr")
           ,(MimeType
"hdf",MimeType
"application/x-hdf")
           ,(MimeType
"hh",MimeType
"text/x-c++hdr")
           ,(MimeType
"hin",MimeType
"chemical/x-hin")
           ,(MimeType
"hpp",MimeType
"text/x-c++hdr")
           ,(MimeType
"hqx",MimeType
"application/mac-binhex40")
           ,(MimeType
"hs",MimeType
"text/x-haskell")
           ,(MimeType
"hta",MimeType
"application/hta")
           ,(MimeType
"htc",MimeType
"text/x-component")
           ,(MimeType
"htm",MimeType
"text/html")
           ,(MimeType
"html",MimeType
"text/html")
           ,(MimeType
"hxx",MimeType
"text/x-c++hdr")
           ,(MimeType
"ica",MimeType
"application/x-ica")
           ,(MimeType
"ice",MimeType
"x-conference/x-cooltalk")
           ,(MimeType
"ico",MimeType
"image/x-icon")
           ,(MimeType
"ics",MimeType
"text/calendar")
           ,(MimeType
"icz",MimeType
"text/calendar")
           ,(MimeType
"ief",MimeType
"image/ief")
           ,(MimeType
"iges",MimeType
"model/iges")
           ,(MimeType
"igs",MimeType
"model/iges")
           ,(MimeType
"iii",MimeType
"application/x-iphone")
           ,(MimeType
"inp",MimeType
"chemical/x-gamess-input")
           ,(MimeType
"ins",MimeType
"application/x-internet-signup")
           ,(MimeType
"iso",MimeType
"application/x-iso9660-image")
           ,(MimeType
"isp",MimeType
"application/x-internet-signup")
           ,(MimeType
"ist",MimeType
"chemical/x-isostar")
           ,(MimeType
"istr",MimeType
"chemical/x-isostar")
           ,(MimeType
"jad",MimeType
"text/vnd.sun.j2me.app-descriptor")
           ,(MimeType
"jar",MimeType
"application/java-archive")
           ,(MimeType
"java",MimeType
"text/x-java")
           ,(MimeType
"jdx",MimeType
"chemical/x-jcamp-dx")
           ,(MimeType
"jmz",MimeType
"application/x-jmol")
           ,(MimeType
"jng",MimeType
"image/x-jng")
           ,(MimeType
"jnlp",MimeType
"application/x-java-jnlp-file")
           ,(MimeType
"jpe",MimeType
"image/jpeg")
           ,(MimeType
"jpeg",MimeType
"image/jpeg")
           ,(MimeType
"jfif",MimeType
"image/jpeg")
           ,(MimeType
"jpg",MimeType
"image/jpeg")
           ,(MimeType
"js",MimeType
"application/javascript")
           ,(MimeType
"kar",MimeType
"audio/midi")
           ,(MimeType
"key",MimeType
"application/pgp-keys")
           ,(MimeType
"kil",MimeType
"application/x-killustrator")
           ,(MimeType
"kin",MimeType
"chemical/x-kinemage")
           ,(MimeType
"kml",MimeType
"application/vnd.google-earth.kml+xml")
           ,(MimeType
"kmz",MimeType
"application/vnd.google-earth.kmz")
           ,(MimeType
"kpr",MimeType
"application/x-kpresenter")
           ,(MimeType
"kpt",MimeType
"application/x-kpresenter")
           ,(MimeType
"ksp",MimeType
"application/x-kspread")
           ,(MimeType
"kwd",MimeType
"application/x-kword")
           ,(MimeType
"kwt",MimeType
"application/x-kword")
           ,(MimeType
"latex",MimeType
"application/x-latex")
           ,(MimeType
"lha",MimeType
"application/x-lha")
           ,(MimeType
"lhs",MimeType
"text/x-literate-haskell")
           ,(MimeType
"lsf",MimeType
"video/x-la-asf")
           ,(MimeType
"lsx",MimeType
"video/x-la-asf")
           ,(MimeType
"ltx",MimeType
"text/x-tex")
           ,(MimeType
"lyx",MimeType
"application/x-lyx")
           ,(MimeType
"lzh",MimeType
"application/x-lzh")
           ,(MimeType
"lzx",MimeType
"application/x-lzx")
           ,(MimeType
"m3u",MimeType
"audio/mpegurl")
           ,(MimeType
"m4a",MimeType
"audio/mpeg")
           ,(MimeType
"m4v",MimeType
"video/x-m4v")
           ,(MimeType
"maker",MimeType
"application/x-maker")
           ,(MimeType
"man",MimeType
"application/x-troff-man")
           ,(MimeType
"mcif",MimeType
"chemical/x-mmcif")
           ,(MimeType
"mcm",MimeType
"chemical/x-macmolecule")
           ,(MimeType
"mdb",MimeType
"application/msaccess")
           ,(MimeType
"me",MimeType
"application/x-troff-me")
           ,(MimeType
"mesh",MimeType
"model/mesh")
           ,(MimeType
"mid",MimeType
"audio/midi")
           ,(MimeType
"midi",MimeType
"audio/midi")
           ,(MimeType
"mif",MimeType
"application/x-mif")
           ,(MimeType
"mm",MimeType
"application/x-freemind")
           ,(MimeType
"mmd",MimeType
"chemical/x-macromodel-input")
           ,(MimeType
"mmf",MimeType
"application/vnd.smaf")
           ,(MimeType
"mml",MimeType
"text/mathml")
           ,(MimeType
"mmod",MimeType
"chemical/x-macromodel-input")
           ,(MimeType
"mng",MimeType
"video/x-mng")
           ,(MimeType
"moc",MimeType
"text/x-moc")
           ,(MimeType
"mol",MimeType
"chemical/x-mdl-molfile")
           ,(MimeType
"mol2",MimeType
"chemical/x-mol2")
           ,(MimeType
"moo",MimeType
"chemical/x-mopac-out")
           ,(MimeType
"mop",MimeType
"chemical/x-mopac-input")
           ,(MimeType
"mopcrt",MimeType
"chemical/x-mopac-input")
           ,(MimeType
"mov",MimeType
"video/quicktime")
           ,(MimeType
"movie",MimeType
"video/x-sgi-movie")
           ,(MimeType
"mp2",MimeType
"audio/mpeg")
           ,(MimeType
"mp3",MimeType
"audio/mpeg")
           ,(MimeType
"mp4",MimeType
"video/mp4")
           ,(MimeType
"mpc",MimeType
"chemical/x-mopac-input")
           ,(MimeType
"mpe",MimeType
"video/mpeg")
           ,(MimeType
"mpeg",MimeType
"video/mpeg")
           ,(MimeType
"mpega",MimeType
"audio/mpeg")
           ,(MimeType
"mpg",MimeType
"video/mpeg")
           ,(MimeType
"mpga",MimeType
"audio/mpeg")
           ,(MimeType
"ms",MimeType
"application/x-troff-ms")
           ,(MimeType
"msh",MimeType
"model/mesh")
           ,(MimeType
"msi",MimeType
"application/x-msi")
           ,(MimeType
"mvb",MimeType
"chemical/x-mopac-vib")
           ,(MimeType
"mxu",MimeType
"video/vnd.mpegurl")
           ,(MimeType
"nb",MimeType
"application/mathematica")
           ,(MimeType
"nc",MimeType
"application/x-netcdf")
           ,(MimeType
"nwc",MimeType
"application/x-nwc")
           ,(MimeType
"o",MimeType
"application/x-object")
           ,(MimeType
"oda",MimeType
"application/oda")
           ,(MimeType
"odb",MimeType
"application/vnd.oasis.opendocument.database")
           ,(MimeType
"odc",MimeType
"application/vnd.oasis.opendocument.chart")
           ,(MimeType
"odf",MimeType
"application/vnd.oasis.opendocument.formula")
           ,(MimeType
"odg",MimeType
"application/vnd.oasis.opendocument.graphics")
           ,(MimeType
"odi",MimeType
"application/vnd.oasis.opendocument.image")
           ,(MimeType
"odm",MimeType
"application/vnd.oasis.opendocument.text-master")
           ,(MimeType
"odp",MimeType
"application/vnd.oasis.opendocument.presentation")
           ,(MimeType
"ods",MimeType
"application/vnd.oasis.opendocument.spreadsheet")
           ,(MimeType
"odt",MimeType
"application/vnd.oasis.opendocument.text")
           ,(MimeType
"oga",MimeType
"audio/ogg")
           ,(MimeType
"ogg",MimeType
"application/ogg")
           ,(MimeType
"ogv",MimeType
"video/ogg")
           ,(MimeType
"ogx",MimeType
"application/ogg")
           ,(MimeType
"old",MimeType
"application/x-trash")
           ,(MimeType
"opus",MimeType
"audio/ogg")
           ,(MimeType
"otg",MimeType
"application/vnd.oasis.opendocument.graphics-template")
           ,(MimeType
"oth",MimeType
"application/vnd.oasis.opendocument.text-web")
           ,(MimeType
"otp",MimeType
"application/vnd.oasis.opendocument.presentation-template")
           ,(MimeType
"ots",MimeType
"application/vnd.oasis.opendocument.spreadsheet-template")
           ,(MimeType
"otf",MimeType
"application/vnd.ms-opentype")
           ,(MimeType
"ott",MimeType
"application/vnd.oasis.opendocument.text-template")
           ,(MimeType
"oza",MimeType
"application/x-oz-application")
           ,(MimeType
"p",MimeType
"text/x-pascal")
           ,(MimeType
"p7r",MimeType
"application/x-pkcs7-certreqresp")
           ,(MimeType
"pac",MimeType
"application/x-ns-proxy-autoconfig")
           ,(MimeType
"pas",MimeType
"text/x-pascal")
           ,(MimeType
"pat",MimeType
"image/x-coreldrawpattern")
           ,(MimeType
"patch",MimeType
"text/x-diff")
           ,(MimeType
"pbm",MimeType
"image/x-portable-bitmap")
           ,(MimeType
"pcap",MimeType
"application/cap")
           ,(MimeType
"pcf",MimeType
"application/x-font")
           ,(MimeType
"pcf.Z",MimeType
"application/x-font")
           ,(MimeType
"pcx",MimeType
"image/pcx")
           ,(MimeType
"pdb",MimeType
"chemical/x-pdb")
           ,(MimeType
"pdf",MimeType
"application/pdf")
           ,(MimeType
"pfa",MimeType
"application/x-font")
           ,(MimeType
"pfb",MimeType
"application/x-font")
           ,(MimeType
"pgm",MimeType
"image/x-portable-graymap")
           ,(MimeType
"pgn",MimeType
"application/x-chess-pgn")
           ,(MimeType
"pgp",MimeType
"application/pgp-signature")
           ,(MimeType
"php",MimeType
"application/x-httpd-php")
           ,(MimeType
"php3",MimeType
"application/x-httpd-php3")
           ,(MimeType
"php3p",MimeType
"application/x-httpd-php3-preprocessed")
           ,(MimeType
"php4",MimeType
"application/x-httpd-php4")
           ,(MimeType
"phps",MimeType
"application/x-httpd-php-source")
           ,(MimeType
"pht",MimeType
"application/x-httpd-php")
           ,(MimeType
"phtml",MimeType
"application/x-httpd-php")
           ,(MimeType
"pk",MimeType
"application/x-tex-pk")
           ,(MimeType
"pl",MimeType
"text/x-perl")
           ,(MimeType
"pls",MimeType
"audio/x-scpls")
           ,(MimeType
"pm",MimeType
"text/x-perl")
           ,(MimeType
"png",MimeType
"image/png")
           ,(MimeType
"pnm",MimeType
"image/x-portable-anymap")
           ,(MimeType
"pot",MimeType
"text/plain")
           ,(MimeType
"ppm",MimeType
"image/x-portable-pixmap")
           ,(MimeType
"pps",MimeType
"application/vnd.ms-powerpoint")
           ,(MimeType
"ppt",MimeType
"application/vnd.ms-powerpoint")
           ,(MimeType
"prf",MimeType
"application/pics-rules")
           ,(MimeType
"prt",MimeType
"chemical/x-ncbi-asn1-ascii")
           ,(MimeType
"ps",MimeType
"application/postscript")
           ,(MimeType
"psd",MimeType
"image/x-photoshop")
           ,(MimeType
"py",MimeType
"text/x-python")
           ,(MimeType
"pyc",MimeType
"application/x-python-code")
           ,(MimeType
"pyo",MimeType
"application/x-python-code")
           ,(MimeType
"qt",MimeType
"video/quicktime")
           ,(MimeType
"qtl",MimeType
"application/x-quicktimeplayer")
           ,(MimeType
"ra",MimeType
"audio/x-pn-realaudio")
           ,(MimeType
"ram",MimeType
"audio/x-pn-realaudio")
           ,(MimeType
"rar",MimeType
"application/rar")
           ,(MimeType
"ras",MimeType
"image/x-cmu-raster")
           ,(MimeType
"rd",MimeType
"chemical/x-mdl-rdfile")
           ,(MimeType
"rdf",MimeType
"application/rdf+xml")
           ,(MimeType
"rgb",MimeType
"image/x-rgb")
           ,(MimeType
"rhtml",MimeType
"application/x-httpd-eruby")
           ,(MimeType
"rm",MimeType
"audio/x-pn-realaudio")
           ,(MimeType
"roff",MimeType
"application/x-troff")
           ,(MimeType
"ros",MimeType
"chemical/x-rosdal")
           ,(MimeType
"rpm",MimeType
"application/x-redhat-package-manager")
           ,(MimeType
"rss",MimeType
"application/rss+xml")
           ,(MimeType
"rtf",MimeType
"application/rtf")
           ,(MimeType
"rtx",MimeType
"text/richtext")
           ,(MimeType
"rxn",MimeType
"chemical/x-mdl-rxnfile")
           ,(MimeType
"sct",MimeType
"text/scriptlet")
           ,(MimeType
"sd",MimeType
"chemical/x-mdl-sdfile")
           ,(MimeType
"sd2",MimeType
"audio/x-sd2")
           ,(MimeType
"sda",MimeType
"application/vnd.stardivision.draw")
           ,(MimeType
"sdc",MimeType
"application/vnd.stardivision.calc")
           ,(MimeType
"sdd",MimeType
"application/vnd.stardivision.impress")
           ,(MimeType
"sdf",MimeType
"application/vnd.stardivision.math")
           ,(MimeType
"sds",MimeType
"application/vnd.stardivision.chart")
           ,(MimeType
"sdw",MimeType
"application/vnd.stardivision.writer")
           ,(MimeType
"ser",MimeType
"application/java-serialized-object")
           ,(MimeType
"sgf",MimeType
"application/x-go-sgf")
           ,(MimeType
"sgl",MimeType
"application/vnd.stardivision.writer-global")
           ,(MimeType
"sh",MimeType
"application/x-sh")
           ,(MimeType
"shar",MimeType
"application/x-shar")
           ,(MimeType
"shtml",MimeType
"text/html")
           ,(MimeType
"sid",MimeType
"audio/prs.sid")
           ,(MimeType
"sik",MimeType
"application/x-trash")
           ,(MimeType
"silo",MimeType
"model/mesh")
           ,(MimeType
"sis",MimeType
"application/vnd.symbian.install")
           ,(MimeType
"sisx",MimeType
"x-epoc/x-sisx-app")
           ,(MimeType
"sit",MimeType
"application/x-stuffit")
           ,(MimeType
"sitx",MimeType
"application/x-stuffit")
           ,(MimeType
"skd",MimeType
"application/x-koan")
           ,(MimeType
"skm",MimeType
"application/x-koan")
           ,(MimeType
"skp",MimeType
"application/x-koan")
           ,(MimeType
"skt",MimeType
"application/x-koan")
           ,(MimeType
"smi",MimeType
"application/smil")
           ,(MimeType
"smil",MimeType
"application/smil")
           ,(MimeType
"snd",MimeType
"audio/basic")
           ,(MimeType
"spc",MimeType
"chemical/x-galactic-spc")
           ,(MimeType
"spl",MimeType
"application/futuresplash")
           ,(MimeType
"spx",MimeType
"audio/ogg")
           ,(MimeType
"src",MimeType
"application/x-wais-source")
           ,(MimeType
"stc",MimeType
"application/vnd.sun.xml.calc.template")
           ,(MimeType
"std",MimeType
"application/vnd.sun.xml.draw.template")
           ,(MimeType
"sti",MimeType
"application/vnd.sun.xml.impress.template")
           ,(MimeType
"stl",MimeType
"application/vnd.ms-pki.stl")
           ,(MimeType
"stw",MimeType
"application/vnd.sun.xml.writer.template")
           ,(MimeType
"sty",MimeType
"text/x-tex")
           ,(MimeType
"sv4cpio",MimeType
"application/x-sv4cpio")
           ,(MimeType
"sv4crc",MimeType
"application/x-sv4crc")
           ,(MimeType
"svg",MimeType
"image/svg+xml")
           -- removed for now, since it causes problems with
           -- extensionFromMimeType: see #2183.
           -- ,("svgz","image/svg+xml")
           ,(MimeType
"sw",MimeType
"chemical/x-swissprot")
           ,(MimeType
"swf",MimeType
"application/x-shockwave-flash")
           ,(MimeType
"swfl",MimeType
"application/x-shockwave-flash")
           ,(MimeType
"sxc",MimeType
"application/vnd.sun.xml.calc")
           ,(MimeType
"sxd",MimeType
"application/vnd.sun.xml.draw")
           ,(MimeType
"sxg",MimeType
"application/vnd.sun.xml.writer.global")
           ,(MimeType
"sxi",MimeType
"application/vnd.sun.xml.impress")
           ,(MimeType
"sxm",MimeType
"application/vnd.sun.xml.math")
           ,(MimeType
"sxw",MimeType
"application/vnd.sun.xml.writer")
           ,(MimeType
"t",MimeType
"application/x-troff")
           ,(MimeType
"tar",MimeType
"application/x-tar")
           ,(MimeType
"taz",MimeType
"application/x-gtar")
           ,(MimeType
"tcl",MimeType
"application/x-tcl")
           ,(MimeType
"tex",MimeType
"text/x-tex")
           ,(MimeType
"texi",MimeType
"application/x-texinfo")
           ,(MimeType
"texinfo",MimeType
"application/x-texinfo")
           ,(MimeType
"text",MimeType
"text/plain")
           ,(MimeType
"tgf",MimeType
"chemical/x-mdl-tgf")
           ,(MimeType
"tgz",MimeType
"application/x-gtar")
           ,(MimeType
"tif",MimeType
"image/tiff")
           ,(MimeType
"tiff",MimeType
"image/tiff")
           ,(MimeType
"tk",MimeType
"text/x-tcl")
           ,(MimeType
"tm",MimeType
"text/texmacs")
           ,(MimeType
"torrent",MimeType
"application/x-bittorrent")
           ,(MimeType
"tr",MimeType
"application/x-troff")
           ,(MimeType
"ts",MimeType
"text/texmacs")
           ,(MimeType
"tsp",MimeType
"application/dsptype")
           ,(MimeType
"tsv",MimeType
"text/tab-separated-values")
           ,(MimeType
"ttf",MimeType
"application/font-sfnt")
           ,(MimeType
"txt",MimeType
"text/plain")
           ,(MimeType
"udeb",MimeType
"application/x-debian-package")
           ,(MimeType
"uls",MimeType
"text/iuls")
           ,(MimeType
"ustar",MimeType
"application/x-ustar")
           ,(MimeType
"val",MimeType
"chemical/x-ncbi-asn1-binary")
           ,(MimeType
"vcd",MimeType
"application/x-cdlink")
           ,(MimeType
"vcf",MimeType
"text/x-vcard")
           ,(MimeType
"vcs",MimeType
"text/x-vcalendar")
           ,(MimeType
"vmd",MimeType
"chemical/x-vmd")
           ,(MimeType
"vms",MimeType
"chemical/x-vamas-iso14976")
           ,(MimeType
"vrm",MimeType
"x-world/x-vrml")
           ,(MimeType
"vrml",MimeType
"model/vrml")
           ,(MimeType
"vs",MimeType
"text/plain")
           ,(MimeType
"vsd",MimeType
"application/vnd.visio")
           ,(MimeType
"vtt",MimeType
"text/vtt")
           ,(MimeType
"wad",MimeType
"application/x-doom")
           ,(MimeType
"wav",MimeType
"audio/x-wav")
           ,(MimeType
"wax",MimeType
"audio/x-ms-wax")
           ,(MimeType
"wbmp",MimeType
"image/vnd.wap.wbmp")
           ,(MimeType
"wbxml",MimeType
"application/vnd.wap.wbxml")
           ,(MimeType
"webm",MimeType
"video/webm")
           ,(MimeType
"webp",MimeType
"image/webp")
           ,(MimeType
"wk",MimeType
"application/x-123")
           ,(MimeType
"wm",MimeType
"video/x-ms-wm")
           ,(MimeType
"wma",MimeType
"audio/x-ms-wma")
           ,(MimeType
"wmd",MimeType
"application/x-ms-wmd")
           ,(MimeType
"wmf",MimeType
"image/x-wmf")
           ,(MimeType
"wml",MimeType
"text/vnd.wap.wml")
           ,(MimeType
"wmlc",MimeType
"application/vnd.wap.wmlc")
           ,(MimeType
"wmls",MimeType
"text/vnd.wap.wmlscript")
           ,(MimeType
"wmlsc",MimeType
"application/vnd.wap.wmlscriptc")
           ,(MimeType
"wmv",MimeType
"video/x-ms-wmv")
           ,(MimeType
"wmx",MimeType
"video/x-ms-wmx")
           ,(MimeType
"wmz",MimeType
"application/x-ms-wmz")
           ,(MimeType
"woff",MimeType
"application/font-woff")
           ,(MimeType
"woff2",MimeType
"font/woff2")
           ,(MimeType
"wp5",MimeType
"application/wordperfect5.1")
           ,(MimeType
"wpd",MimeType
"application/wordperfect")
           ,(MimeType
"wrl",MimeType
"model/vrml")
           ,(MimeType
"wsc",MimeType
"text/scriptlet")
           ,(MimeType
"wvx",MimeType
"video/x-ms-wvx")
           ,(MimeType
"wz",MimeType
"application/x-wingz")
           ,(MimeType
"xbm",MimeType
"image/x-xbitmap")
           ,(MimeType
"xcf",MimeType
"application/x-xcf")
           ,(MimeType
"xht",MimeType
"application/xhtml+xml")
           ,(MimeType
"xhtml",MimeType
"application/xhtml+xml")
           ,(MimeType
"xlb",MimeType
"application/vnd.ms-excel")
           ,(MimeType
"xls",MimeType
"application/vnd.ms-excel")
           ,(MimeType
"xlt",MimeType
"application/vnd.ms-excel")
           ,(MimeType
"xml",MimeType
"application/xml")
           ,(MimeType
"xpi",MimeType
"application/x-xpinstall")
           ,(MimeType
"xpm",MimeType
"image/x-xpixmap")
           ,(MimeType
"xsl",MimeType
"application/xml")
           ,(MimeType
"xtel",MimeType
"chemical/x-xtel")
           ,(MimeType
"xul",MimeType
"application/vnd.mozilla.xul+xml")
           ,(MimeType
"xwd",MimeType
"image/x-xwindowdump")
           ,(MimeType
"xyz",MimeType
"chemical/x-xyz")
           ,(MimeType
"zip",MimeType
"application/zip")
           ,(MimeType
"zmt",MimeType
"chemical/x-mopac-input")
           ]