A Multipurpose Internet Mail Extension (MIME) type identifies the format of a file. The MIME type enables applications to read the file. Applications such as Internet browsers and e-mail applications use the MIME type to handle files of different types. For example, an e-mail application can use the MIME type to detect what type of file is attached to an e-mail.
The Nautilus file manager uses MIME types to identify the type of a file. The file manager needs to know the MIME type of a file to perform the following tasks:
Open the file in an appropriate application
Display a string that describes the type of file
Display an appropriate icon to represent the file
Display a list of other applications that can open the file
It is sometimes necessary to work out the correct MIME type for a file. This is usually done by examining the file's name or contents and looking up the correct MIME type in a database. If you add a new application (that is, extend the database), you must make sure that other applications can recognize the files associated with the application. For example, you might want to add the following:
image/png files should be edited using the Gimp.
image/png files should be described in English as Portable Network Graphics files.
Files whose names end in .png should have the type image/png.
You can use a graphical editor (such as MIME-Editor to edit the
database, or you can do it manually by creating a file called
$XDG_DATA_HOME/mime/packages/Override.xml in the format described below.
For information on the XDG_ variables, see the Base Directory
Specification.
When your new application is installed, it should install a file with the application's name
in $XDG_DATA_DIRS/mime/packages. For example, running the
./configure && make install command with the Gimp will create
/usr/local/share/mime/packages/gimp.xml.
This file has the following format:
<?xml version=”1.0” encoding=”UTF-8”?>
<mime-info xmlns=”http://www.freedesktop.org/standards/shared-mime-info”>
<mime-type type=”image/png”>
<comment xml:lang=”en”>PNG image</comment>
<comment xml:lang=”af”>png bleed</comment>
...
<magic priority=”50”>
<match type=”string” value=”\x89PNG” offset=”0”/>
</magic>
<glob pattern=”*.png”/>
</mime-type>
</mime-info>
This provides a comment in two languages, a rule to recognize PNG files by their contents,
and a rule to recognize PNG files by their names. You can provide information about several types
in the single
file. You do not need to provide any
information which is also in the base package. application.xml
You can also add extra elements if they are namespaced to avoid conflicts. For example:
<desktop:can-edit-with>gimp.desktop</desktop:can-edit-with>
This indicates that the named desktop entry file describes an application that can edit image/png files.
Information added to the database should be static (for example, “The Gimp can edit PNG files.”), not configuration (for example, “The Gimp is the preferred editor for PNG files.”). For more information on storing configuration information, see the Shared Configuration System Spec.
After you have installed the
file, run the
update-mime-database command to rebuild the output files. This program checks
that the syntax of your file is correct and merges the information in it with the information in
the other XML files in the application.xml packages directory. It then puts the rules for
recognizing files into one set of files and the information about each type into other files (for
example, $XDG_DATA_DIR/mime/image/png.xml) where other programs can easily
access it.
When the application is uninstalled, the
file is removed. Run
application.xml update-mime-database again to remove the information from the database.