MIME types

MIME types — File extension and MIME-type mappings

Functions

Description

Maps file extensions to MIME-types and MIME-types to preferred extensions, using MimeKit's built-in mappings rather than the host's MIME database. The two directions are independent: a type can have several extensions, and a preferred extension can be shared by aliases of a type.

Registrations are process-wide and survive g_mime_shutdown(). Lookups and registrations are synchronized, and returned strings are owned copies that remain valid after later registrations. Comparisons use ASCII case-insensitivity, as elsewhere in GMime's MIME-type handling.

Functions

g_mime_types_get_mime_type ()

char *
g_mime_types_get_mime_type (const char *file_name);

Gets the MIME-type based on the last extension of file_name , without accessing the file or inspecting its content. Directory separators follow the host platform. Empty names, extensionless names, trailing dots, and unknown extensions use application/octet-stream.

Parameters

file_name

a file name or path.

[type filename]

Returns

the MIME-type; free with g_free().

[transfer full]


g_mime_types_try_get_extension ()

gboolean
g_mime_types_try_get_extension (const char *mime_type,
                                char **extension);

Looks up the exact MIME-type, ignoring ASCII case. Does not parse or normalize a Content-Type value. An empty or unknown MIME-type is not found.

Parameters

mime_type

a MIME-type, without parameters or surrounding whitespace

 

extension

the preferred extension, including its leading dot, or NULL if unknown.

[out][transfer full][nullable]

Returns

TRUE if the MIME-type has a preferred extension.


g_mime_types_register ()

void
g_mime_types_register (const char *mime_type,
                       const char *extension);

Registers both directions of a mapping, replacing any existing entry for this extension and any preferred extension for this MIME-type. Other mappings, including old aliases, remain unchanged. A leading dot is prepended if absent. Values are copied as supplied, without trimming, validation of MIME syntax, or case normalization.

The two updates are atomic with respect to other registry operations.

Parameters

mime_type

a nonempty MIME-type

 

extension

a nonempty file extension, with or without a leading dot