GMimeBodyBuilder

GMimeBodyBuilder — Building common MIME message bodies

Functions

Types and Values

Description

Ports MimeKit's BodyBuilder. Plain text and HTML form multipart/alternative when both are present. HTML and linked resources form multipart/related, and attachments wrap the body in multipart/mixed. Resources are ignored without an HTML body. A lone attachment without either body is returned directly; an otherwise empty builder creates an empty text/plain part.

Body strings are copied UTF-8 strings, with NULL meaning absent and an empty string meaning present. BodyEncoding is represented by a charset name, defaulting to "utf-8". Generated text parts use that charset without charset detection or transfer-encoding selection. Unsupported charsets and conversion failures are reported rather than silently replacing unrepresentable text.

Each build creates fresh text parts and containers, but retains the original attachment and resource instances without modifying their headers or removing them from the builder's collections.

Functions

g_mime_body_builder_new ()

GMimeBodyBuilder *
g_mime_body_builder_new (void);

Returns

a new builder with empty attachment collections, absent text and HTML bodies, and UTF-8 body encoding.

[transfer full]


g_mime_body_builder_get_attachments ()

GMimeAttachmentCollection *
g_mime_body_builder_get_attachments (GMimeBodyBuilder *builder);

Parameters

builder

a GMimeBodyBuilder

 

Returns

the persistent mutable attachment collection.

[transfer none]


g_mime_body_builder_get_linked_resources ()

GMimeAttachmentCollection *
g_mime_body_builder_get_linked_resources
                               (GMimeBodyBuilder *builder);

Parameters

builder

a GMimeBodyBuilder

 

Returns

the persistent mutable linked-resource collection.

[transfer none]


g_mime_body_builder_get_text_body ()

const char *
g_mime_body_builder_get_text_body (GMimeBodyBuilder *builder);

Parameters

builder

a GMimeBodyBuilder

 

Returns

the borrowed UTF-8 plain-text body, or NULL if absent.

[nullable]


g_mime_body_builder_set_text_body ()

void
g_mime_body_builder_set_text_body (GMimeBodyBuilder *builder,
                                   const char *text);

Copies text . An empty string is a present, empty body.

Parameters

builder

a GMimeBodyBuilder

 

text

a UTF-8 body string, or NULL to omit the plain-text body.

[nullable]

g_mime_body_builder_get_html_body ()

const char *
g_mime_body_builder_get_html_body (GMimeBodyBuilder *builder);

Parameters

builder

a GMimeBodyBuilder

 

Returns

the borrowed UTF-8 HTML body, or NULL if absent.

[nullable]


g_mime_body_builder_set_html_body ()

void
g_mime_body_builder_set_html_body (GMimeBodyBuilder *builder,
                                   const char *html);

Copies html . An empty string is a present, empty body.

Parameters

builder

a GMimeBodyBuilder

 

html

a UTF-8 body string, or NULL to omit the HTML body.

[nullable]

g_mime_body_builder_get_body_encoding ()

const char *
g_mime_body_builder_get_body_encoding (GMimeBodyBuilder *builder);

Parameters

builder

a GMimeBodyBuilder

 

Returns

the borrowed MIME charset name used for generated text parts.


g_mime_body_builder_set_body_encoding ()

gboolean
g_mime_body_builder_set_body_encoding (GMimeBodyBuilder *builder,
                                       const char *charset,
                                       GError **error);

Resolves charset with GMime's native charset aliases and MIME-name mapping, and checks that a UTF-8 converter is available. Charset names must be MIME tokens; iconv modifiers such as //IGNORE and //TRANSLIT are not accepted. Generic UTF-16/32 aliases are normalized before conversion, so generated content does not include a Unicode byte-order mark. The "unicode" alias selects UTF-16, describing a managed Encoding object, unlike the MIME charset alias accepted by GMimeTextPart.

Unlike a managed Encoding object, this API does not support custom encoders or replacement fallbacks. Unrepresentable body text causes a conversion error during g_mime_body_builder_to_message_body(), not a charset change.

Parameters

builder

a GMimeBodyBuilder

 

charset

a non-NULL charset name

 

error

return location for an error, or NULL

 

Returns

TRUE on success, or FALSE with a G_CONVERT_ERROR on failure, leaving the previous encoding unchanged.


g_mime_body_builder_to_message_body ()

GMimeEntity *
g_mime_body_builder_to_message_body (GMimeBodyBuilder *builder,
                                     GError **error);

Constructs the MIME tree without changing the builder's state. NULL body strings are absent; empty strings are present. Linked resources participate only when HTML is present. Attachment and resource ordering and identity are preserved, including duplicate occurrences. Generated text parts keep the transfer encoding unspecified, matching MimeKit's TextPart.SetText().

A lone attachment is returned by reference if neither text body is present. If no body or attachments are present, returns an empty text/plain part in the selected charset. Conversion errors use G_CONVERT_ERROR and converted content exceeding the GMimeStreamMem limit uses GMIME_ERROR with EOVERFLOW. Failures release partial trees without modifying either collection.

Parameters

builder

a GMimeBodyBuilder

 

error

return location for an error, or NULL

 

Returns

the message body, or NULL on failure.

[nullable][transfer full]

Types and Values

GMimeBodyBuilder

typedef struct _GMimeBodyBuilder GMimeBodyBuilder;

A helper for constructing common MIME message body structures.

See Also

GMimeAttachmentCollection, GMimeMultipartAlternative, GMimeMultipartRelated