Adding and removing associations between mimetypes and applications is done with the following syntax in the mimeapps.list file:
[Added Associations] mimetype1=foo1.desktop;foo2.desktop;foo3.desktop; mimetype2=foo4.desktop; [Removed Associations] mimetype1=foo5.desktop;
[Added Associations] and [Removed Associations] groups may only appear in the non-desktop-specific files (ie: in files that are actually named "mimeapps.list").
The [Added Associations] group defines additional associations of applications with mimetypes, as if the .desktop file was listing this mimetype in the first place.
The [Removed Associations] group removes associations of applications with mimetypes, as if the .desktop file was NOT listing this mimetype in the first place.
Listing the same application for the same type in both the Added and Removed sections is invalid and may produce implementation-defined behaviour.
The order of the entries in the [Added Associations] entry for a given type should be in the "most preferred order", according to the implementation. As such, implementations should take care to preserve the order except in situations where they are explicitly intending to change it.
The adding and removal of associations only applies to desktop files in the current directory, or a later one (in precedence order). This means that additions and removals applied from the mimeapps.list file in $XDG_CONFIG_HOME, $XDG_CONFIG_DIRS and $XDG_DATA_HOME will override all existing desktop files, but that an addition or removal of an association using /usr/share/applications/mimeapps.list, for example, would be ignored if the desktop file of the named application was present in $XDG_DATA_HOME/applications. Put another way: added and removed associations can be thought of as equivalent to copying the desktop file from the next-in-precedence directory with respect to the directory containing the mimeapps.list (which may be the same directory) and tweaking its MimeType= line. If the same .desktop file appears again in a directory with higher precedence order, then this modified .desktop file with lower precedence would be ignored. If the addition or removal refers to a desktop file that doesn't exist at this precedence level, or a lower one, then the addition or removal is ignored, even if the desktop file exists in a high-precedence directory.
The suggested algorithm for listing (in preference order) the applications associated to a given mimetype is:
create an empty list for the results, and a temporary empty "blacklist"
visit each "mimeapps.list" file, in turn; a missing file is equivalent to an empty file
add to the results list any "Added Associations" in the mimeapps.list, excluding items on the blacklist
add to the blacklist any "Removed Associations" in mimeapps.list
add to the results list any .desktop file found in the same directory as the mimeapps.list which lists the given type in its MimeType= line, excluding any desktop files already in the blacklist. For directories based on XDG_CONFIG_HOME and XDG_CONFIG_DIRS, there are (by definition) no desktop files in the same directory.
add to the blacklist the names of any desktop files found in the same directory as the mimeapps.list file (which for directories based on XDG_CONFIG_HOME and XDG_CONFIG_DIRS, is none)
repeat the last four steps for each subsequent directory
The above process is repeated for each mimetype from the most specific to the least specific. Note in particular that an application "Added" with a more specific mime type will keep that association, even if it is "Removed" in a higher-precedence directory, using a less specific type.