GMimeTextPart

GMimeTextPart — textual MIME parts

Functions

Types and Values

Description

A GMimeTextPart represents any text MIME part.

Functions

g_mime_text_part_new ()

GMimeTextPart *
g_mime_text_part_new (void);

Creates a new text MIME part object with a default content-type of text/plain.

Returns

an empty MIME Part object with a default content-type of text/plain.


g_mime_text_part_new_with_subtype ()

GMimeTextPart *
g_mime_text_part_new_with_subtype (const char *subtype);

Creates a new text MIME part with a sepcified subtype.

Parameters

subtype

textual subtype string

 

Returns

an empty text MIME part object with the specified subtype.


g_mime_text_part_new_with_format ()

GMimeTextPart *
g_mime_text_part_new_with_format (GMimeTextFormat format);

Creates a text part for format . Flowed text uses text/plain with a format=flowed parameter. Both rich-text formats use text/rtf; this constructor does not compress content.

Parameters

format

a GMimeTextFormat

 

Returns

a new GMimeTextPart.

[transfer full]


g_mime_text_part_get_format ()

GMimeTextFormat
g_mime_text_part_get_format (GMimeTextPart *mime_part);

Gets the format indicated by the Content-Type header. Unknown media types and subtypes return GMIME_TEXT_FORMAT_PLAIN. Enriched text includes text/richtext; RTF includes application/rtf.

Flowed text is text/plain with a format parameter equal to "flowed", ignoring ASCII case and surrounding ASCII linear whitespace in the parameter. Compressed rich text is not inferred from the Content-Type header.

Parameters

mime_part

a GMimeTextPart

 

Returns

the text format.


g_mime_text_part_is_plain ()

gboolean
g_mime_text_part_is_plain (GMimeTextPart *mime_part);

Tests whether the Content-Type is text/plain, ignoring ASCII case. This also matches flowed text.

Parameters

mime_part

a GMimeTextPart

 

Returns

TRUE for text/plain, otherwise FALSE.


g_mime_text_part_is_flowed ()

gboolean
g_mime_text_part_is_flowed (GMimeTextPart *mime_part);

Tests for text/plain with a format parameter equal to "flowed", ignoring ASCII case and surrounding ASCII linear whitespace.

Parameters

mime_part

a GMimeTextPart

 

Returns

TRUE for flowed text, otherwise FALSE.


g_mime_text_part_is_html ()

gboolean
g_mime_text_part_is_html (GMimeTextPart *mime_part);

Tests whether the Content-Type is text/html, ignoring ASCII case.

Parameters

mime_part

a GMimeTextPart

 

Returns

TRUE for text/html, otherwise FALSE.


g_mime_text_part_is_enriched ()

gboolean
g_mime_text_part_is_enriched (GMimeTextPart *mime_part);

Tests whether the Content-Type is text/enriched or text/richtext, ignoring ASCII case.

Parameters

mime_part

a GMimeTextPart

 

Returns

TRUE for enriched text, otherwise FALSE.


g_mime_text_part_is_rich_text ()

gboolean
g_mime_text_part_is_rich_text (GMimeTextPart *mime_part);

Tests whether the Content-Type is text/rtf or application/rtf, ignoring ASCII case.

Parameters

mime_part

a GMimeTextPart

 

Returns

TRUE for RTF, otherwise FALSE.


g_mime_text_part_get_charset ()

const char *
g_mime_text_part_get_charset (GMimeTextPart *mime_part);

Gets the value of the charset parameter on the Content-Type header.

Parameters

mime_part

a GMimeTextPart

 

Returns

the value of the charset parameter or NULL if unavailable.


g_mime_text_part_set_charset ()

void
g_mime_text_part_set_charset (GMimeTextPart *mime_part,
                              const char *charset);

Sets the charset parameter on the Content-Type header to the specified value.

Parameters

mime_part

a GMimeTextPart

 

charset

the name of the charset

 

g_mime_text_part_try_detect_encoding ()

gboolean
g_mime_text_part_try_detect_encoding (GMimeTextPart *mime_part,
                                      char **charset,
                                      GMimeTextEncodingConfidence *confidence,
                                      GError **error);

Resolves the Content-Type charset, then looks for a UTF-8 or UTF-16 BOM in transfer-decoded content. A supported declared charset takes precedence over a BOM; either gives GMIME_TEXT_ENCODING_CONFIDENCE_CERTAIN. Missing, invalid and unsupported declarations are ignored. No content gives "us-ascii" with GMIME_TEXT_ENCODING_CONFIDENCE_IRRELEVANT, even if a charset is declared. Empty content is not the same as absent content.

HTML without a declaration or BOM is scanned for meta charset declarations in its first 1024 transfer-decoded bytes. A supported meta charset gives GMIME_TEXT_ENCODING_CONFIDENCE_TENTATIVE. The scan requires opening html and head tags and stops at a body tag. Both charset attributes and http-equiv="Content-Type" declarations are recognized. Unsupported names are skipped; x-user-defined maps to Windows-1252 and UTF-16 to UTF-8. Otherwise returns FALSE with NULL charset and GMIME_TEXT_ENCODING_CONFIDENCE_UNDEFINED. This does not guess UTF-8 or Latin-1 or validate the entire content.

A declared charset or absent content requires no I/O. Otherwise this opens a decoded reader with g_mime_content_open() and makes one read of up to three decoded bytes. The decoder may read ahead in the backing stream; short BOM reads are not retried. The HTML scan opens a new decoded reader and fills its bounded prefix across short reads. Readers are released without closing or rewinding the backing stream. This path uses the backing stream, not the content's decode-to-stream override. Source-backed content must remain open and unchanged.

Stream failures report GMIME_ERROR; operational charset resolution failures report G_CONVERT_ERROR. Both outputs are cleared on failure. Neither headers nor content bytes are modified. Free charset with g_free().

Parameters

mime_part

a GMimeTextPart

 

charset

the detected charset, or NULL.

[out][nullable][transfer full]

confidence

confidence in the detected charset.

[out][optional]

error

return location for an error, or NULL

 

Returns

TRUE if an encoding was detected, otherwise FALSE.


g_mime_text_part_get_text ()

char *
g_mime_text_part_get_text (GMimeTextPart *mime_part);

Gets the text content of the mime_part as a string. Generic UTF-16 and UTF-32 charsets use little-endian bytes, matching g_mime_text_part_set_text_with_charset().

Parameters

mime_part

a GMimeTextPart

 

Returns

a newly allocated string containing the utf-8 encoded text content.


g_mime_text_part_get_text_with_encoding ()

char *
g_mime_text_part_get_text_with_encoding
                               (GMimeTextPart *mime_part,
                                char **used_charset,
                                GError **error);

Gets checked, automatically decoded UTF-8 text and optionally reports its source charset. Uses the same decoding policy as g_mime_message_get_text_body_with_format(): supported declared charsets and UTF-16 BOMs use replacement, while UTF-8 BOMs and the UTF-8 default use strict decoding and retry malformed input as ISO-8859-1. Without a declared charset or BOM, HTML meta charsets in the first 1024 decoded bytes are used before the UTF-8 default. Meta charsets use replacement, except UTF-16 declarations remapped to strict UTF-8. Incomplete final characters are handled rather than dropped.

Reports the charset used by the successful conversion, including Latin-1 after fallback, not merely the detected or declared charset. Missing content gives an allocated empty string and "us-ascii"; empty content is decoded using the normal charset selection. used_charset is NULL on any error.

Transfer-decoded bytes are read once, honoring content decode-to-stream overrides. The complete buffered prefix is used for BOM detection, even when the source produces short reads. Newlines follow the default GMimeFormatOptions. BOMs and bare CRs are retained; no final newline is added. No flowed-text conversion or markup conversion is done.

I/O and conversion failures never return partial text. Embedded decoded NULs report G_CONVERT_ERROR_EMBEDDED_NUL. Source-backed content must remain open and unchanged; successful decoding rewinds its stream, while failures may leave it advanced. Headers and content bytes remain unchanged. Free both the returned text and used_charset with g_free().

Parameters

mime_part

a GMimeTextPart

 

used_charset

the charset actually used.

[out][optional][nullable][transfer full]

error

return location for an error, or NULL

 

Returns

UTF-8 text, or NULL on failure.

[nullable][transfer full]


g_mime_text_part_set_text ()

void
g_mime_text_part_set_text (GMimeTextPart *mime_part,
                           const char *text);

Sets the specified text as the content and updates the charset parameter on the Content-Type header.

Parameters

mime_part

a GMimeTextPart

 

text

the text in utf-8

 

Types and Values

GMimeTextPart

typedef struct _GMimeTextPart GMimeTextPart;

A text MIME part object.


enum GMimeTextFormat

Text formats.

Members

GMIME_TEXT_FORMAT_PLAIN

Plain text.

 

GMIME_TEXT_FORMAT_TEXT

An alias for plain text.

 

GMIME_TEXT_FORMAT_FLOWED

Flowed text.

 

GMIME_TEXT_FORMAT_HTML

HTML.

 

GMIME_TEXT_FORMAT_ENRICHED

Enriched text.

 

GMIME_TEXT_FORMAT_COMPRESSED_RICH_TEXT

Compressed rich text.

 

GMIME_TEXT_FORMAT_RICH_TEXT

Rich text (RTF).

 

enum GMimeTextEncodingConfidence

Confidence in a detected text encoding, not a statistical probability. HTML meta declarations give tentative confidence.

Members

GMIME_TEXT_ENCODING_CONFIDENCE_UNDEFINED

No encoding was detected.

 

GMIME_TEXT_ENCODING_CONFIDENCE_TENTATIVE

An encoding was tentatively detected.

 

GMIME_TEXT_ENCODING_CONFIDENCE_CERTAIN

An explicit charset or BOM was found.

 

GMIME_TEXT_ENCODING_CONFIDENCE_IRRELEVANT

The part has no content.