GMimeContentType

GMimeContentType — Content-Type fields

Functions

Types and Values

Description

A GMimeContentType represents the pre-parsed contents of a Content-Type header field.

Functions

g_mime_content_type_new ()

GMimeContentType *
g_mime_content_type_new (const char *type,
                         const char *subtype);

Creates a Content-Type object with type type and subtype subtype .

Parameters

type

the MIME type or NULL for the default value

 

subtype

the MIME subtype or NULL for the default value

 

Returns

a new GMimeContentType object.


g_mime_content_type_parse ()

GMimeContentType *
g_mime_content_type_parse (GMimeParserOptions *options,
                           const char *str);

Parses the input string using best-effort recovery, substituting a default content type on invalid input and retaining partial parameters. Use g_mime_content_type_parse_full() for all-or-nothing parsing.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

str

input string containing a content-type (and params)

 

Returns

a new GMimeContentType object.

[transfer full]


g_mime_content_type_parse_full ()

GMimeContentType *
g_mime_content_type_parse_full (GMimeParserOptions *options,
                                const char *str,
                                gssize length,
                                GError **error);

Parses the complete input without substituting a default content type or ignoring malformed parameters. Syntax errors return NULL with GMIME_ERROR_PARSE_ERROR and a byte offset relative to str . Explicitly bounded input need not be NUL-terminated but cannot contain embedded NUL bytes.

Comments and whitespace are accepted between tokens. The media type is an ASCII atom excluding '/', and the subtype is an ASCII MIME token that may also contain '/'. Parameters use the compliance and duplicate precedence rules of g_mime_param_list_parse_full().

Parameters

options

parser options, or NULL for the defaults.

[nullable]

str

Content-Type field value

 

length

byte length, or -1 for a NUL-terminated string

 

error

return location for a GError.

[nullable]

Returns

the parsed content type, or NULL on error.

[nullable][transfer full]


g_mime_content_type_clone ()

GMimeContentType *
g_mime_content_type_clone (GMimeContentType *content_type);

Copies the media type, subtype, and all parameters, including their charset, language, encoding method, and quoting preference. Parameters are copied independently in their original order, retaining spelling and any duplicate names recovered by legacy parsing.

Parameters

content_type

a GMimeContentType

 

Returns

an independent copy of content_type .

[transfer full]


g_mime_content_type_get_mime_type ()

char *
g_mime_content_type_get_mime_type (GMimeContentType *content_type);

Allocates a string buffer containing the type and subtype defined by the content_type .

Parameters

content_type

a GMimeContentType

 

Returns

an allocated string containing the type and subtype of the content-type in the format: type/subtype.


g_mime_content_type_to_string ()

char *
g_mime_content_type_to_string (GMimeContentType *content_type);

Formats a display string beginning with "Content-Type: ". Parameter values are always quoted and escaped, without transport encoding, folding, or an appended newline. This is not a transport-safe header; use g_mime_content_type_encode() when serializing a MIME message.

Parameters

content_type

a GMimeContentType

 

Returns

the unencoded display string.

[transfer full]


g_mime_content_type_encode ()

char *
g_mime_content_type_encode (GMimeContentType *content_type,
                            GMimeFormatOptions *options);

Encodes the Content-Type field value, including leading whitespace and a terminating newline. The field name is not included.

Parameters

content_type

a GMimeContentType

 

options

a GMimeFormatOptions or NULL.

[nullable]

Returns

a new string containing the encoded header value.


g_mime_content_type_is_type ()

gboolean
g_mime_content_type_is_type (GMimeContentType *content_type,
                             const char *type,
                             const char *subtype);

Compares the given type and subtype with that of the given mime type object.

Parameters

content_type

a GMimeContentType

 

type

MIME type to compare against

 

subtype

MIME subtype to compare against

 

Returns

TRUE if the MIME types match or FALSE otherwise. You may use "*" in place of type and/or subtype as a wilcard.


g_mime_content_type_get_media_type ()

const char *
g_mime_content_type_get_media_type (GMimeContentType *content_type);

Gets the Content-Type's media type.

Parameters

content_type

a GMimeContentType

 

Returns

the Content-Type's media type.


g_mime_content_type_set_media_type ()

void
g_mime_content_type_set_media_type (GMimeContentType *content_type,
                                    const char *type);

Sets the Content-Type's media type.

Parameters

content_type

a GMimeContentType

 

type

media type

 

g_mime_content_type_get_media_subtype ()

const char *
g_mime_content_type_get_media_subtype (GMimeContentType *content_type);

Gets the Content-Type's media sub-type.

Parameters

content_type

a GMimeContentType

 

Returns

the Content-Type's media sub-type.


g_mime_content_type_set_media_subtype ()

void
g_mime_content_type_set_media_subtype (GMimeContentType *content_type,
                                       const char *subtype);

Sets the Content-Type's media subtype.

Parameters

content_type

a GMimeContentType

 

subtype

media subtype

 

g_mime_content_type_get_boundary ()

const char *
g_mime_content_type_get_boundary (GMimeContentType *content_type);

Gets the boundary parameter without generating a value.

Parameters

content_type

a GMimeContentType

 

Returns

the borrowed boundary, or NULL if absent.

[nullable]


g_mime_content_type_set_boundary ()

void
g_mime_content_type_set_boundary (GMimeContentType *content_type,
                                  const char *boundary);

Sets the boundary parameter. An empty string remains an explicit empty value. Unlike g_mime_multipart_set_boundary(), NULL removes the parameter rather than generating a boundary.

Parameters

content_type

a GMimeContentType

 

boundary

the UTF-8 boundary, or NULL to remove the parameter.

[nullable]

g_mime_content_type_get_charset ()

const char *
g_mime_content_type_get_charset (GMimeContentType *content_type);

Gets the charset parameter without resolving or normalizing its name.

Parameters

content_type

a GMimeContentType

 

Returns

the borrowed charset name, or NULL if absent.

[nullable]


g_mime_content_type_set_charset ()

void
g_mime_content_type_set_charset (GMimeContentType *content_type,
                                 const char *charset);

Sets the charset parameter without resolving or normalizing its name. An empty string remains an explicit empty value.

Parameters

content_type

a GMimeContentType

 

charset

the UTF-8 charset name, or NULL to remove the parameter.

[nullable]

g_mime_content_type_get_charset_encoding ()

char *
g_mime_content_type_get_charset_encoding
                               (GMimeContentType *content_type,
                                GError **error);

Resolves the charset parameter to a supported canonical MIME charset name, following MimeKit's ContentType.CharsetEncoding property. Missing, empty, invalid, and unsupported names return NULL without an error. Other converter failures report G_CONVERT_ERROR rather than masquerading as an unknown charset. Resolution uses the same aliases as g_mime_content_type_set_charset_encoding().

This method does not change the parameter, its metadata, or raw headers. The result is independent of later parameter changes.

Parameters

content_type

a GMimeContentType

 

error

return location for an error, or NULL

 

Returns

the resolved charset name, or NULL if unavailable or on failure.

[nullable][transfer full]


g_mime_content_type_set_charset_encoding ()

gboolean
g_mime_content_type_set_charset_encoding
                               (GMimeContentType *content_type,
                                const char *charset,
                                GError **error);

Resolves charset and assigns its canonical MIME name, following MimeKit's ContentType.CharsetEncoding property. Unlike g_mime_content_type_set_charset(), this validates the name before changing any parameters or their owning entity's headers. Unsupported, empty, or non-token names report G_CONVERT_ERROR.

Generic UTF-16/32 names select little-endian encodings. MimeKit's historical "unicode" alias selects UTF-8. Available encodings and aliases follow the platform's iconv implementation; custom managed encodings are not supported. Borrowed parameter values may safely be passed as charset .

Parameters

content_type

a GMimeContentType

 

charset

a supported MIME charset name, or NULL to remove it.

[nullable]

error

return location for an error, or NULL

 

Returns

TRUE on success, or FALSE on failure without changing the object.


g_mime_content_type_get_format ()

const char *
g_mime_content_type_get_format (GMimeContentType *content_type);

Gets the format parameter.

Parameters

content_type

a GMimeContentType

 

Returns

the borrowed format, or NULL if absent.

[nullable]


g_mime_content_type_set_format ()

void
g_mime_content_type_set_format (GMimeContentType *content_type,
                                const char *format);

Sets the format parameter, typically "fixed" or "flowed" for text/plain. Other values and explicit empty strings are preserved.

Parameters

content_type

a GMimeContentType

 

format

the UTF-8 format, or NULL to remove the parameter.

[nullable]

g_mime_content_type_get_name ()

const char *
g_mime_content_type_get_name (GMimeContentType *content_type);

Gets the name parameter.

Parameters

content_type

a GMimeContentType

 

Returns

the borrowed UTF-8 display name, or NULL if absent.

[nullable]


g_mime_content_type_set_name ()

void
g_mime_content_type_set_name (GMimeContentType *content_type,
                              const char *name);

Sets the name parameter. Empty strings and whitespace are preserved.

Parameters

content_type

a GMimeContentType

 

name

the UTF-8 display name, or NULL to remove the parameter.

[nullable]

g_mime_content_type_get_parameters ()

GMimeParamList *
g_mime_content_type_get_parameters (GMimeContentType *content_type);

Gets the Content-Type's parameter list.

Parameters

content_type

a GMimeContentType

 

Returns

the Content-Type's parameter list.

[transfer none]


g_mime_content_type_get_parameter ()

const char *
g_mime_content_type_get_parameter (GMimeContentType *content_type,
                                   const char *name);

Gets the parameter value specified by name if it's available.

Parameters

content_type

a GMimeContentType

 

name

parameter name (aka attribute)

 

Returns

the value of the requested parameter or NULL if the parameter is not set. If the parameter is set, the returned string will be in UTF-8.


g_mime_content_type_set_parameter ()

void
g_mime_content_type_set_parameter (GMimeContentType *content_type,
                                   const char *name,
                                   const char *value);

Sets a parameter on the Content-Type.

Note: The name should be in US-ASCII while the value should be in UTF-8.

Parameters

content_type

a GMimeContentType

 

name

parameter name (aka attribute)

 

value

parameter value

 

Types and Values

GMimeContentType

typedef struct _GMimeContentType GMimeContentType;

A data structure representing a Content-Type.