| Top |
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.
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().
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.
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.
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.
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().
options |
parser options, or |
[nullable] |
content_type |
the Content-Type of |
|
content |
the body stream, positioned at the start of the content to load |
|
error |
return location for a GError, or |
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().
options |
parser options, or |
[nullable] |
stream |
the input stream at the start of the entity |
|
error |
return location for a GError, or |
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.
options |
parser options, or |
[nullable] |
stream |
input positioned at the start of the entity |
|
storage |
storage for parsed MIME part content |
|
error |
return location for a GError, or |
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.
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.
GMimeContentType *
g_mime_entity_get_content_type (GMimeEntity *object);
Gets the GMimeContentType object for the given MIME object or
NULL on fail.
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.
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
.
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.
const char *
g_mime_entity_get_disposition (GMimeEntity *object);
Gets the MIME object's disposition if set or NULL otherwise.
the disposition string which is probably one of GMIME_DISPOSITION_ATTACHMENT or GMIME_DISPOSITION_INLINE.
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.
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.
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.
GMimeContentDisposition *
g_mime_entity_get_content_disposition (GMimeEntity *object);
Gets the GMimeContentDisposition for the specified MIME object.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
gboolean g_mime_entity_remove_header (GMimeEntity *object,const char *header);
Removed the specified header if it exists.
void g_mime_entity_set_header (GMimeEntity *object,const char *header,const char *value,const char *charset);
Sets a header to the specified value.
const char * g_mime_entity_get_header (GMimeEntity *object,const char *header);
Gets the value of the first header with the specified name.
char * g_mime_entity_get_headers (GMimeEntity *object,GMimeFormatOptions *options);
Allocates a string buffer containing all of the MIME object's raw headers.
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]
GMimeHeaderList *
g_mime_entity_get_header_list (GMimeEntity *object);
Get the header list for object
.
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
.
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
.
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.
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().
char * g_mime_entity_to_string (GMimeEntity *object,GMimeFormatOptions *options);
Allocates a string buffer containing the contents of object
.
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.
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.
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().