GMimeEntity

GMimeEntity — Abstract MIME objects

Functions

void (*GMimeEntityForeachFunc) ()
void g_mime_entity_register_type ()
GMimeEntity * g_mime_entity_new ()
GMimeEntity * g_mime_entity_new_type ()
GMimeEntity * g_mime_entity_load_with_content_type ()
GMimeEntity * g_mime_entity_load ()
GMimeEntity * g_mime_entity_load_with_storage ()
GMimeEntity * g_mime_entity_load_from_file ()
void g_mime_entity_set_content_type ()
GMimeContentType * g_mime_entity_get_content_type ()
void g_mime_entity_set_content_type_parameter ()
const char * g_mime_entity_get_content_type_parameter ()
void g_mime_entity_set_disposition ()
const char * g_mime_entity_get_disposition ()
gboolean g_mime_entity_is_attachment ()
void g_mime_entity_set_is_attachment ()
void g_mime_entity_set_content_disposition ()
GMimeContentDisposition * g_mime_entity_get_content_disposition ()
void g_mime_entity_set_content_disposition_parameter ()
const char * g_mime_entity_get_content_disposition_parameter ()
void g_mime_entity_set_content_id ()
const char * g_mime_entity_get_content_id ()
void g_mime_entity_set_content_base ()
const char * g_mime_entity_get_content_base ()
void g_mime_entity_set_content_location ()
const char * g_mime_entity_get_content_location ()
void g_mime_entity_prepend_header ()
void g_mime_entity_append_header ()
gboolean g_mime_entity_remove_header ()
void g_mime_entity_set_header ()
const char * g_mime_entity_get_header ()
char * g_mime_entity_get_headers ()
GMimeHeaderList * g_mime_entity_get_header_list ()
ssize_t g_mime_entity_write_to_stream ()
ssize_t g_mime_entity_write_content_to_stream ()
gboolean g_mime_entity_write_to_file ()
gboolean g_mime_entity_write_content_to_file ()
char * g_mime_entity_to_string ()
gboolean g_mime_entity_prepare ()
gboolean g_mime_entity_prepare_with_max_line_length ()
void g_mime_entity_accept ()

Types and Values

Description

GMimeEntity is an abstract class from which all message and MIME parts are derived.

Containers release their child references iteratively to avoid stack overflow with deeply nested messages. Descendant releases may be deferred until the outermost release completes. Subclass finalizers must not rely on descendants having finalized when chaining to their parent finalizer.

Functions

GMimeEntityForeachFunc ()

void
(*GMimeEntityForeachFunc) (GMimeEntity *parent,
                           GMimeEntity *part,
                           gpointer user_data);

The function signature for a callback to g_mime_message_foreach() and g_mime_multipart_foreach().

Parameters

parent

parent GMimeEntity

 

part

a GMimeEntity

 

user_data

User-supplied callback data.

 

g_mime_entity_register_type ()

void
g_mime_entity_register_type (const char *type,
                             const char *subtype,
                             GType object_type);

Registers the object type object_type for use with the g_mime_entity_new_type() convenience function.

Note: You may use the wildcard "*" to match any type and/or subtype.

Parameters

type

mime type

 

subtype

mime subtype

 

object_type

object type

 

g_mime_entity_new ()

GMimeEntity *
g_mime_entity_new (GMimeParserOptions *options,
                   GMimeContentType *content_type);

Performs a lookup of registered GMimeEntity subclasses, registered using g_mime_entity_register_type(), to find an appropriate class capable of handling MIME parts of the specified Content-Type. If no class has been registered to handle that type, it looks for a registered class that can handle content_type 's media type. If that also fails, then it will use the generic part class, GMimePart.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

content_type

a GMimeContentType object

 

Returns

an appropriate GMimeEntity registered to handle MIME parts appropriate for content_type .


g_mime_entity_new_type ()

GMimeEntity *
g_mime_entity_new_type (GMimeParserOptions *options,
                        const char *type,
                        const char *subtype);

Performs a lookup of registered GMimeEntity subclasses, registered using g_mime_entity_register_type(), to find an appropriate class capable of handling MIME parts of type type /subtype . If no class has been registered to handle that type, it looks for a registered class that can handle type . If that also fails, then it will use the generic part class, GMimePart.

Parameters

options

a GMimeParserOptions or NULL.

[nullable]

type

mime type

 

subtype

mime subtype

 

Returns

an appropriate GMimeEntity registered to handle mime-types of type /subtype .


g_mime_entity_load_with_content_type ()

GMimeEntity *
g_mime_entity_load_with_content_type (GMimeParserOptions *options,
                                      GMimeContentType *content_type,
                                      GMimeStream *content,
                                      GError **error);

Loads an entity from a body stream whose Content-Type was supplied separately, such as an HTTP response body. A serialized Content-Type header is prepended before parsing; content_type is not retained or modified. The parser selects the entity subclass from that header.

Content is copied into memory. The returned entity remains usable after content is closed, modified or released. The input is read from its current position without seeking, resetting or closing it, and need not support seeking. Parser options and errors have the same semantics as g_mime_parser_construct_part().

Parameters

options

parser options, or NULL for defaults.

[nullable]

content_type

the Content-Type of content

 

content

the body stream, positioned at the start of the content to load

 

error

return location for a GError, or NULL

 

Returns

the loaded entity, or NULL on failure.

[nullable][transfer full]


g_mime_entity_load ()

GMimeEntity *
g_mime_entity_load (GMimeParserOptions *options,
                    GMimeStream *stream,
                    GError **error);

Loads a MIME entity, copying its content into memory. The input need not support seeking and is neither reset nor closed. The returned entity remains usable after stream is closed, modified or released.

Unlike g_mime_parser_construct_part(), empty input is a parse error. The input must start with entity headers; message-specific byte-order mark handling is provided by g_mime_message_load().

Parameters

options

parser options, or NULL for defaults.

[nullable]

stream

the input stream at the start of the entity

 

error

return location for a GError, or NULL

 

Returns

the entity, or NULL on failure.

[nullable][transfer full]


g_mime_entity_load_with_storage ()

GMimeEntity *
g_mime_entity_load_with_storage (GMimeParserOptions *options,
                                 GMimeStream *stream,
                                 GMimeContentStorage storage,
                                 GError **error);

Loads an entity using the requested content storage. Memory storage behaves like g_mime_entity_load(). Source storage references leaf content through substreams instead of copying it, and requires working tell, seek and substream operations. Seekability is checked with a zero-offset seek from the current position before reading. Unsupported operations and I/O failures report GMIME_ERROR rather than falling back to memory.

The caller owns stream in both modes. With source storage, keep it open and unchanged while parsed content is in use. Content views retain it; releasing the entity does not close a stream still owned by the caller. Empty input is a parse error. The stream is neither reset nor closed.

Parameters

options

parser options, or NULL for defaults.

[nullable]

stream

input positioned at the start of the entity

 

storage

storage for parsed MIME part content

 

error

return location for a GError, or NULL

 

Returns

the entity, or NULL on failure.

[nullable][transfer full]


g_mime_entity_load_from_file ()

GMimeEntity *
g_mime_entity_load_from_file (GMimeParserOptions *options,
                              const char *filename,
                              GError **error);

Loads a MIME entity from filename using g_mime_entity_load(). The file is opened for reading and closed before returning, on success or failure. Content is copied into memory and does not retain the file. Open, read, parse and close failures return NULL with error set.

Parameters

options

parser options, or NULL for defaults.

[nullable]

filename

the input file path.

[type filename]

error

return location for a GError, or NULL

 

Returns

the entity, or NULL on failure.

[nullable][transfer full]


g_mime_entity_set_content_type ()

void
g_mime_entity_set_content_type (GMimeEntity *object,
                                GMimeContentType *content_type);

Sets the content-type for the specified MIME object and then serializes it to the Content-Type header field.

Parameters

object

a GMimeEntity

 

content_type

a GMimeContentType object

 

g_mime_entity_get_content_type ()

GMimeContentType *
g_mime_entity_get_content_type (GMimeEntity *object);

Gets the GMimeContentType object for the given MIME object or NULL on fail.

Parameters

object

a GMimeEntity

 

Returns

the content-type object for the specified MIME object.

[transfer none]


g_mime_entity_set_content_type_parameter ()

void
g_mime_entity_set_content_type_parameter
                               (GMimeEntity *object,
                                const char *name,
                                const char *value);

Sets the content-type param name to the value value .

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

Parameters

object

a GMimeEntity

 

name

param name

 

value

param value

 

g_mime_entity_get_content_type_parameter ()

const char *
g_mime_entity_get_content_type_parameter
                               (GMimeEntity *object,
                                const char *name);

Gets the value of the content-type param name set on the MIME part object .

Parameters

object

a GMimeEntity

 

name

param name

 

Returns

the value of the requested content-type param or NULL if the param doesn't exist. If the param is set, the returned string will be in UTF-8.


g_mime_entity_set_disposition ()

void
g_mime_entity_set_disposition (GMimeEntity *object,
                               const char *disposition);

Sets the disposition to disposition which may be one of GMIME_DISPOSITION_ATTACHMENT or GMIME_DISPOSITION_INLINE or, by your choice, any other string which would indicate how the MIME part should be displayed by the MUA.

Parameters

object

a GMimeEntity

 

disposition

disposition ("attachment" or "inline")

 

g_mime_entity_get_disposition ()

const char *
g_mime_entity_get_disposition (GMimeEntity *object);

Gets the MIME object's disposition if set or NULL otherwise.

Parameters

object

a GMimeEntity

 

Returns

the disposition string which is probably one of GMIME_DISPOSITION_ATTACHMENT or GMIME_DISPOSITION_INLINE.


g_mime_entity_is_attachment ()

gboolean
g_mime_entity_is_attachment (GMimeEntity *object);

Determines whether the Content-Disposition is "attachment", ignoring ASCII case. A filename alone does not make an entity an attachment.

Parameters

object

a GMimeEntity

 

Returns

TRUE for an attachment, or FALSE otherwise.


g_mime_entity_set_is_attachment ()

void
g_mime_entity_set_is_attachment (GMimeEntity *object,
                                 gboolean attachment);

Sets Content-Disposition to "attachment" when attachment is TRUE and the entity is not already an attachment. Setting FALSE changes an attachment to "inline", but leaves missing or other dispositions alone. Existing parameters are retained. Assigning the current attachment status preserves raw spelling and duplicate headers.

Parameters

object

a GMimeEntity

 

attachment

whether the entity is an attachment

 

g_mime_entity_set_content_disposition ()

void
g_mime_entity_set_content_disposition (GMimeEntity *object,
                                       GMimeContentDisposition *disposition);

Set the content disposition for the specified mime part and then serializes it to the Content-Disposition header field.

Parameters

object

a GMimeEntity

 

disposition

a GMimeContentDisposition object

 

g_mime_entity_get_content_disposition ()

GMimeContentDisposition *
g_mime_entity_get_content_disposition (GMimeEntity *object);

Gets the GMimeContentDisposition for the specified MIME object.

Parameters

object

a GMimeEntity

 

Returns

the GMimeContentDisposition set on the MIME object.

[transfer none]


g_mime_entity_set_content_disposition_parameter ()

void
g_mime_entity_set_content_disposition_parameter
                               (GMimeEntity *object,
                                const char *name,
                                const char *value);

Add a content-disposition parameter to the specified mime part.

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

Parameters

object

a GMimeEntity

 

name

parameter name

 

value

parameter value

 

g_mime_entity_get_content_disposition_parameter ()

const char *
g_mime_entity_get_content_disposition_parameter
                               (GMimeEntity *object,
                                const char *name);

Gets the value of the Content-Disposition parameter specified by name , or NULL if the parameter does not exist.

Parameters

object

a GMimeEntity

 

name

parameter name

 

Returns

the value of the requested content-disposition param or NULL if the param doesn't exist. If the param is set, the returned string will be in UTF-8.


g_mime_entity_set_content_id ()

void
g_mime_entity_set_content_id (GMimeEntity *object,
                              const char *content_id);

Sets the Content-Id after normalizing a complete message-id, or removes all Content-Id headers if content_id is NULL. Invalid values are programming errors and leave the entity unchanged. Assigning the current ID preserves the original raw header.

Parameters

object

a GMimeEntity

 

content_id

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

[nullable]

g_mime_entity_get_content_id ()

const char *
g_mime_entity_get_content_id (GMimeEntity *object);

Gets the Content-Id of the MIME object or NULL if one is not set.

Parameters

object

a GMimeEntity

 

Returns

the Content-Id, or NULL if not set.

[nullable]


g_mime_entity_set_content_base ()

void
g_mime_entity_set_content_base (GMimeEntity *object,
                                const char *uri);

Sets Content-Base, replacing duplicate headers. Invalid URI strings and relative references are programming errors and leave the entity unchanged. URI strings are validated using GLib without canonicalizing their spelling. Unescaped ASCII whitespace, controls, and unsafe delimiters are rejected.

Assigning the cached string preserves raw headers and duplicates. Setting NULL before the first read removes even malformed headers; after a read returning NULL, assigning NULL is a no-op until matching headers change.

Parameters

object

a GMimeEntity

 

uri

an absolute UTF-8 URI, or NULL to remove the header.

[nullable]

g_mime_entity_get_content_base ()

const char *
g_mime_entity_get_content_base (GMimeEntity *object);

Gets the absolute URI from the first Content-Base header. After header decoding, only surrounding ASCII linear whitespace (SP, HTAB, CR and LF) is trimmed. Invalid or relative values return NULL without falling back to later duplicates. Reads preserve raw headers; matching header edits invalidate the cached value.

Parameters

object

a GMimeEntity

 

Returns

a borrowed URI string, or NULL if absent or invalid.

[nullable]


g_mime_entity_set_content_location ()

void
g_mime_entity_set_content_location (GMimeEntity *object,
                                    const char *uri);

Sets Content-Location, replacing duplicate headers. An empty string is a valid relative reference. Validation and cached-string no-op behavior are the same as g_mime_entity_set_content_base(), but relative references are accepted. URI spelling and percent escapes are preserved.

Parameters

object

a GMimeEntity

 

uri

an absolute or relative UTF-8 URI, or NULL to remove the header.

[nullable]

g_mime_entity_get_content_location ()

const char *
g_mime_entity_get_content_location (GMimeEntity *object);

Gets the absolute or relative URI from the first Content-Location header. Trimming, invalid-value handling, and cache invalidation are the same as g_mime_entity_get_content_base(). An empty relative reference is returned as an empty string, not NULL.

Parameters

object

a GMimeEntity

 

Returns

a borrowed URI string, or NULL if absent or invalid.

[nullable]


g_mime_entity_prepend_header ()

void
g_mime_entity_prepend_header (GMimeEntity *object,
                              const char *header,
                              const char *value,
                              const char *charset);

Prepends a new header to the header list.

Parameters

object

a GMimeEntity

 

header

header name

 

value

header value

 

charset

a charset.

[nullable]

g_mime_entity_append_header ()

void
g_mime_entity_append_header (GMimeEntity *object,
                             const char *header,
                             const char *value,
                             const char *charset);

Appends a new header to the header list.

Parameters

object

a GMimeEntity

 

header

header name

 

value

header value

 

charset

a charset.

[nullable]

g_mime_entity_remove_header ()

gboolean
g_mime_entity_remove_header (GMimeEntity *object,
                             const char *header);

Removed the specified header if it exists.

Parameters

object

a GMimeEntity

 

header

header name

 

Returns

TRUE if the header was removed or FALSE if it could not be found.


g_mime_entity_set_header ()

void
g_mime_entity_set_header (GMimeEntity *object,
                          const char *header,
                          const char *value,
                          const char *charset);

Sets a header to the specified value.

Parameters

object

a GMimeEntity

 

header

header name

 

value

header value

 

charset

a charset.

[nullable]

g_mime_entity_get_header ()

const char *
g_mime_entity_get_header (GMimeEntity *object,
                          const char *header);

Gets the value of the first header with the specified name.

Parameters

object

a GMimeEntity

 

header

header name

 

Returns

the value of the requested header if it exists or NULL otherwise.

[nullable]


g_mime_entity_get_headers ()

char *
g_mime_entity_get_headers (GMimeEntity *object,
                           GMimeFormatOptions *options);

Allocates a string buffer containing all of the MIME object's raw headers.

Parameters

object

a GMimeEntity

 

options

a GMimeFormatOptions or NULL.

[nullable]

Returns

an allocated string containing all of the raw MIME headers, or NULL on failure.

Note: The returned string will not be suitable for display.

[nullable]


g_mime_entity_get_header_list ()

GMimeHeaderList *
g_mime_entity_get_header_list (GMimeEntity *object);

Get the header list for object .

Parameters

object

a GMimeEntity

 

Returns

the GMimeHeaderList for object . Do not free this pointer when you are done with it.

[transfer none]


g_mime_entity_write_to_stream ()

ssize_t
g_mime_entity_write_to_stream (GMimeEntity *object,
                               GMimeFormatOptions *options,
                               GMimeStream *stream);

Write the headers and content of the MIME object to stream .

Parameters

object

a GMimeEntity

 

options

a GMimeFormatOptions or NULL.

[nullable]

stream

stream

 

Returns

the number of bytes written or -1 on fail.


g_mime_entity_write_content_to_stream ()

ssize_t
g_mime_entity_write_content_to_stream (GMimeEntity *object,
                                       GMimeFormatOptions *options,
                                       GMimeStream *stream);

Write only the content of the MIME object to stream .

Parameters

object

a GMimeEntity

 

options

a GMimeFormatOptions or NULL.

[nullable]

stream

stream

 

Returns

the number of bytes written or -1 on fail.


g_mime_entity_write_to_file ()

gboolean
g_mime_entity_write_to_file (GMimeEntity *object,
                             GMimeFormatOptions *options,
                             const char *filename,
                             GError **error);

Writes the entity's headers and content to filename using the same virtual writer as g_mime_entity_write_to_stream(). Also accepts a GMimeMessage to write a complete message.

Creates the file or truncates an existing file before serialization, then flushes and closes it. Failures leave the created or partially written file in place; the operation is not atomic. Do not use the file backing the entity's source content as the destination.

Open, write, flush and close failures report GMIME_ERROR with the corresponding errno code, or GMIME_ERROR_GENERAL if none is supplied. Cleanup preserves the first failure. The destination is closed on both success and failure, even if a custom writer retains the stream.

Parameters

object

a GMimeEntity

 

options

formatting options, or NULL for defaults.

[nullable]

filename

the output file path.

[type filename]

error

return location for a GError, or NULL

 

Returns

TRUE on success, or FALSE on failure.


g_mime_entity_write_content_to_file ()

gboolean
g_mime_entity_write_content_to_file (GMimeEntity *object,
                                     GMimeFormatOptions *options,
                                     const char *filename,
                                     GError **error);

Writes only the entity's content to filename , without its headers. Uses g_mime_entity_write_content_to_stream() semantics and the same create/truncate, flush, close and error handling as g_mime_entity_write_to_file().

Parameters

object

a GMimeEntity

 

options

formatting options, or NULL for defaults.

[nullable]

filename

the output file path.

[type filename]

error

return location for a GError, or NULL

 

Returns

TRUE on success, or FALSE on failure.


g_mime_entity_to_string ()

char *
g_mime_entity_to_string (GMimeEntity *object,
                         GMimeFormatOptions *options);

Allocates a string buffer containing the contents of object .

Parameters

object

a GMimeEntity

 

options

a GMimeFormatOptions or NULL.

[nullable]

Returns

an allocated string containing the contents of the mime object.


g_mime_entity_prepare ()

gboolean
g_mime_entity_prepare (GMimeEntity *object,
                       GMimeEncodingConstraint constraint,
                       GError **error);

Prepares this entity and its children for transport using a maximum line length of 78. Equivalent to g_mime_entity_prepare_with_max_line_length() with that limit.

Parameters

object

a GMimeEntity

 

constraint

a GMimeEncodingConstraint

 

error

return location for a GError, or NULL

 

Returns

TRUE on success, or FALSE on failure.


g_mime_entity_prepare_with_max_line_length ()

gboolean
g_mime_entity_prepare_with_max_line_length
                               (GMimeEntity *object,
                                GMimeEncodingConstraint constraint,
                                guint max_line_length,
                                GError **error);

Prepares an entity tree for transport using each entity's prepare_with_max_line_length virtual method. Parts use g_mime_part_prepare_with_max_line_length(); multiparts prepare their children in order; message parts prepare their encapsulated messages. Signed multiparts do not modify or analyze their children.

Messages add MIME-Version: 1.0 when their body has headers but their first MIME-Version header is absent or invalid, then prepare the body.

An invalid line limit reports GMIME_ERROR with EINVAL before virtual dispatch or any header changes. Constraint validation otherwise follows the leaf-part policy, including its safe-encoding fast paths. A subclass without a prepare implementation reports GMIME_ERROR_NOT_SUPPORTED.

Preparation stops at the first failure. Earlier child changes and message MIME-Version updates are retained, matching MimeKit's preparation order; this is not an atomic operation on the entire tree. The failing leaf preserves its transfer headers and previous encoder limit.

Reports analysis failures and carries the requested encoder line limit into serialization.

Parameters

object

a GMimeEntity

 

constraint

a GMimeEncodingConstraint

 

max_line_length

maximum line length, excluding CRLF, from 60 through 998

 

error

return location for a GError, or NULL

 

Returns

TRUE on success, or FALSE on failure.


g_mime_entity_accept ()

void
g_mime_entity_accept (GMimeEntity *object,
                      GMimeVisitor *visitor);

Dispatches object to the visitor's most specific visit method. Subclasses can override the accept virtual method to select a different visit method. The base implementation calls g_mime_visitor_visit_entity().

Parameters

object

a GMimeEntity

 

visitor

a GMimeVisitor

 

Types and Values

GMimeEntity

typedef struct _GMimeEntity GMimeEntity;

Base class for all MIME parts.