| Top |
| enum | GMimeAddressType |
| enum | GMimeMessageImportance |
| enum | GMimeMessagePriority |
| enum | GMimeXMessagePriority |
| GMimeMessage |
A GMimeMessage represents an rfc822 message. Message header values are parsed on demand and cached until their headers change. Address lists are also allocated on demand. Reading metadata does not rewrite raw headers.
Changed or removed address headers clear a previously returned list; the
next message getter reloads that same list. Appending a header extends an
already loaded list. References are cleared on any References header change
and reloaded by g_mime_message_get_references(). Reacquire these lists through
the message after editing raw headers. Editing a retained list instead makes
its contents authoritative and updates the corresponding headers.
The legacy parser warning callback requires eager address parsing to retain its existing warning timing. Compliance logging is independent of lazy metadata and continues to report issues during parsing.
GMimeMessage *
g_mime_message_new (gboolean pretty_headers);
If pretty_headers
is TRUE, then the standard rfc822 headers are
initialized so as to put headers in a nice friendly order. This is
strictly a cosmetic thing, so if you are unsure, it is safe to say
no (FALSE).
GMimeMessage * g_mime_message_load (GMimeParserOptions *options,GMimeStream *stream,GError **error);
Loads a message, copying its content into memory. An optional leading
UTF-8 byte-order mark is consumed. The input need not support seeking
and is neither reset nor closed. The returned message remains usable
after stream
is closed, modified or released.
Empty input is a parse error. This loads a single MIME message, not an mbox or MMDF mailbox; use GMimeParser for mailbox input.
options |
parser options, or |
[nullable] |
stream |
the input stream at the start of the message |
|
error |
return location for a GError, or |
GMimeMessage * g_mime_message_load_with_storage (GMimeParserOptions *options,GMimeStream *stream,GMimeContentStorage storage,GError **error);
Loads a message using the requested content storage. Memory storage
behaves like g_mime_message_load(). Source storage references leaf
content through substreams 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 message does not close a stream still owned by the caller.
An optional leading UTF-8 byte-order mark is consumed. 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 message |
|
storage |
storage for parsed MIME part content |
|
error |
return location for a GError, or |
GMimeMessage * g_mime_message_load_from_file (GMimeParserOptions *options,const char *filename,GError **error);
Loads a message from filename
using g_mime_message_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.
ssize_t g_mime_message_write_headers_to_stream (GMimeMessage *message,GMimeFormatOptions *options,GMimeStream *stream);
Writes the message headers, merged with the body's headers when present, and the blank line separating headers from content. A parsed message without a separator retains that state, as in full-message output.
Unlike g_mime_entity_get_headers(), this includes the header/body
separator when present. It does not read or serialize the body, invoke
its virtual writer, or apply body newline completion. The caller's
output stream remains open.
message |
||
options |
formatting options, or |
[nullable] |
stream |
the output stream |
GMimeInternetAddressList *
g_mime_message_get_sender (GMimeMessage *message);
Gets the persistent list of addresses from all Sender headers, preserving mailboxes and groups. Missing headers yield an empty list. Header edits invalidate the list until the next message getter; list and nested address edits rewrite the Sender header. Clearing the list removes all Sender headers.
This is the same list returned by g_mime_message_get_addresses() with
GMIME_ADDRESS_TYPE_SENDER. This intentionally differs from MimeKit's
single-mailbox Sender property to support group syntax.
GMimeInternetAddressList *
g_mime_message_get_from (GMimeMessage *message);
Gets the parsed list of addresses in the From header.
GMimeInternetAddressList *
g_mime_message_get_reply_to (GMimeMessage *message);
Gets the parsed list of addresses in the Reply-To header.
GMimeInternetAddressList *
g_mime_message_get_to (GMimeMessage *message);
Gets combined list of parsed addresses in the To header(s).
GMimeInternetAddressList *
g_mime_message_get_cc (GMimeMessage *message);
Gets combined list of parsed addresses in the Cc header(s).
GMimeInternetAddressList *
g_mime_message_get_bcc (GMimeMessage *message);
Gets combined list of parsed addresses in the Bcc header(s).
GMimeInternetAddressList *
g_mime_message_get_resent_from (GMimeMessage *message);
Gets the persistent, mutable list combining all Resent-From headers in header order. Raw-header edits clear this same list for lazy reloading by the next message getter, without rewriting the headers. List and nested address changes replace matching headers; emptying the list removes them all. A retained list is safe to use after the message is finalized and no longer updates the message.
GMimeInternetAddressList *
g_mime_message_get_resent_reply_to (GMimeMessage *message);
Gets the persistent, mutable list combining all Resent-Reply-To headers. Changes to the list update the header, removing it when empty.
GMimeInternetAddressList *
g_mime_message_get_resent_to (GMimeMessage *message);
Gets the persistent, mutable list combining all Resent-To headers. Changes to the list update the header, removing it when empty.
GMimeInternetAddressList *
g_mime_message_get_resent_cc (GMimeMessage *message);
Gets the persistent, mutable list combining all Resent-Cc headers. Changes to the list update the header, removing it when empty.
GMimeInternetAddressList *
g_mime_message_get_resent_bcc (GMimeMessage *message);
Gets the persistent, mutable list combining all Resent-Bcc headers. Changes to the list update the header, removing it when empty.
GMimeInternetAddressList *
g_mime_message_get_resent_sender (GMimeMessage *message);
Gets the persistent list of addresses from all Resent-Sender headers, preserving mailboxes and groups. Missing headers yield an empty list. Header edits invalidate the list until the next message getter; list and nested address edits rewrite the Resent-Sender header. Clearing the list removes all matching headers.
This is the same list returned by g_mime_message_get_addresses() with
GMIME_ADDRESS_TYPE_RESENT_SENDER. This intentionally differs from MimeKit's
single-mailbox ResentSender property to support group syntax.
gboolean g_mime_message_add_mailbox (GMimeMessage *message,GMimeAddressType type,const char *name,const char *addr,GError **error);
Add a mailbox of a chosen type to the MIME message.
Note: The name
(and addr
) strings should be in UTF-8.
GMimeInternetAddressList * g_mime_message_get_addresses (GMimeMessage *message,GMimeAddressType type);
Gets a list of addresses of the specified type
from the message
.
The list is allocated and parsed on first access. Changed or removed
headers clear it for reloading by the next message getter; the list object
remains the same. List edits update the headers without requiring a getter.
GMimeInternetAddressList *
g_mime_message_get_all_recipients (GMimeMessage *message);
Combines the ordinary To, Cc, and Bcc lists, preserving groups and
duplicates. This legacy accessor does not select resent recipients;
use g_mime_message_get_recipients() for MimeKit-style recipient selection.
a newly allocated GMimeInternetAddressList
containing all recipients of the message or NULL if no recipients
are set.
GMimeInternetAddressList * g_mime_message_get_recipients (GMimeMessage *message,gboolean only_unique);
Gets a mailbox-only snapshot in To, Cc, then Bcc order, flattening groups depth-first. If the Resent-Sender or Resent-From address list is nonempty, only Resent-To, Resent-Cc, and Resent-Bcc are used, even when they contain no mailboxes. Merely having resent recipient headers does not select them.
With only_unique
, local parts remain case-sensitive and domains are
IDN-encoded and converted to ASCII lowercase, as in address ordering.
Domainless addresses are compared as stored. Display names and source
routes do not affect deduplication. The first original mailbox instance
wins.
The result owns references to original mailboxes, not clones. Its membership is independent of the message, but edits to shared mailboxes are visible through the original address lists.
void g_mime_message_set_importance (GMimeMessage *message,GMimeMessageImportance importance);
Sets the Importance header to low, normal, or high. Assigning the current importance preserves a single raw header; duplicates are replaced. Invalid enum values are programming errors and leave the message unchanged.
GMimeMessageImportance
g_mime_message_get_importance (GMimeMessage *message);
the first Importance header's value, or
GMIME_MESSAGE_IMPORTANCE_NORMAL if absent or unrecognized.
void g_mime_message_set_priority (GMimeMessage *message,GMimeMessagePriority priority);
Sets the Priority header to non-urgent, normal, or urgent. Assigning the current priority preserves a single raw header; duplicates are replaced. Invalid enum values are programming errors and leave the message unchanged.
GMimeMessagePriority
g_mime_message_get_priority (GMimeMessage *message);
the first Priority header's value, or
GMIME_MESSAGE_PRIORITY_NORMAL if absent or unrecognized.
void g_mime_message_set_x_priority (GMimeMessage *message,GMimeXMessagePriority priority);
Sets the X-Priority header to its numeric value and descriptive label. Assigning the current priority preserves a single raw header; duplicates are replaced. Invalid enum values are programming errors and leave the message unchanged.
GMimeXMessagePriority
g_mime_message_get_x_priority (GMimeMessage *message);
Parses an unsigned decimal prefix from the first raw X-Priority header after ASCII folding whitespace. Values are clamped to 1 through 5; missing digits and Int32 overflow yield normal priority.
the numeric priority, or GMIME_X_MESSAGE_PRIORITY_NORMAL
if the header is absent or invalid.
void g_mime_message_set_subject (GMimeMessage *message,const char *subject,const char *charset);
Set the subject of a message
.
Note: The subject
string should be in UTF-8.
message |
||
subject |
Subject string |
|
charset |
The charset to use for encoding the subject or |
[nullable] |
const char *
g_mime_message_get_subject (GMimeMessage *message);
Gets the decoded value of the first Subject header. Decoding is deferred until the value is requested and cached by the header. Reading the subject does not change the stored raw header or notify header-list observers.
the subject of the message
in a form suitable for
display or NULL if no subject is set. If not NULL, the returned string
will be in UTF-8.
[nullable]
void g_mime_message_set_date (GMimeMessage *message,GDateTime *date);
Sets the Date header on a MIME Message. The message retains date
,
including its timezone and microseconds; the header represents whole
seconds. Assigning the same instant as an already loaded value preserves
the cached value and raw header unless duplicate Date headers need to be
replaced.
A NULL date is a programming error.
GDateTime *
g_mime_message_get_date (GMimeMessage *message);
Gets the lazily parsed date and time value. Raw header edits invalidate the cache; the next getter parses the first Date header without decoding encoded words or falling back to duplicates.
void g_mime_message_set_resent_date (GMimeMessage *message,GDateTime *date);
Sets the Resent-Date header independently of Date. The message retains
date
, including its timezone and microseconds; the header represents
whole seconds. Assigning the same instant as an already loaded value
preserves the cached value, raw header, and any duplicates. Changed values
update only the first Resent-Date header, preserving older resent blocks.
A NULL date is a programming error.
GDateTime *
g_mime_message_get_resent_date (GMimeMessage *message);
Gets the lazily parsed resent date and time. Raw header edits invalidate the cache; the next getter parses the first Resent-Date header without decoding encoded words or falling back to duplicates.
void g_mime_message_set_message_id (GMimeMessage *message,const char *message_id);
Sets the Message-Id after normalizing a complete message-id. Invalid values, including empty IDs, extra tokens, and non-folding line breaks, are programming errors and leave the message unchanged. Assigning the already loaded ID preserves a single raw header; duplicates are replaced.
const char *
g_mime_message_get_message_id (GMimeMessage *message);
Gets the Message-Id header of message
.
void g_mime_message_set_in_reply_to (GMimeMessage *message,const char *message_id);
Sets the In-Reply-To header after normalizing a complete message-id.
Invalid values are programming errors and leave the message unchanged.
Assigning the already loaded ID preserves a single raw header; duplicates are
replaced. A NULL value removes all In-Reply-To headers, including
malformed duplicates.
const char *
g_mime_message_get_in_reply_to (GMimeMessage *message);
Gets the first recovered message-id from the first In-Reply-To header, skipping malformed IDs and unrelated text without rewriting the header.
the message-id being replied to, or NULL if absent
or no valid ID could be recovered.
[nullable]
void g_mime_message_set_resent_message_id (GMimeMessage *message,const char *message_id);
Sets the Resent-Message-Id header after normalizing a complete message-id.
Invalid values, including NULL, are programming errors and leave the
message unchanged. Assigning the already loaded ID preserves the raw header.
Changed values update only the first Resent-Message-Id header, preserving
older resent blocks.
const char *
g_mime_message_get_resent_message_id (GMimeMessage *message);
Gets the parsed ID from the first Resent-Message-Id header.
GMimeMessageIdList *
g_mime_message_get_references (GMimeMessage *message);
Gets the persistent, mutable References list. Editing it updates the References header, removing all matching headers when the list becomes empty. Raw-header edits clear this same list; the next getter reloads it from the first matching header without rewriting it. Editing the cleared list instead replaces the header with those new contents. The caller may retain its own reference; the list stops updating the message after the message is finalized.
void g_mime_message_set_mime_part (GMimeMessage *message,GMimeEntity *mime_part);
Set the root-level MIME part of the message.
GMimeEntity *
g_mime_message_get_mime_part (GMimeMessage *message);
Gets the toplevel MIME part contained within message
.
GPtrArray *
g_mime_message_get_body_parts (GMimeMessage *message);
Gets all non-multipart body entities in depth-first order, including inline and attachment parts. Message parts are included as leaves; their embedded message bodies are not traversed.
Unlike MimeKit's lazy BodyParts enumeration, this returns a membership snapshot. The entities are retained original instances, not clones. Changes to their properties remain visible through the message, but changing the array does not change the MIME tree. Releasing the message or removing parts from its tree does not invalidate the snapshot.
a newly allocated
array owning its entity references, empty when there are no body parts.
Elements are borrowed from the array; retain them separately to outlive
it. Free the array with g_ptr_array_unref().
[transfer container][element-type GMimeEntity]
GPtrArray *
g_mime_message_get_attachments (GMimeMessage *message);
Gets the entities from g_mime_message_get_body_parts() whose
Content-Disposition is "attachment". Multipart containers themselves
are excluded even when marked as attachments, but their children are
visited. Inline entities with filenames are not attachments. Attached
messages are included without traversing their embedded bodies.
The result has the same depth-first ordering, snapshot membership, and
shared entity ownership as g_mime_message_get_body_parts(). Attachment
status is evaluated at the time of this call, not tracked by the array.
a newly allocated
array owning its entity references, empty when there are no attachments.
Elements are borrowed from the array; retain them separately to outlive
it. Free the array with g_ptr_array_unref().
[transfer container][element-type GMimeEntity]
gboolean g_mime_message_try_get_entity (GMimeMessage *message,const char *path_specifier,GMimeEntity **entity);
Looks up an entity directly, including inside attached messages. Multipart children are numbered from 1. A non-multipart message body is part 1; a multipart message body is part 0, and its children omit that 0. For example, "3.0" selects the multipart body of an attached message in part 3, while "3.1" selects its first child.
Components contain only ASCII decimal digits and must fit in a signed
32-bit integer. Leading zeros are accepted. A 0 component can only select
a multipart message body and must be the final component. Empty,
malformed, overflowing, or nonexistent paths return FALSE and clear
entity
. The returned entity is borrowed from the message tree.
Lookup is iterative and follows only the specified path, not siblings. Path specifiers use the same numbering as GMimeIterator.
message |
||
path_specifier |
a dot-separated MIME path |
|
entity |
the entity found, or |
[out][transfer none][nullable] |
void g_mime_message_foreach (GMimeMessage *message,GMimeEntityForeachFunc callback,gpointer user_data);
Recursively calls callback
on each of the mime parts in the mime message.
message |
||
callback |
function to call on each of the mime parts contained by the mime message. |
[scope call] |
user_data |
user-supplied callback data |
GMimeEntity *
g_mime_message_get_body (GMimeMessage *message);
Attempts to identify the MIME part containing the body of the message.
a GMimeEntity containing the textual
content that appears to be the main body of the message, or NULL if no
body part has been set.
Note: This function is NOT guaranteed to always work as it makes some assumptions that are not necessarily true. It is recommended that you traverse the MIME structure yourself.
char * g_mime_message_get_text_body (GMimeMessage *message,GError **error);
Gets the decoded plain-text body using
g_mime_message_get_text_body_with_format() with GMIME_TEXT_FORMAT_PLAIN.
Flowed text matches plain text, but its flow and space-stuffing are not
converted to fixed text.
char * g_mime_message_get_html_body (GMimeMessage *message,GError **error);
Gets the decoded HTML body using g_mime_message_get_text_body_with_format()
with GMIME_TEXT_FORMAT_HTML. No markup conversion or sanitization is done.
char * g_mime_message_get_text_body_with_format (GMimeMessage *message,GMimeTextFormat format,GError **error);
Selects and decodes a text body without modifying the MIME tree. Multipart
selection uses g_mime_multipart_try_get_value(), including alternative and
related overrides. A standalone text body must match format
and must not
be an attachment. Embedded messages are not searched. Unknown formats and
GMIME_TEXT_FORMAT_COMPRESSED_RICH_TEXT have no match.
Transfer encoding is decoded before charset conversion. A supported Content-Type charset takes precedence, followed by a UTF-8/UTF-16 BOM, an HTML meta charset in the first 1024 decoded bytes, then UTF-8. Declared charsets, meta charsets and UTF-16 BOMs use replacement decoding: malformed Unicode sequences become U+FFFD, other malformed input becomes '?'. HTML meta UTF-16 declarations are remapped to strict UTF-8. The default UTF-8 and UTF-8 BOM decoders are also strict and retry the whole body as ISO-8859-1 on malformed input, like MimeKit. Charset mappings follow native iconv rather than managed codepage best-fit tables. Incomplete final characters are also handled, unlike MimeKit versions whose charset filter omits decoder finalization at EOF. Newlines follow the default GMimeFormatOptions; bare CRs and Unicode BOMs are retained. No final newline is added. Flowed text is not unflowed, and formats are neither converted nor sanitized.
Missing bodies return NULL without an error. Selected text parts with
absent or empty content return an allocated empty string. Decoded NULs
report G_CONVERT_ERROR_EMBEDDED_NUL, other conversion failures report
G_CONVERT_ERROR, and content/stream failures report GMIME_ERROR. No error
returns partial text. Source-backed content must remain open and unchanged;
successful decoding rewinds its stream, but failures may leave it advanced.
GMimeAutocryptHeader * g_mime_message_get_autocrypt_header (GMimeMessage *message,GDateTime *now);
Creates a new GMimeAutocryptHeader based on the relevant Autocrypt header associated with the sender of an e-mail message.
If the message has no sender in the From: field, or has more than
one sender, then this function will return NULL. Autocrypt should
ignore the message entirely.
If there is one sender, but no single Autocrypt header is found that matches that e-mail address, a GMimeAutocryptHeader will be returned for the sender, but it will be incomplete (see g_mime_autocrypt_header_is_complete).
Note that the following types of Autocrypt headers will not be returned by this function:
headers that do not match an address in "From:"
unparseable headers
headers with unknown critical attributes
duplicate valid headers for the sender's address
The returned Autocrypt header will have its effective_date set to the earliest of either:
the Date: header of the message or
now
(or the current time, if now
is NULL)
a new GMimeAutocryptHeader object,
or NULL if the message should be ignored for purposes of
Autocrypt.
GMimeAutocryptHeaderList * g_mime_message_get_autocrypt_gossip_headers_from_inner_part (GMimeMessage *message,GDateTime *now,GMimeEntity *inner_part);
Extracts Autocrypt-Gossip headers matching an address in the outer message's To, Cc, or Reply-To fields.
You must pass the decrypted inner part of the message to this function, since Autocrypt-Gossip headers are only stored within the encrypted layer.
If you don't already have the decrypted inner part available to you, you probably want to use g_mime_message_get_autocrypt_gossip_headers instead.
Each header in the returned list will:
have a valid address
be of the type requested
be complete
If no Autocrypt header is found for a recipient, no GMimeAutocryptHeader will be in the list associated with that e-mail address.
Note that the following types of Autocrypt headers will not be returned by this function:
headers of an unrequested type
headers that do not match an address in To, Cc, or Reply-To
unparseable headers
headers with unknown critical attributes
duplicate valid headers for a given address
On error (e.g. if this version of GMime cannot handle the requested
Autocrypt type, or if a parameter is missing or malformed), returns
NULL
The returned Autocrypt headers will have their effective_date set to the earliest of either:
the Date: header of the message or
now
(or the current time, if now
is NULL)
message |
a GMimeMessage object. |
|
now |
a GDateTime object, or |
[nullable] |
inner_part |
a GMimeEntity which is the cleartext part of the inner message |
GMimeAutocryptHeaderList * g_mime_message_get_autocrypt_gossip_headers (GMimeMessage *message,GDateTime *now,gpgme_ctx_t ctx,GError **err);
Extracts Autocrypt-Gossip headers matching To, Cc, or Reply-To.
Returns the same object as
g_mime_message_get_autocrypt_gossip_headers_from_inner_part(), but
handles decryption and cleanup automatically.
Configure network and session-key policy on ctx
before calling.
If the message is not actually an encrypted message, returns NULL:
it should be ignored for purposes of evaluating gossip.
If decryption fails, returns NULL. In this case, an exception
will be set on err
to provide information about the decryption
failure.
[skip]
message |
a GMimeMessage object, which is expected to be encrypted. |
|
now |
a GDateTime object, or |
[nullable] |
ctx |
a borrowed GPGME OpenPGP context |
|
err |
a GError (can be |
An address type.
|
Represents the addresses in the Sender header. |
||
|
Represents the addresses in the From header. |
||
|
Represents the addresses in the Reply-To header. |
||
|
Represents the recipients in the To header. |
||
|
Represents the recipients in the Cc header. |
||
|
Represents the recipients in the Bcc header. |
||
|
Represents the authors in Resent-From headers. |
||
|
Represents the addresses in Resent-Reply-To headers. |
||
|
Represents the recipients in Resent-To headers. |
||
|
Represents the recipients in Resent-Cc headers. |
||
|
Represents the recipients in Resent-Bcc headers. |
||
|
Represents the addresses in Resent-Sender headers. |