| Top |
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.
GMimeAttachmentCollection *
g_mime_attachment_collection_new (gboolean linked_resources);
int
g_mime_attachment_collection_get_count
(GMimeAttachmentCollection *collection);
GMimeEntity * g_mime_attachment_collection_get_attachment (GMimeAttachmentCollection *collection,int index);
void g_mime_attachment_collection_set_attachment (GMimeAttachmentCollection *collection,int index,GMimeEntity *attachment);
Retains attachment
and releases the previous entry without changing headers.
collection |
||
index |
an existing attachment index |
|
attachment |
the replacement entity. |
[transfer none] |
void g_mime_attachment_collection_add (GMimeAttachmentCollection *collection,GMimeEntity *attachment);
Retains attachment
without changing its headers. Duplicate entries are allowed.
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.
collection |
||
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 |
|
content_type |
the content type, or |
[nullable] |
error |
return location for a GError, or |
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.
collection |
||
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 |
[nullable] |
error |
return location for a GError, or |
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.
void
g_mime_attachment_collection_clear (GMimeAttachmentCollection *collection);
Removes all entries, releasing each reference. Externally retained entities are not disposed and remain usable.
gboolean g_mime_attachment_collection_contains (GMimeAttachmentCollection *collection,GMimeEntity *attachment);
int g_mime_attachment_collection_index_of (GMimeAttachmentCollection *collection,GMimeEntity *attachment);
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.
collection |
||
index |
an existing attachment index |
|
attachment |
the entity to insert. |
[transfer none] |
gboolean g_mime_attachment_collection_remove (GMimeAttachmentCollection *collection,GMimeEntity *attachment);
Removes only the first identical instance, releasing its reference.
void g_mime_attachment_collection_remove_at (GMimeAttachmentCollection *collection,int index);
Removes the entry at index
, releasing its reference.