GMimePart

GMimePart — MIME parts

Functions

Types and Values

Description

A GMimePart represents any MIME leaf part (meaning it has no sub-parts).

Functions

g_mime_part_new ()

GMimePart *
g_mime_part_new (void);

Creates a new MIME Part object with a default content-type of application/octet-stream.

Returns

an empty MIME Part object with a default content-type of application/octet-stream.


g_mime_part_new_with_type ()

GMimePart *
g_mime_part_new_with_type (const char *type,
                           const char *subtype);

Creates a new MIME Part with the specified type.

Parameters

type

content-type string

 

subtype

content-subtype string

 

Returns

an empty MIME Part object with the specified content-type.


g_mime_part_is_attachment ()

gboolean
g_mime_part_is_attachment (GMimePart *mime_part);

Determines whether or not the part is an attachment based on the value of the Content-Disposition header.

Parameters

mime_part

a GMimePart object

 

Returns

TRUE if the part is an attachment, otherwise FALSE.


g_mime_part_set_content_description ()

void
g_mime_part_set_content_description (GMimePart *mime_part,
                                     const char *description);

Sets Content-Description, trimming surrounding ASCII linear whitespace (SP, HTAB, CR and LF). Other whitespace is preserved. Empty descriptions are allowed; NULL removes all matching headers. Assigning the current cached value preserves raw headers and duplicates. Assignment before the first read replaces matching duplicates even if the first header already has the same value.

Parameters

mime_part

a GMimePart object

 

description

a UTF-8 description, or NULL to remove it.

[nullable]

g_mime_part_get_content_description ()

const char *
g_mime_part_get_content_description (GMimePart *mime_part);

Gets the first Content-Description value, trimming surrounding ASCII linear whitespace without changing the header. Matching header changes invalidate the cached value; duplicate headers do not override the first.

Parameters

mime_part

a GMimePart object

 

Returns

the borrowed content description, or NULL if absent.

[nullable]


g_mime_part_set_content_duration ()

void
g_mime_part_set_content_duration (GMimePart *mime_part,
                                  int duration);

Sets Content-Duration to a nonnegative decimal Int32 value, replacing matching duplicate headers. -1 removes all Content-Duration headers. Values below -1 are programming errors and leave the part unchanged.

Assigning the current cached value preserves raw headers and duplicates. Before the first read, even -1 removes malformed headers; after a read that returns -1, assigning -1 is a no-op until matching headers change.

Parameters

mime_part

a GMimePart

 

duration

the duration in seconds, or -1 to remove the header

 

g_mime_part_get_content_duration ()

int
g_mime_part_get_content_duration (GMimePart *mime_part);

Gets the duration in seconds from the first Content-Duration header. Only a complete nonnegative decimal Int32 value in the raw header with optional surrounding ASCII linear whitespace is accepted. Signs, comments, fractions, and overflow are invalid; an invalid first header does not fall back to duplicates. RFC 2047 encoded words are not decoded. Reads preserve raw headers. Matching header changes invalidate the cache.

Parameters

mime_part

a GMimePart

 

Returns

the duration in seconds, or -1 if the header is missing or invalid.


g_mime_part_set_content_id ()

void
g_mime_part_set_content_id (GMimePart *mime_part,
                            const char *content_id);

Sets the content ID, or removes all Content-Id headers if content_id is NULL. See g_mime_entity_set_content_id() for validation and normalization.

Parameters

mime_part

a GMimePart object

 

content_id

a UTF-8 content-id, with or without angle brackets.

[nullable]

g_mime_part_get_content_id ()

const char *
g_mime_part_get_content_id (GMimePart *mime_part);

Gets the content-id of the specified mime part if it exists, or NULL otherwise.

Parameters

mime_part

a GMimePart object

 

Returns

the content ID, or NULL if not set.

[nullable]


g_mime_part_set_content_md5 ()

void
g_mime_part_set_content_md5 (GMimePart *mime_part,
                             const char *content_md5);

Sets the Content-MD5 header, trimming leading and trailing ASCII linear whitespace (SP, HTAB, CR and LF). Empty values are allowed. This does not read the content or compute a digest; use g_mime_part_compute_content_md5() separately. Assigning the current cached value preserves raw headers and duplicates. Before the first read, assignment replaces matching duplicates even if the first header already has the same value. Comparison precedes trimming.

Parameters

mime_part

a GMimePart object

 

content_md5

the UTF-8 digest value, or NULL to remove it.

[nullable]

g_mime_part_get_content_md5 ()

const char *
g_mime_part_get_content_md5 (GMimePart *mime_part);

Gets the first Content-MD5 value, trimming surrounding ASCII linear whitespace without changing raw headers. Matching header changes invalidate the cached value; later duplicates do not override the first header. Missing headers return NULL; values empty after trimming return "".

Parameters

mime_part

a GMimePart object

 

Returns

the borrowed, trimmed digest value.

[nullable][transfer none]


g_mime_part_compute_content_md5 ()

char *
g_mime_part_compute_content_md5 (GMimePart *mime_part,
                                 GError **error);

Computes the base64-encoded MD5 of the decoded content in canonical form. For text parts, bare LF bytes become CRLF without adding a final newline or converting the charset. Other media types are hashed verbatim. No headers, content objects or transfer encodings are changed.

The backing stream is rewound before reading and left at EOF on success, without being closed. On failure, it is left at its current position. A new computation rewinds again; concurrent use of the shared source can interfere with reading, as described in g_mime_content_open().

Missing content or a missing backing stream reports GMIME_ERROR_INVALID_OPERATION. Rewind and read failures report a GMIME_ERROR using errno, or GMIME_ERROR_GENERAL if errno is unset. A zero-byte read without EOF reports EIO instead of a partial digest.

Parameters

mime_part

a GMimePart object

 

error

return location for a GError, or NULL

 

Returns

the digest, or NULL on error.

[nullable][transfer full]


g_mime_part_verify_content_md5 ()

gboolean
g_mime_part_verify_content_md5 (GMimePart *mime_part,
                                GError **error);

Compares the Content-MD5 value with an independently computed digest using exact, case-sensitive equality. Missing or empty trimmed values and missing content return FALSE without reading the source or setting an error. Other failures follow g_mime_part_compute_content_md5().

Parameters

mime_part

a GMimePart object

 

error

return location for a GError, or NULL

 

Returns

TRUE if the digest matches; FALSE for a mismatch or error.


g_mime_part_set_content_location ()

void
g_mime_part_set_content_location (GMimePart *mime_part,
                                  const char *content_location);

Sets the content location. See g_mime_entity_set_content_location() for URI validation, duplicate-header handling, and removal with NULL.

Parameters

mime_part

a GMimePart object

 

content_location

an absolute or relative UTF-8 URI.

[nullable]

g_mime_part_get_content_location ()

const char *
g_mime_part_get_content_location (GMimePart *mime_part);

Gets the value of the Content-Location header if it exists, or NULL otherwise.

Parameters

mime_part

a GMimePart object

 

Returns

the borrowed content location, or NULL if absent or invalid.

[nullable]


g_mime_part_set_content_encoding ()

void
g_mime_part_set_content_encoding (GMimePart *mime_part,
                                  GMimeContentEncoding encoding);

Sets the desired transfer encoding using its canonical header name. GMIME_CONTENT_ENCODING_UNSPECIFIED removes all matching headers. Assigning the current cached value preserves raw headers and duplicates; before the first read, assignment replaces or removes matching headers. Values outside GMimeContentEncoding are programming errors and leave the part unchanged. This does not change the backing content's encoding.

Parameters

mime_part

a GMimePart object

 

encoding

a GMimeContentEncoding

 

g_mime_part_get_content_encoding ()

GMimeContentEncoding
g_mime_part_get_content_encoding (GMimePart *mime_part);

Gets the desired transfer encoding from the first matching header, without rewriting raw headers. A missing or unrecognized first value returns GMIME_CONTENT_ENCODING_UNSPECIFIED, without falling back to later duplicates. Matching header edits invalidate the lazy cache. The raw value is parsed without RFC 2047 decoding. The legacy 7-bit and 8-bit aliases remain supported.

Parameters

mime_part

a GMimePart object

 

Returns

the content encoding for the specified mime part.


g_mime_part_get_best_content_encoding ()

GMimeContentEncoding
g_mime_part_get_best_content_encoding (GMimePart *mime_part,
                                       GMimeEncodingConstraint constraint,
                                       GError **error);

Calculates the most efficient content encoding using a maximum line length of 78, excluding CRLF. This is equivalent to calling g_mime_part_get_best_content_encoding_with_max_line_length() with that limit, including its content dispatch, positioning and error behavior.

Parameters

mime_part

a GMimePart object

 

constraint

a GMimeEncodingConstraint

 

error

return location for a GError, or NULL

 

Returns

the best encoding, or GMIME_CONTENT_ENCODING_UNSPECIFIED on error.


g_mime_part_get_best_content_encoding_with_max_line_length ()

GMimeContentEncoding
g_mime_part_get_best_content_encoding_with_max_line_length
                               (GMimePart *mime_part,
                                GMimeEncodingConstraint constraint,
                                guint max_line_length,
                                GError **error);

Analyzes decoded text and message content without changing headers, content objects or transfer encodings. Missing text/message content returns 7bit. Other media types return binary for the binary constraint and base64 otherwise, without reading content. These fast paths do not validate the constraint or line limit, matching MimeKit.

Analysis calls g_mime_content_decode_to_stream(), honoring content write and decode overrides. The default content implementation rewinds its source before reading and again on success, leaving it open. I/O failures preserve the failure position and report a GMIME_ERROR using errno, or GMIME_ERROR_GENERAL if errno is unset. A missing backing stream reports GMIME_ERROR_INVALID_OPERATION.

The line limit and constraint are validated after successful analysis; invalid values report EINVAL. No encoding is returned for partial content after an I/O error, even if a selection could otherwise be made.

Parameters

mime_part

a GMimePart object

 

constraint

a GMimeEncodingConstraint

 

max_line_length

maximum line length, excluding CRLF, from 60 through 998

 

error

return location for a GError, or NULL

 

Returns

the best encoding, or GMIME_CONTENT_ENCODING_UNSPECIFIED on error.


g_mime_part_set_filename ()

void
g_mime_part_set_filename (GMimePart *mime_part,
                          const char *filename);

Sets both the Content-Disposition filename and Content-Type name parameters without trimming their values. A non-NULL value creates an attachment disposition if absent; existing dispositions are preserved. An empty string is an explicit filename. NULL removes both parameters without creating or removing a disposition.

Existing parameter objects and formatting metadata are preserved. Invalid UTF-8 is a programming error and leaves the part unchanged.

Parameters

mime_part

a GMimePart object

 

filename

the UTF-8 filename, or NULL to remove it.

[nullable]

g_mime_part_get_filename ()

const char *
g_mime_part_get_filename (GMimePart *mime_part);

Gets the Content-Disposition filename, falling back to the Content-Type name only if the filename parameter is absent. Parameter values are preserved without trimming or changing the raw headers. Empty and all-whitespace filenames do not trigger the fallback.

The returned filename is untrusted and is not sanitized for filesystem use.

Parameters

mime_part

a GMimePart object

 

Returns

the borrowed UTF-8 filename, or NULL if neither parameter exists. The value is valid until a subsequent call returns a different filename or the part is finalized.

[nullable][transfer none]


g_mime_part_get_content ()

GMimeContent *
g_mime_part_get_content (GMimePart *mime_part);

Gets the content of the specified mime part, or NULL if no content has been assigned.

Parameters

mime_part

a GMimePart object

 

Returns

the part's content. The reference is valid until the content is replaced or the part is finalized.

[transfer none][nullable]


g_mime_part_set_content ()

void
g_mime_part_set_content (GMimePart *mime_part,
                         GMimeContent *content);

Sets the content on the mime part, or clears it when content is NULL. The part retains a reference to content .

Parameters

mime_part

a GMimePart object

 

content

a GMimeContent content object.

[nullable]

g_mime_part_get_openpgp_data ()

GMimeOpenPGPData
g_mime_part_get_openpgp_data (GMimePart *mime_part);

Gets whether or not (and what type) of OpenPGP data is contained within the GMimePart.

Parameters

mime_part

a GMimePart

 

Returns

a GMimeOpenPGPData.


g_mime_part_set_openpgp_data ()

void
g_mime_part_set_openpgp_data (GMimePart *mime_part,
                              GMimeOpenPGPData data);

Sets whether or not (and what type) of OpenPGP data is contained within the GMimePart.

Parameters

mime_part

a GMimePart

 

data

a GMimeOpenPGPData

 

g_mime_part_openpgp_encrypt ()

gboolean
g_mime_part_openpgp_encrypt (GMimePart *mime_part,
                             gpgme_ctx_t ctx,
                             gboolean sign,
                             gpgme_encrypt_flags_t flags,
                             gpgme_key_t *recipients,
                             gpgme_key_t *hidden_recipients,
                             gpgme_encrypt_result_t *encrypt_result,
                             gpgme_sign_result_t *sign_result,
                             GError **err);

Encrypts (and optionally signs) the content of the mime_part and then replaces the content with the new, encrypted, content. Hidden recipients receive the same content without exposing their key IDs. See g_mime_gpgme_encrypt() for recipient-array and encryption-flag semantics.

[skip]

Parameters

mime_part

a GMimePart

 

ctx

a borrowed GPGME OpenPGP context

 

sign

TRUE if the content should also be signed; otherwise, FALSE

 

flags

native GPGME encryption flags

 

recipients

borrowed NULL-terminated recipient keys.

[nullable]

hidden_recipients

borrowed NULL-terminated hidden recipient keys.

[nullable]

encrypt_result

a retained encryption result.

[out][optional]

sign_result

a retained signing result.

[out][optional]

err

a GError

 

Returns

TRUE on success or FALSE on error.


g_mime_part_openpgp_decrypt ()

gboolean
g_mime_part_openpgp_decrypt (GMimePart *mime_part,
                             gpgme_ctx_t ctx,
                             gpgme_decrypt_result_t *decrypt_result,
                             gpgme_verify_result_t *verify_result,
                             GError **err);

Decrypts the content of the mime_part and then replaces the content with the new, decrypted, content.

[skip]

Parameters

mime_part

a GMimePart

 

ctx

a borrowed GPGME OpenPGP context

 

decrypt_result

a retained decryption result.

[out][optional]

verify_result

a retained verification result.

[out][optional]

err

a GError

 

Returns

TRUE on success. Inspect embedded signatures separately.


g_mime_part_openpgp_sign ()

gboolean
g_mime_part_openpgp_sign (GMimePart *mime_part,
                          gpgme_ctx_t ctx,
                          gpgme_sign_result_t *result,
                          GError **err);

Signs the content of the mime_part and then replaces the content with the new, signed, content.

[skip]

Parameters

mime_part

a GMimePart

 

ctx

a borrowed GPGME OpenPGP context with configured signers

 

result

a retained signing result.

[out][optional]

err

a GError

 

Returns

TRUE on success or FALSE on error.


g_mime_part_openpgp_verify ()

gboolean
g_mime_part_openpgp_verify (GMimePart *mime_part,
                            gpgme_ctx_t ctx,
                            gpgme_verify_result_t *result,
                            GError **err);

Verifies the OpenPGP signature of the mime_part and then replaces the content with the original, raw, content.

[skip]

Parameters

mime_part

a GMimePart

 

ctx

a borrowed GPGME OpenPGP context

 

result

a retained verification result.

[out][optional]

err

a GError

 

Returns

TRUE if verification completed. Inspect signature status and validity before presenting the extracted content as authenticated.

Types and Values

GMimePart

typedef struct _GMimePart GMimePart;

A leaf-node MIME part object.