GMimeParserOptions

GMimeParserOptions — Parser options

Functions

void (*GMimeParserWarningFunc) ()
GMimeParserOptions * g_mime_parser_options_new ()
GMimeParserOptions * g_mime_parser_options_ref ()
void g_mime_parser_options_unref ()
GMimeParserOptions * g_mime_parser_options_clone ()
GMimeParserOptions * g_mime_parser_options_get_default ()
int g_mime_parser_options_get_max_address_group_depth ()
void g_mime_parser_options_set_max_address_group_depth ()
int g_mime_parser_options_get_max_mime_depth ()
void g_mime_parser_options_set_max_mime_depth ()
GMimeRfcComplianceMode g_mime_parser_options_get_address_compliance_mode ()
void g_mime_parser_options_set_address_compliance_mode ()
gboolean g_mime_parser_options_get_allow_addresses_without_domain ()
void g_mime_parser_options_set_allow_addresses_without_domain ()
gboolean g_mime_parser_options_get_allow_unquoted_commas_in_addresses ()
void g_mime_parser_options_set_allow_unquoted_commas_in_addresses ()
gboolean g_mime_parser_options_get_respect_content_length ()
void g_mime_parser_options_set_respect_content_length ()
gboolean g_mime_parser_options_get_detect_openpgp ()
void g_mime_parser_options_set_detect_openpgp ()
int g_mime_parser_options_get_max_header_length ()
void g_mime_parser_options_set_max_header_length ()
GMimeRfcComplianceMode g_mime_parser_options_get_parameter_compliance_mode ()
void g_mime_parser_options_set_parameter_compliance_mode ()
GMimeRfcComplianceMode g_mime_parser_options_get_rfc2047_compliance_mode ()
void g_mime_parser_options_set_rfc2047_compliance_mode ()
const char * g_mime_parser_options_get_charset_encoding ()
gboolean g_mime_parser_options_set_charset_encoding ()
GMimeParserWarningFunc g_mime_parser_options_get_warning_callback ()
void g_mime_parser_options_set_warning_callback ()

Types and Values

Description

A GMimeParserOptions is used to pass various options to GMimeParser and all of the various other parser functions in GMime.

Functions

GMimeParserWarningFunc ()

void
(*GMimeParserWarningFunc) (gint64 offset,
                           GMimeParserWarning errcode,
                           const gchar *item,
                           gpointer user_data);

The function signature for a callback to g_mime_parser_options_set_warning_callback().

Prefer GMimeComplianceIssueFunc for new compliance reporting code. See GMimeParserWarning for guidance on when this callback is still useful.

Parameters

offset

parser offset where the issue has been detected, or -1 if it is unknown

 

errcode

a GMimeParserWarning

 

item

a NUL-terminated string containing the value causing the issue, may be NULL

 

user_data

User-supplied callback data.

 

g_mime_parser_options_new ()

GMimeParserOptions *
g_mime_parser_options_new (void);

Creates a new set of GMimeParserOptions.

Returns

new options with the default values and one reference.

[transfer full]


g_mime_parser_options_ref ()

GMimeParserOptions *
g_mime_parser_options_ref (GMimeParserOptions *options);

Atomically acquires a reference to options . This shares the same settings; concurrent changes to the settings still require external synchronization.

Parameters

options

a GMimeParserOptions

 

Returns

options with an additional reference.

[transfer full]


g_mime_parser_options_unref ()

void
g_mime_parser_options_unref (GMimeParserOptions *options);

Atomically releases a reference to options . The options and their owned data are destroyed when the last reference is released.

Parameters


g_mime_parser_options_clone ()

GMimeParserOptions *
g_mime_parser_options_clone (GMimeParserOptions *options);

Creates an independent copy of the settings in options . Unlike g_mime_parser_options_ref() or g_boxed_copy(), this does not share settings. Warning callback data remains borrowed; the clone does not copy its destroy notification. The data must remain valid while the clone uses it.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

a newly allocated GMimeParserOptions.

[transfer full]


g_mime_parser_options_get_default ()

GMimeParserOptions *
g_mime_parser_options_get_default (void);

Gets the default parser options.

The returned reference belongs to GMime. Use g_mime_parser_options_ref() to retain it independently, or g_mime_parser_options_clone() for a copy.

Returns

the default parser options.

[transfer none]


g_mime_parser_options_get_max_address_group_depth ()

int
g_mime_parser_options_get_max_address_group_depth
                               (GMimeParserOptions *options);

Gets the maximum number of nested address groups. The default is 3. A value of 0 prevents the parser from accepting group addresses.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the maximum address group depth.


g_mime_parser_options_set_max_address_group_depth ()

void
g_mime_parser_options_set_max_address_group_depth
                               (GMimeParserOptions *options,
                                int max_depth);

Sets the maximum number of nested address groups. Groups beyond this limit are rejected and reported through the parser warning callback.

Parameters

options

a GMimeParserOptions

 

max_depth

the maximum address group depth, greater than or equal to 0

 

g_mime_parser_options_get_max_mime_depth ()

int
g_mime_parser_options_get_max_mime_depth
                               (GMimeParserOptions *options);

Gets the maximum MIME nesting depth. The default is 1024. A value of 0 treats all multipart and embedded-message entities as leaves.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the maximum MIME nesting depth.


g_mime_parser_options_set_max_mime_depth ()

void
g_mime_parser_options_set_max_mime_depth
                               (GMimeParserOptions *options,
                                int max_depth);

Sets the maximum MIME nesting depth. Containers at this depth are parsed as GMimePart objects, preserving their content without parsing it. Exceeding the limit is reported through the parser warning callback.

The parser currently uses recursion. Increasing the limit above its default may exhaust the call stack.

Parameters

options

a GMimeParserOptions

 

max_depth

the maximum MIME nesting depth, greater than or equal to 0

 

g_mime_parser_options_get_address_compliance_mode ()

GMimeRfcComplianceMode
g_mime_parser_options_get_address_compliance_mode
                               (GMimeParserOptions *options);

Gets the compliance mode that should be used when parsing rfc822 addresses.

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the address parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input. GMIME_RFC_COMPLIANCE_LOOSER additionally accepts consecutive or trailing dots and escaped at-signs in local parts.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the compliance mode that is currently set.


g_mime_parser_options_set_address_compliance_mode ()

void
g_mime_parser_options_set_address_compliance_mode
                               (GMimeParserOptions *options,
                                GMimeRfcComplianceMode mode);

Sets the compliance mode that should be used when parsing rfc822 addresses.

In general, you'll probably want this value to be GMIME_RFC_COMPLIANCE_LOOSE (the default) as it allows maximum interoperability with existing (broken) mail clients and other mail software such as sloppily written perl scripts (aka spambots).

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the address parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input.

Parameters


g_mime_parser_options_get_allow_addresses_without_domain ()

gboolean
g_mime_parser_options_get_allow_addresses_without_domain
                               (GMimeParserOptions *options);

Gets whether or not the rfc822 address parser should allow addresses without a domain.

The default is TRUE, allowing local UNIX mailbox addresses.

This option exists in order to allow parsing of mailbox addresses that do not have a domain component. These types of addresses are rare and were typically only used when sending mail to other users on the same UNIX system.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

TRUE if the address parser should allow addresses without a domain.


g_mime_parser_options_set_allow_addresses_without_domain ()

void
g_mime_parser_options_set_allow_addresses_without_domain
                               (GMimeParserOptions *options,
                                gboolean allow);

Sets whether the rfc822 address parser should allow addresses without a domain.

The default is TRUE, allowing local UNIX mailbox addresses.

This option exists in order to allow parsing of mailbox addresses that do not have a domain component. These types of addresses are rare and were typically only used when sending mail to other users on the same UNIX system.

Parameters

options

a GMimeParserOptions

 

allow

TRUE if the parser should allow addresses without a domain or FALSE otherwise

 

g_mime_parser_options_get_allow_unquoted_commas_in_addresses ()

gboolean
g_mime_parser_options_get_allow_unquoted_commas_in_addresses
                               (GMimeParserOptions *options);

Gets whether unquoted commas are allowed in address display names. The default is TRUE, matching MimeKit's address recovery behavior.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

TRUE if unquoted commas are allowed.


g_mime_parser_options_set_allow_unquoted_commas_in_addresses ()

void
g_mime_parser_options_set_allow_unquoted_commas_in_addresses
                               (GMimeParserOptions *options,
                                gboolean allow);

Sets whether unquoted commas are allowed in address display names. A comma following a quoted word is still treated as an address separator. This option is independent of whether domainless addresses are allowed.

Parameters

options

a GMimeParserOptions

 

allow

whether to allow unquoted commas in address display names

 

g_mime_parser_options_get_respect_content_length ()

gboolean
g_mime_parser_options_get_respect_content_length
                               (GMimeParserOptions *options);

Gets whether Content-Length headers postpone recognition of mbox From-lines until the declared body length has been consumed. The default is FALSE. Other input formats ignore this option.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

TRUE if mbox parsing respects Content-Length.


g_mime_parser_options_set_respect_content_length ()

void
g_mime_parser_options_set_respect_content_length
                               (GMimeParserOptions *options,
                                gboolean respect);

Enables Content-Length handling for mbox input. The first header with a valid nonnegative 32-bit numeric prefix is used; invalid values are ignored. The raw value must start with whitespace followed by decimal digits. This does not truncate content at the declared length: the parser resumes looking for a From-line there.

Parameters

options

a GMimeParserOptions

 

respect

whether mbox parsing should respect Content-Length

 

g_mime_parser_options_get_detect_openpgp ()

gboolean
g_mime_parser_options_get_detect_openpgp
                               (GMimeParserOptions *options);

Gets whether parsing scans leaf content for inline OpenPGP armor markers. The default is FALSE. This does not affect explicit OpenPGP detection through g_mime_part_get_openpgp_data() or GMimeFilterOpenPGP.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

TRUE if parsing should detect inline OpenPGP data.


g_mime_parser_options_set_detect_openpgp ()

void
g_mime_parser_options_set_detect_openpgp
                               (GMimeParserOptions *options,
                                gboolean detect);

Enables GMime's optional inline OpenPGP detection extension. This scans the original transfer-encoded content, not decoded Base64 or uuencoded bytes. g_mime_part_get_openpgp_data() can still detect decoded content on demand when parsing has not cached a result.

Parameters

options

a GMimeParserOptions

 

detect

whether to scan for inline OpenPGP armor markers while parsing

 

g_mime_parser_options_get_max_header_length ()

int
g_mime_parser_options_get_max_header_length
                               (GMimeParserOptions *options);

Gets the maximum raw length of a single header, in bytes. The default is 32768 (32 KiB).

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the maximum header length.


g_mime_parser_options_set_max_header_length ()

void
g_mime_parser_options_set_max_header_length
                               (GMimeParserOptions *options,
                                int max_length);

Sets the maximum length of a single header. The length includes the field name, colon, raw value, folding whitespace and terminating newline sequence. GMimeParser fails with GMIME_ERROR_HEADER_TOO_LONG before buffering data beyond this limit.

Parameters

options

a GMimeParserOptions

 

max_length

the maximum raw header length, greater than 0

 

g_mime_parser_options_get_parameter_compliance_mode ()

GMimeRfcComplianceMode
g_mime_parser_options_get_parameter_compliance_mode
                               (GMimeParserOptions *options);

Gets the compliance mode that should be used when parsing Content-Type and Content-Disposition parameters.

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the parameter parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the compliance mode that is currently set.


g_mime_parser_options_set_parameter_compliance_mode ()

void
g_mime_parser_options_set_parameter_compliance_mode
                               (GMimeParserOptions *options,
                                GMimeRfcComplianceMode mode);

Sets the compliance mode that should be used when parsing Content-Type and Content-Disposition parameters.

In general, you'll probably want this value to be GMIME_RFC_COMPLIANCE_LOOSE (the default) as it allows maximum interoperability with existing (broken) mail clients and other mail software such as sloppily written perl scripts (aka spambots).

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the parameter parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input.

Parameters


g_mime_parser_options_get_rfc2047_compliance_mode ()

GMimeRfcComplianceMode
g_mime_parser_options_get_rfc2047_compliance_mode
                               (GMimeParserOptions *options);

Gets the compliance mode that should be used when parsing rfc2047 encoded words.

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the rfc2047 parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the compliance mode that is currently set.


g_mime_parser_options_set_rfc2047_compliance_mode ()

void
g_mime_parser_options_set_rfc2047_compliance_mode
                               (GMimeParserOptions *options,
                                GMimeRfcComplianceMode mode);

Sets the compliance mode that should be used when parsing rfc2047 encoded words.

In general, you'll probably want this value to be GMIME_RFC_COMPLIANCE_LOOSE (the default) as it allows maximum interoperability with existing (broken) mail clients and other mail software such as sloppily written perl scripts (aka spambots).

Note: Even in GMIME_RFC_COMPLIANCE_STRICT mode, the parameter parser is fairly liberal in what it accepts. Setting it to GMIME_RFC_COMPLIANCE_LOOSE just makes it try harder to deal with garbage input.

Parameters


g_mime_parser_options_get_charset_encoding ()

const char *
g_mime_parser_options_get_charset_encoding
                               (GMimeParserOptions *options);

Gets the fallback charset encoding used when decoding undeclared 8-bit header text. The default is "utf-8". UTF-8 is always attempted first, followed by this charset, and finally ISO-8859-1.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the charset name, owned by options or the defaults.

[transfer none]


g_mime_parser_options_set_charset_encoding ()

gboolean
g_mime_parser_options_set_charset_encoding
                               (GMimeParserOptions *options,
                                const char *charset,
                                GError **error);

Sets the fallback charset encoding for undeclared 8-bit header text, following MimeKit's CharsetEncoding option. The name is copied and must be supported by the platform's iconv implementation.

UTF-8 is always attempted first and ISO-8859-1 last. An unsupported or empty name fails without changing the option.

Parameters

options

a GMimeParserOptions

 

charset

charset encoding name, or NULL to reset to UTF-8.

[nullable]

error

return location for a GError, or NULL

 

Returns

TRUE on success or FALSE with error set on failure.


g_mime_parser_options_get_warning_callback ()

GMimeParserWarningFunc
g_mime_parser_options_get_warning_callback
                               (GMimeParserOptions *options);

Gets callback function which is called if the parser detects any issues.

[skip]

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

Returns

the currently registered warning callback function


g_mime_parser_options_set_warning_callback ()

void
g_mime_parser_options_set_warning_callback
                               (GMimeParserOptions *options,
                                GMimeParserWarningFunc warning_cb,
                                gpointer user_data,
                                GDestroyNotify notify);

Registers the callback function being called if the parser detects any issues.

New applications should prefer g_mime_parser_set_compliance_logger() or g_mime_reader_set_compliance_logger(). Warning callbacks remain supported for diagnostics outside the compliance APIs' coverage; see GMimeParserWarning.

Parameters

options

a GMimeParserOptions

 

warning_cb

a GMimeParserWarningFunc or NULL to clear the callback

 

user_data

data passed to the warning callback function

 

notify

callback function ran on destruction

 

Types and Values

GMimeParserOptions

typedef struct _GMimeParserOptions GMimeParserOptions;

A reference-counted set of parser options used by GMimeParser and various other parsing functions. Boxed copies share settings; use g_mime_parser_options_clone() for an independent copy.


enum GMimeRfcComplianceMode

An RFC compliance mode.

Members

GMIME_RFC_COMPLIANCE_LOOSE

Attempt to be much more liberal accepting broken and/or invalid formatting.

 

GMIME_RFC_COMPLIANCE_STRICT

Do not attempt to be overly liberal in accepting broken and/or invalid formatting.

 

GMIME_RFC_COMPLIANCE_LOOSER

Also allow consecutive or trailing local-part dots and escaped '@' characters in addresses.

 

enum GMimeParserWarning

Issues the GMimeParser detects. Note that the GMIME_CRIT_* issues indicate that some parts of the GMimeParser input may be ignored or will be interpreted differently by other software products.

New applications should prefer the GMimeComplianceViolation reporting APIs. Register a logger with g_mime_parser_set_compliance_logger() or g_mime_reader_set_compliance_logger() to receive structured GMimeComplianceIssue diagnostics with more detailed input positions.

The two reporting mechanisms have different coverage. Parser warning callbacks remain supported for diagnostics not currently provided by the compliance APIs, including value-conflict distinctions and decoder warnings outside the selected encoded-word validator headers. They are not deprecated and may be used alongside compliance reporting; installing a compliance logger does not replace or disable a parser warning callback.

Members

GMIME_WARN_DUPLICATED_HEADER

Repeated exactly the same header which should exist only once.

 

GMIME_WARN_DUPLICATED_PARAMETER

Repeated exactly the same header parameter.

 

GMIME_WARN_UNENCODED_8BIT_HEADER

A header contains unencoded 8-bit characters.

 

GMIME_WARN_INVALID_CONTENT_TYPE

Invalid content type, assuming application/octet-stream.

 

GMIME_WARN_INVALID_RFC2047_HEADER_VALUE

Invalid RFC 2047 encoded header value.

 

GMIME_WARN_MALFORMED_MULTIPART

No child parts detected within a multipart.

 

GMIME_WARN_TRUNCATED_MESSAGE

The message is truncated.

 

GMIME_WARN_MALFORMED_MESSAGE

A message was returned after EOF was encountered where a nested entity's headers should start or before its field name was complete.

 

GMIME_CRIT_INVALID_HEADER_NAME

Invalid header name, the parser may skip the message or parts of it.

 

GMIME_CRIT_CONFLICTING_HEADER

Conflicting header.

 

GMIME_CRIT_CONFLICTING_PARAMETER

Conflicting header parameter.

 

GMIME_CRIT_MULTIPART_WITHOUT_BOUNDARY

A multipart lacks the required boundary parameter.

 

GMIME_WARN_INVALID_PARAMETER

Invalid header parameter.

 

GMIME_WARN_INVALID_ADDRESS_LIST

Invalid address list.

 

GMIME_CRIT_NESTING_OVERFLOW

The maximum MIME nesting level has been exceeded. This is very likely to be an attempt to exploit the MIME parser.

 

GMIME_WARN_PART_WITHOUT_CONTENT

A MIME part's headers were terminated by a boundary marker.

 

GMIME_CRIT_PART_WITHOUT_HEADERS_OR_CONTENT

A MIME part was encountered without any headers -or- content. This is very likely to be an attempt to exploit the MIME parser.