GMimeAttachmentCollection

GMimeAttachmentCollection — Constructing attachments and linked resources

Functions

Types and Values

Description

Ports MimeKit's AttachmentCollection. Collections retain entities by reference and allow duplicate entries. Adding an existing entity does not change its headers. The data, stream and file helpers construct and append an attachment only after loading succeeds, and return a separate owned reference.

Text attachments use GMimeFilterBest with the 7bit constraint. Other ordinary parts use base64. A message/rfc822 attachment is parsed into GMimeMessagePart. Linked collections give newly constructed attachments an inline disposition and a Content-Location containing the file name.

Clearing and removing entries releases references; retained entities remain usable. There is no force-dispose operation. The synchronous APIs do not yet implement MimeKit's cancellation or asynchronous overloads.

Functions

g_mime_attachment_collection_new ()

GMimeAttachmentCollection *
g_mime_attachment_collection_new (gboolean linked_resources);

Parameters

linked_resources

whether constructed attachments are linked resources

 

Returns

a new empty attachment collection.

[transfer full]


g_mime_attachment_collection_get_count ()

int
g_mime_attachment_collection_get_count
                               (GMimeAttachmentCollection *collection);

Parameters

collection

a GMimeAttachmentCollection

 

Returns

the number of attachments, including duplicate references.


g_mime_attachment_collection_get_attachment ()

GMimeEntity *
g_mime_attachment_collection_get_attachment
                               (GMimeAttachmentCollection *collection,
                                int index);

Parameters

collection

a GMimeAttachmentCollection

 

index

an existing attachment index

 

Returns

the attachment at index .

[transfer none]


g_mime_attachment_collection_set_attachment ()

void
g_mime_attachment_collection_set_attachment
                               (GMimeAttachmentCollection *collection,
                                int index,
                                GMimeEntity *attachment);

Retains attachment and releases the previous entry without changing headers.

Parameters

collection

a GMimeAttachmentCollection

 

index

an existing attachment index

 

attachment

the replacement entity.

[transfer none]

g_mime_attachment_collection_add ()

void
g_mime_attachment_collection_add (GMimeAttachmentCollection *collection,
                                  GMimeEntity *attachment);

Retains attachment without changing its headers. Duplicate entries are allowed.

Parameters

collection

a GMimeAttachmentCollection

 

attachment

the entity to append.

[transfer none]

g_mime_attachment_collection_add_data ()

GMimeEntity *
g_mime_attachment_collection_add_data (GMimeAttachmentCollection *collection,
                                       const char *file_name,
                                       const guint8 *data,
                                       gsize length,
                                       GMimeContentType *content_type,
                                       GError **error);

Copies data into owned storage, then constructs and appends an attachment. data may be NULL only when length is zero. Inputs larger than G_MAXUINT bytes fail with GMIME_ERROR and EOVERFLOW because native memory streams use GByteArray. A supplied content_type is retained by ordinary parts, not cloned; its name parameter is updated on success.

Automatically detected message/rfc822 data that fails to parse is attached as application/octet-stream. Explicit message/rfc822 parse errors propagate. Linked file names must be relative references satisfying native Content-Location validation; invalid references return GMIME_ERROR_PARSE_ERROR without adding an entry.

Parameters

collection

a GMimeAttachmentCollection

 

file_name

a nonempty UTF-8 file name or path

 

data

attachment data.

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

length

the number of bytes in data

 

content_type

the content type, or NULL to detect it by extension.

[nullable]

error

return location for a GError, or NULL

 

Returns

the added entity, or NULL on failure.

[nullable][transfer full]


g_mime_attachment_collection_add_stream ()

GMimeEntity *
g_mime_attachment_collection_add_stream
                               (GMimeAttachmentCollection *collection,
                                const char *file_name,
                                GMimeStream *stream,
                                GMimeContentType *content_type,
                                GError **error);

Constructs and appends an attachment with an independent copy of the remaining input. The caller's stream is consumed but not closed or reset. Parsed message content is also independent of stream . Failed additions leave the collection unchanged, but may consume input. Linked file names must be relative references satisfying native Content-Location validation.

Automatically detected message/rfc822 content falls back to a generic binary attachment only on a format error and only if stream can seek back to its original position. I/O failures and explicit message/rfc822 format errors propagate. Native parser recovery rules still apply. Ordinary part content is limited to G_MAXUINT bytes by GMimeStreamMem; exceeding this returns GMIME_ERROR with EOVERFLOW.

Parameters

collection

a GMimeAttachmentCollection

 

file_name

a nonempty UTF-8 file name or path

 

stream

the input stream, read from its current position

 

content_type

the content type, or NULL to detect it by extension.

[nullable]

error

return location for a GError, or NULL

 

Returns

the added entity, or NULL on failure.

[nullable][transfer full]


g_mime_attachment_collection_add_file ()

GMimeEntity *
g_mime_attachment_collection_add_file (GMimeAttachmentCollection *collection,
                                       const char *file_name,
                                       GMimeContentType *content_type,
                                       GError **error);

Opens file_name and constructs an attachment using g_mime_attachment_collection_add_stream(). The file is closed on both success and failure. File open and input I/O errors use GMIME_ERROR with errno codes. File paths must also be valid UTF-8 for the attachment's file name metadata.

Parameters

collection

a GMimeAttachmentCollection

 

file_name

a nonempty path to the attachment file.

[type filename]

content_type

the content type, or NULL to detect it by extension.

[nullable]

error

return location for a GError, or NULL

 

Returns

the added entity, or NULL on failure.

[nullable][transfer full]


g_mime_attachment_collection_clear ()

void
g_mime_attachment_collection_clear (GMimeAttachmentCollection *collection);

Removes all entries, releasing each reference. Externally retained entities are not disposed and remain usable.

Parameters

collection

a GMimeAttachmentCollection

 

g_mime_attachment_collection_contains ()

gboolean
g_mime_attachment_collection_contains (GMimeAttachmentCollection *collection,
                                       GMimeEntity *attachment);

Parameters

collection

a GMimeAttachmentCollection

 

attachment

the entity to find

 

Returns

whether the exact attachment instance belongs to the collection.


g_mime_attachment_collection_index_of ()

int
g_mime_attachment_collection_index_of (GMimeAttachmentCollection *collection,
                                       GMimeEntity *attachment);

Parameters

collection

a GMimeAttachmentCollection

 

attachment

the entity to find

 

Returns

the index of the first identical instance, or -1 if absent.


g_mime_attachment_collection_insert ()

void
g_mime_attachment_collection_insert (GMimeAttachmentCollection *collection,
                                     int index,
                                     GMimeEntity *attachment);

Retains attachment and inserts it before index without changing its headers. Matching MimeKit, index must be less than the count; use add() to append.

Parameters

collection

a GMimeAttachmentCollection

 

index

an existing attachment index

 

attachment

the entity to insert.

[transfer none]

g_mime_attachment_collection_remove ()

gboolean
g_mime_attachment_collection_remove (GMimeAttachmentCollection *collection,
                                     GMimeEntity *attachment);

Removes only the first identical instance, releasing its reference.

Parameters

collection

a GMimeAttachmentCollection

 

attachment

the entity to remove

 

Returns

whether an entry was removed.


g_mime_attachment_collection_remove_at ()

void
g_mime_attachment_collection_remove_at
                               (GMimeAttachmentCollection *collection,
                                int index);

Removes the entry at index , releasing its reference.

Parameters

collection

a GMimeAttachmentCollection

 

index

an existing attachment index

 

Types and Values

GMimeAttachmentCollection

typedef struct _GMimeAttachmentCollection GMimeAttachmentCollection;

An ordered, mutable collection for constructing attachments or linked resources.

See Also

GMimePart, GMimeMessagePart