GMimeReceived

GMimeReceived — Received header values

Functions

Types and Values

Description

Parses Received header values following MimeKit's clause recovery rules. Clauses retain their order and keyword spelling; their parsed values are not subjected to the stricter public ReceivedClause constructor checks. Duplicate known clauses, incomplete comments and nonempty invalid dates fail with GMIME_ERROR_PARSE_ERROR.

Named setters update or remove the first matching clause. Adding a missing named clause sorts the entire collection by clause identifier; updating or removing an existing clause does not sort. Unlike MimeKit's unstable List.Sort(), equal identifiers retain their relative order, so adding a different clause cannot change which duplicate is first. Direct collection operations preserve order and permit duplicate and shared clause instances, but not NULL entries.

Functions

g_mime_received_new ()

GMimeReceived *
g_mime_received_new (void);

Creates an empty value with no clauses or date.

Returns

a new GMimeReceived.

[transfer full]


g_mime_received_new_with_hosts ()

GMimeReceived *
g_mime_received_new_with_hosts (const char *from,
                                GInetAddress *from_tcp_info,
                                const char *by,
                                GInetAddress *by_tcp_info,
                                GDateTime *date_time,
                                GError **error);

Creates validated From and By clauses with bracketed IP address comments. Host strings and address text are copied; the addresses are not retained. Invalid host values report GMIME_ERROR_PARSE_ERROR.

GInetAddress does not carry an IPv6 scope ID. Scoped address comments can instead be assigned with g_mime_received_set_from_tcp_info() and g_mime_received_set_by_tcp_info().

Parameters

from

the sending host's domain or address literal

 

from_tcp_info

the sending host's IP address

 

by

the receiving host's domain or address literal

 

by_tcp_info

the receiving host's IP address

 

date_time

the date and timezone offset to retain.

[transfer none]

error

return location for a GError.

[nullable]

Returns

a new value, or NULL on error.

[transfer full][nullable]


g_mime_received_parse ()

GMimeReceived *
g_mime_received_parse (GMimeParserOptions *options,
                       const char *text,
                       gssize length,
                       GError **error);

Parses a header value, not its field name. Empty input, missing clause values and missing dates are accepted. Parsed clauses bypass constructor validation, retain keyword spelling and collapse whitespace between value tokens to one space. Leading comments form a GMIME_RECEIVED_CLAUSE_NONE clause. Known keywords may occur only once; repeated extensions are allowed.

Raw text uses the parser's fallback charset, without RFC 2047 decoding. Embedded NUL characters are represented as U+FFFD in returned strings. Input is bounded by length and is not retained.

Parameters

options

a GMimeParserOptions or NULL for the defaults.

[nullable]

text

the raw Received header value.

[array length=length][element-type guint8]

length

the input byte length, or -1 for a NUL-terminated string

 

error

return location for a GError.

[nullable]

Returns

a parsed value, or NULL on error.

[transfer full][nullable]


g_mime_received_to_string ()

char *
g_mime_received_to_string (GMimeReceived *received,
                           GMimeFormatOptions *options);

Serializes the value without its field name, including leading whitespace and a terminating newline. Folding accounts for the "Received:" field name and counts UTF-16 units like MimeKit. Individual tokens are not split and may exceed the configured line-length target.

Comments are unfolded and backslashes escaped. Clauses retain their order, keyword spelling and values. Parsed dates retain their unfolded spelling until date assignment invalidates the cache. Otherwise dates use g_mime_utils_header_format_date(). No RFC 2047 or IDN encoding is applied.

Parameters

received

a GMimeReceived

 

options

a GMimeFormatOptions or NULL for the defaults.

[nullable]

Returns

the serialized value, or NULL if a date cannot be formatted because a required UTC conversion is out of range.

[transfer full][nullable]


g_mime_received_get_clause_count ()

int
g_mime_received_get_clause_count (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the number of clauses, including any leading-comment clause.


g_mime_received_get_clause ()

GMimeReceivedClause *
g_mime_received_get_clause (GMimeReceived *received,
                            int index);

Parameters

received

a GMimeReceived

 

index

a zero-based clause index

 

Returns

the clause owned by received .

[transfer none]


g_mime_received_set_clause ()

void
g_mime_received_set_clause (GMimeReceived *received,
                            int index,
                            GMimeReceivedClause *clause);

Retains clause and releases the old entry without validating or sorting. Replacing an entry with itself is safe. Duplicate instances are allowed.

Parameters

received

a GMimeReceived

 

index

an existing clause index

 

clause

the replacement clause.

[transfer none]

g_mime_received_add_clause ()

void
g_mime_received_add_clause (GMimeReceived *received,
                            GMimeReceivedClause *clause);

Retains clause without validating or sorting. Duplicate instances are allowed.

Parameters

received

a GMimeReceived

 

clause

the clause to append.

[transfer none]

g_mime_received_insert_clause ()

void
g_mime_received_insert_clause (GMimeReceived *received,
                               int index,
                               GMimeReceivedClause *clause);

Retains clause at index without validating or sorting.

Parameters

received

a GMimeReceived

 

index

an index from zero through the clause count

 

clause

the clause to insert.

[transfer none]

g_mime_received_index_of_clause ()

int
g_mime_received_index_of_clause (GMimeReceived *received,
                                 GMimeReceivedClause *clause);

Parameters

received

a GMimeReceived

 

clause

the clause instance to find

 

Returns

the first matching instance index, or -1 if absent.


g_mime_received_contains_clause ()

gboolean
g_mime_received_contains_clause (GMimeReceived *received,
                                 GMimeReceivedClause *clause);

Parameters

received

a GMimeReceived

 

clause

the clause instance to find

 

Returns

whether the exact clause instance belongs to received .


g_mime_received_remove_clause ()

gboolean
g_mime_received_remove_clause (GMimeReceived *received,
                               GMimeReceivedClause *clause);

Removes and releases only the first occurrence, preserving remaining order.

Parameters

received

a GMimeReceived

 

clause

the clause instance to remove.

[transfer none]

Returns

whether a clause was removed.


g_mime_received_remove_clause_at ()

void
g_mime_received_remove_clause_at (GMimeReceived *received,
                                  int index);

Removes and releases the indexed entry without reordering survivors.

Parameters

received

a GMimeReceived

 

index

an existing clause index

 

g_mime_received_clear_clauses ()

void
g_mime_received_clear_clauses (GMimeReceived *received);

Removes and releases every clause without changing the date.

Parameters

received

a GMimeReceived

 

g_mime_received_get_date_time ()

GDateTime *
g_mime_received_get_date_time (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the parsed date with its offset, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_date_time ()

void
g_mime_received_set_date_time (GMimeReceived *received,
                               GDateTime *date_time);

Retains date_time . Always clears the cached parsed date spelling, even when assigning the existing date. Does not change clauses.

Parameters

received

a GMimeReceived

 

date_time

the date and offset, or NULL to remove.

[nullable][transfer none]

g_mime_received_get_from ()

const char *
g_mime_received_get_from (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first From value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_from ()

gboolean
g_mime_received_set_from (GMimeReceived *received,
                          const char *value,
                          GError **error);

Updates the first From clause without changing its keyword or comments. A missing clause is created and the collection sorted by identifier. Invalid values report GMIME_ERROR_PARSE_ERROR without changing the model.

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 domain or address literal, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.


g_mime_received_get_from_tcp_info ()

const char *
g_mime_received_get_from_tcp_info (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first From comment, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_from_tcp_info ()

void
g_mime_received_set_from_tcp_info (GMimeReceived *received,
                                   const char *comment);

Replaces all comments of the first From clause with an unfolded copy. Tabs become spaces and CR/LF are removed; other whitespace is preserved. If absent and comment is non-NULL, creates an empty-valued From clause and sorts the collection by identifier. NULL does not create a clause.

Parameters

received

a GMimeReceived

 

comment

a UTF-8 comment, or NULL to clear comments.

[nullable]

g_mime_received_get_by ()

const char *
g_mime_received_get_by (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first By value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_by ()

gboolean
g_mime_received_set_by (GMimeReceived *received,
                        const char *value,
                        GError **error);

Updates or removes the first By clause, as g_mime_received_set_from() does for From. Failed validation leaves the model unchanged.

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 domain or address literal, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.


g_mime_received_get_by_tcp_info ()

const char *
g_mime_received_get_by_tcp_info (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first By comment, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_by_tcp_info ()

void
g_mime_received_set_by_tcp_info (GMimeReceived *received,
                                 const char *comment);

Replaces all comments of the first By clause, as g_mime_received_set_from_tcp_info() does for From.

Parameters

received

a GMimeReceived

 

comment

a UTF-8 comment, or NULL to clear comments.

[nullable]

g_mime_received_get_via ()

const char *
g_mime_received_get_via (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first Via value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_via ()

gboolean
g_mime_received_set_via (GMimeReceived *received,
                         const char *value,
                         GError **error);

Updates or removes the first Via clause. New clauses sort the collection by identifier. Values are not trimmed and must pass clause validation. Failed validation leaves the model unchanged.

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 value, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.


g_mime_received_get_with ()

const char *
g_mime_received_get_with (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first With value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_with ()

gboolean
g_mime_received_set_with (GMimeReceived *received,
                          const char *value,
                          GError **error);

Updates or removes the first With clause using the same ordering and validation rules as g_mime_received_set_via().

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 value, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.


g_mime_received_get_id ()

const char *
g_mime_received_get_id (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first Id value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_id ()

gboolean
g_mime_received_set_id (GMimeReceived *received,
                        const char *value,
                        GError **error);

Updates or removes the first Id clause. New clauses sort the collection. Uses complete lenient message-id validation without normalizing the value. Failed validation leaves the model unchanged.

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 message identifier, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.


g_mime_received_get_for ()

const char *
g_mime_received_get_for (GMimeReceived *received);

Parameters

received

a GMimeReceived

 

Returns

the first For value, or NULL if absent.

[transfer none][nullable]


g_mime_received_set_for ()

gboolean
g_mime_received_set_for (GMimeReceived *received,
                         const char *value,
                         GError **error);

Updates or removes the first For clause. New clauses sort the collection. Uses the existing mailbox parser without normalizing the stored value. Failed validation leaves the model unchanged.

Parameters

received

a GMimeReceived

 

value

a nonempty UTF-8 mailbox address, or NULL to remove.

[nullable]

error

return location for a GError.

[nullable]

Returns

TRUE on success, or FALSE on error.

Types and Values

GMimeReceived

typedef struct _GMimeReceived GMimeReceived;

A Received header value, containing ordered clauses and an optional date.