1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
|
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="mimetypes-0">
<title>MIME Types</title>
<anchor id="mimetypes-TBL-3"/>
<anchor id="mimetypes-TBL-6"/>
<anchor id="mimetypes-TBL-8"/>
<highlights>
<para>This chapter describes how applications detect MIME types, how to
register MIME types, and how to add applications to the GNOME
Desktop.</para>
</highlights>
<para>The purpose of this chapter is to make it easy for an administrator to
understand how to configure different parts of the MIME database and give an
general overview of the MIME system. Therefore we will
<emphasis>not</emphasis> attempt to go into details where it is not
necessary. For the gory details, it is recommended that you refer to the
<ulink url="http://www.freedesktop.org/Standards/shared-mime-info-spec">XDG
shared mime info specification</ulink>.</para>
<sect1 id="mimetypes-intro">
<title>Introduction to MIME Types</title>
<anchor id="mimetypes-1"/>
<indexterm>
<primary>MIME types</primary>
<secondary>introduction</secondary>
</indexterm>
<para>A <firstterm>Multipurpose Internet Mail Extension</firstterm>
[<acronym>MIME</acronym>] type identifies the format of a file.
Applications such as Internet browsers and email applications use the MIME
type of a file to decide which actions to perform on it. For example, an
email application can use the MIME type to detect the format of an
attachment and choose an appropriate viewer for the file, such as opening
a text document with <application>gedit</application>.</para>
<para>As another example, the <application>Nautilus</application> file
manager needs to know the MIME type of a file to perform the following
tasks:</para>
<itemizedlist>
<listitem>
<para>Open the file in an appropriate application.</para>
</listitem>
<listitem>
<para>Display a string that describes the type of file.</para>
</listitem>
<listitem>
<para>Display an appropriate icon to represent the file.</para>
</listitem>
<listitem>
<para>Display a list of other applications that can open the
file.</para>
</listitem>
</itemizedlist>
<para>MIME types were originally proposed as a standard for identifying
the message body of an e-mail message. Now, many systems use MIME types to
identify the format of arbitrary files on the file system. MIME types are
composed of a top-level <emphasis>media type</emphasis> followed by a
<emphasis>subtype identifier</emphasis>, separated by a forward slash
character, <quote><literal>/</literal></quote>. One example of a MIME type
is <literal>image/jpeg</literal>. The media type in this example is
<quote><literal>image</literal></quote> and the subtype identifier is
<quote><literal>jpeg</literal></quote>. The top-level media type is meant
to be a general categorization about the content of the file, while the
subtype identifer is meant to specifically identify the format of the
file.</para>
<para>There are eight media types currently blessed by the
<acronym>IANA</acronym> [Internet Assigned Naming Authority]. These eight
media types are <simplelist type="inline">
<member>application</member>
<member>audio</member>
<member>image</member>
<member>message</member>
<member>model</member>
<member>multipart</member>
<member>text</member>
<member>video</member>
</simplelist>. Many subtypes exist for each media type; for more
information, see <ulink
url="http://www.iana.org/assignments/media-types/">MIME Media
Types</ulink> at the <ulink url="http://www.iana.org/">IANA</ulink> web
site.</para>
<para>Implementation of MIME types in GNOME follows the <ulink
url="http://www.freedesktop.org/Standards/shared-mime-info-spec">XDG
shared mime info specification</ulink>. This specification provides the
following advantages:</para>
<itemizedlist>
<listitem>
<para>Standard locations for all MIME related files.</para>
</listitem>
<listitem>
<para>A standard way for applications to register information about a
new MIME type.</para>
</listitem>
<listitem>
<para>A standard way to retrieve the MIME type for a file.</para>
</listitem>
<listitem>
<para>A standard way to retrieve information about a MIME type.</para>
</listitem>
</itemizedlist>
<para>The rest of the chapter describes the files and directories that
make up the MIME database, details about source XML files, how to create
or modify MIME types, how to register applications as handlers for certain
MIME types and finally, how to add an application to the GNOME
desktop.</para>
</sect1>
<sect1 id="mimetypes-database">
<title>The MIME Database</title>
<anchor id="mimetypes-4"/>
<anchor id="mimetypes-5"/>
<indexterm>
<primary>MIME types</primary>
<secondary>database</secondary>
</indexterm>
<para>The MIME database is a collection of files that make up:</para>
<itemizedlist>
<listitem>
<para>The set of known MIME types</para>
</listitem>
<listitem>
<para>The method for determing the MIME type of a file</para>
</listitem>
<listitem>
<para>Meta information regarding a MIME type, such as a human readable
description to use when displaying files of this type.</para>
</listitem>
</itemizedlist>
<sect2 id="mimetypes-location">
<title>Location</title>
<para>As an administrator, the most important and basic step to
understanding the MIME system is learning the locations where these
files are stored. Since the <ulink
url="http://www.freedesktop.org/Standards/shared-mime-info-spec">XDG
shared mime info specification</ulink> was drafted by the X Desktop
Group, it also makes use of the <ulink
url="http://www.freedesktop.org/wiki/Standards/basedir-spec">XDG base
directory specification</ulink>. It is highly recommended that you
familiarize yourself with this specification, as it is also important
for other system administration tasks such as editing menus. A brief
summary of the directory locations as pertaining to the MIME
specification is given below.</para>
<para>The MIME database is created from the set of files located in the
<filename>$XDG_DATA_HOME/mime</filename> and
<filename>$XDG_DATA_DIRS/mime</filename> directories. If
these environment variables are unset, then they default to the values
<filename>~/.local/share</filename> and
<filename>/usr/local/share:/usr/share</filename> respectively. As can be
seen from the default value for <envar>$XDG_DATA_DIRS</envar> , each
environment variable is actually a colon separated list of directories.
The user's database at
<filename>$XDG_DATA_HOME/mime</filename> has precedence
over the system database at
<filename>$XDG_DATA_DIRS/mime</filename> when conflicting
definitions are encountered. Similar to the <citetitle>XDG shared mime
specification</citetitle>, we will refer to this set of directories as
<literal><MIME></literal> in the rest of this document.</para>
<para>For example, assuming default paths for the environment variables,
<quote>Load
<filename><MIME>/text/plain.xml</filename></quote>
means to load the following files:</para>
<itemizedlist>
<listitem>
<para><filename>~/.local/share/mime/text/plain.xml</filename></para>
</listitem>
<listitem>
<para><filename>/usr/local/share/mime/text/plain.xml</filename></para>
</listitem>
<listitem>
<para><filename>/usr/share/mime/text/plain.xml</filename></para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="mimetypes-contents">
<title>Contents</title>
<para>The following is a list of directories and files that are found
inside the MIME database along with brief descriptions:</para>
<variablelist>
<varlistentry>
<term><filename><MIME>/packages/</filename></term>
<listitem>
<para>This directory contains any number of XML files, each of
which describe a collection of MIME types. By default, the
<filename>freedesktop.org.xml</filename> file is installed in the
<filename>/usr/share/mime/packages</filename> directory. This file
contains all the default MIME types that are widely used and
recognized.</para>
<para>Applications which provide information about new MIME types
are to install a <emphasis>single</emphasis> new XML file here.
Depending on the prefix where the application is installed, it
will create the file in the <filename>/mime/package</filename>
subdirectory of one of the directories in
<envar>$XDG_DATA_HOME:$XDG_DATA_DIRS</envar>. For example, an
application installed to <filename>/usr/bin</filename> should
install a new source XML file to the
<filename>/usr/share/mime/packages</filename> directory. For more
information about the XML files in the
<filename>packages</filename> directory, please see <xref linkend="mimetypes-source-xml"/>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename><MIME>/<replaceable>MEDIA</replaceable>/<replaceable>SUBTYPE</replaceable>.xml</filename></term>
<listitem>
<para>These directories and files are automatically generated from
the collection of source XML files in the
<filename><MIME>/packages/</filename> subdirectory by the
<application>update-mime-database</application> application. For
example, for each <literal>mime-type</literal> element in the
<filename>/usr/share/mime/packages/freedesktop.org.xml</filename>
file, a directory is created at
<filename>/usr/share/mime/</filename> with the <emphasis>media
type</emphasis> of the MIME type. An XML file is created in that
directory with the <emphasis>subtype identifier</emphasis> of that
MIME type as well. The contents of the created XML file include
comments (and translations for them), subclasses designations and
aliases.</para>
<example>
<title>Example:
<filename>/usr/share/mime/text/plain.xml</filename> file</title>
<para><programlisting><?xml version='1.0' encoding='utf-8'?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/plain">
<!--Created automatically by update-mime-database. DO NOT EDIT!-->
|