Fedora 4.0 and MIME types

Disclaimer: These notes are my own in support of Fedora 4.0 in ACD -- and specifically how it deals with MIME along with Thunderbird and Firefox. Neither I or my organization are responsible for errors in this document or their consequences.

Updated 10/18/2005

Fedora 4.0 and MIME types

A few MIME related questions keep coming up -- primarily how to deal with .pdf files in a manner other than the Gnome default (which is to bring up evince which in turn brings up Xpdf). We also have issues dealing with other file associations.

As I understand it, Fedora 4.0 has gone to a different method of dealing with file associations. That is, Gnome 2.10 which comes with Fedora 4 has adopted the Freedesktop.org approach to mime types. Firefox as of recent versions works through Gnome for its mime types. So does the email reader, Thunderbird, and the desktop file manager, Nautilus. This has the advantage of a single point of maintenance for mime types which then affect all applications which go through Gnome.

OS control over MIME behavior

The directory /usr/share/mime-info seems to have two types of files -- .keys and .mime files. For PDF the configurations look like this:
  • gnome-vfs.mime: This file provides a mapping of a filename name to a file type. The section below defines files with a 3-letter extension ".pdf" to be mapped to the mime type "application/pdf". The .mime file for Gnome is read first, providing system defaults.
    application/pdf ext: pdf
    A way to change behavior is to add or edit entires. For example, editing the entry to look like this:
    application/pdf ext: pdf goo
    causes files with the ".goo" extension to be recognized as PDF documents within Gnome-aware applications.
  • gnome-vfs.keys: provides Gnome keys, but I'm not certain this file is used by Gnome 2.10+.
In the directory /usr/share/mime/packages there is a file called freedesktop.org.xml. Our entry for pdf (with the language-specific fields removed) looks like this:
  <mime-type type="application/pdf">
    <comment>PDF document</comment>
    <magic priority="50">
      <match value="%PDF-" type="string" offset="0"/>
    </magic>
    <glob pattern="*.pdf"/>
    <alias type="application/x-pdf"/>
  </mime-type>

The long and short of it is that to control a MIME association default, the file to edit seems to be the defaults.list file (in /usr/share/applications). Within this file are entries that control which application comes up for the given mime-type. For example, with PDF the entry looks like:

application/pdf=evince.desktop
evince is the Gnome document viewer. If we want the default to be Adobe Reader instead, we can change the entry to look like:
application/pdf=livna-acroread.desktop
The file livna-acroread.desktop is located in /usr/share/applications. Such a Gnome .desktop file also determines where the application appears in the Gnome pull-down menus.

Editing the file /usr/share/applications/mimeinfo.cache can affect which applications are authorized to handle a particular MIME type in Gnome 2.10+. For example, the entry for pdf looks like this:

application/pdf=evince.desktop;net-xpdf.desktop;livna-acroread.desktop;
       kde-kghostview.desktop;kde-kpdf.desktop;
I may decide that I don't want the KDE applications so I can edit the entry to look like:
application/pdf=livna-acroread.desktop;evince.desktop;net-xpdf.desktop;
(note that editing this and the defaults.list file may not have an affect on user accounts with a $HOME/.local/share/applications directory -- that directory may have corresponding files which override the system defaults).

Really, though, MIME behavior for Fedora 4.0 out of the box is probably best left to the end-use (see next section below).

User control over MIME behavior

Nautilus File Manager

In Nautilus, if you double-click on a .pdf file -- the default behavior in Fedora 4.0 is to launch Xpdf. Just as with Microsoft Windows, if you right click on the file, you get additional options than the Xpdf default. For example, you can select 'Open With' and then 'Open with "adobe reader"'.

The user can control behavior over MIME types with Nautilus by right clicking on an icon and selecting properties. For example, I can right-click on a pdf document and select properties to see something like this:

By changing the viewer here, subsequent double-clicks on .pdf files will open such files in the new viewer. For example, in Fedora 4.0, I wanted Adobe Reader to open my files, so I clicked on "Adobe Reader".

Behind the scenes, what happens are changes within a file $HOME/.local/share/applications/defaults.list. This probably overrides system defaults in /usr/share/applications/defaults.list. Changes are immediately recognized by the Nautilus file manager (without the user having to log out and in).

Firefox

Firefox may use a plugin to open a file type (as with the Adobe Reader plugin which opens pdf documents within the browser), or it may go to Gnome for the MIME association. For example, if the user right clicks on a .xls file in Nautilus and sets up the default viewer to be Crossover Office (as opposed to OpenOffice), when Firefox encounters a link to an XLS file,it will prompt the user to open or save the file. If the user selects the option to open the file, Firefox will open the file using Crossover Office (MSWORD.EXE).

Thunderbird should follow along with the same behavior. A .xls attachment would open in Crossover Office (MSWORD.EXE) rather than OpenOffice.

References