| Reference Manual of the tinymail framework | ||||
|---|---|---|---|---|
TnyMimePart;
TnyMimePartIface;
const gchar* tny_mime_part_get_content_type (TnyMimePart *self);
gboolean tny_mime_part_content_type_is (TnyMimePart *self,
const gchar *type);
TnyStream* tny_mime_part_get_stream (TnyMimePart *self);
void tny_mime_part_write_to_stream (TnyMimePart *self,
TnyStream *stream);
gint tny_mime_part_construct_from_stream (TnyMimePart *self,
TnyStream *stream,
const gchar *type);
const gchar* tny_mime_part_get_filename (TnyMimePart *self);
const gchar* tny_mime_part_get_content_id (TnyMimePart *self);
const gchar* tny_mime_part_get_description (TnyMimePart *self);
const gchar* tny_mime_part_get_content_location (TnyMimePart *self);
gboolean tny_mime_part_is_purged (TnyMimePart *self);
void tny_mime_part_set_content_location (TnyMimePart *self,
const gchar *content_location);
void tny_mime_part_set_description (TnyMimePart *self,
const gchar *description);
void tny_mime_part_set_content_id (TnyMimePart *self,
const gchar *content_id);
void tny_mime_part_set_filename (TnyMimePart *self,
const gchar *filename);
void tny_mime_part_set_content_type (TnyMimePart *self,
const gchar *contenttype);
void tny_mime_part_set_purged (TnyMimePart *self);
gboolean tny_mime_part_is_attachment (TnyMimePart *self);
void tny_mime_part_decode_to_stream (TnyMimePart *self,
TnyStream *stream);
void tny_mime_part_get_parts (TnyMimePart *self,
TnyList *list);
gint tny_mime_part_add_part (TnyMimePart *self,
TnyMimePart *part);
void tny_mime_part_del_part (TnyMimePart *self,
TnyMimePart *part);
void tny_mime_part_get_header_pairs (TnyMimePart *self,
TnyList *list);
void tny_mime_part_set_header_pair (TnyMimePart *self,
const gchar *name,
const gchar *value);
A mime part is a part of a message. Like the body, an attachment or the PGP key of a message.
typedef struct {
GTypeInterface parent;
const gchar* (*get_content_type_func) (TnyMimePart *self);
gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type);
TnyStream* (*get_stream_func) (TnyMimePart *self);
void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream);
void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream);
gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type);
const gchar* (*get_filename_func) (TnyMimePart *self);
const gchar* (*get_content_id_func) (TnyMimePart *self);
const gchar* (*get_description_func) (TnyMimePart *self);
const gchar* (*get_content_location_func) (TnyMimePart *self);
gboolean (*is_purged_func) (TnyMimePart *self);
void (*set_content_location_func) (TnyMimePart *self, const gchar *content_location);
void (*set_description_func) (TnyMimePart *self, const gchar *description);
void (*set_content_id_func) (TnyMimePart *self, const gchar *content_id);
void (*set_filename_func) (TnyMimePart *self, const gchar *filename);
void (*set_content_type_func) (TnyMimePart *self, const gchar *contenttype);
void (*set_purged_func) (TnyMimePart *self);
gboolean (*is_attachment_func) (TnyMimePart *self);
void (*get_parts_func) (TnyMimePart *self, TnyList *list);
void (*del_part_func) (TnyMimePart *self, TnyMimePart *part);
gint (*add_part_func) (TnyMimePart *self, TnyMimePart *part);
void (*get_header_pairs_func) (TnyMimePart *self, TnyList *list);
void (*set_header_pair_func) (TnyMimePart *self, const gchar *name, const gchar *value);
} TnyMimePartIface;
const gchar* tny_mime_part_get_content_type (TnyMimePart *self);
Get the mime part type in the format "type/subtype". You shouldn't free the returned value.
self : |
a TnyMimePart object |
| Returns : | content-type of a message part as a read-only string |
gboolean tny_mime_part_content_type_is (TnyMimePart *self, const gchar *type);
Efficiently checks whether self is of type type. You can use things
like "type/ *" for matching. Only '*' works and stands for 'any'. It's not
a regular expression nor is it like a regular expression.
Example:
TnyMsg *message = ...
TnyList *parts = tny_simple_list_new ();
tny_mime_part_get_parts (TNY_MIME_PART (message), parts);
iter = tny_list_create_iterator (parts);
while (!tny_iterator_is_done (iter))
{
TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter));
if (tny_mime_part_content_type_is (part, "text/ *"))
g_print ("Found an E-mail body\n");
if (tny_mime_part_content_type_is (part, "text/html"))
g_print ("Found an E-mail HTML body\n");
g_object_unref (G_OBJECT (part));
tny_iterator_next (iter);
}
g_object_unref (G_OBJECT (iter));
g_object_unref (G_OBJECT (parts));
self : |
a TnyMimePart object |
type : |
The content type in the string format type/subtype |
| Returns : | Whether or not the part is the content type |
TnyStream* tny_mime_part_get_stream (TnyMimePart *self);
Inefficiently get a stream for self. The entire data of the part will be
kept in memory until the stream is unreferenced.
self : |
a TnyMimePart object |
| Returns : | An in-memory stream |
void tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream);
Efficiently write the content of self to a stream. This will not read the
data of the part in a memory buffer. In stead it will read the part data while
already writing it to the stream efficiently.
You probably want to utilise the tny_mime_part_decode_to_stream method in stead of this one. This method will not attempt to decode the mime part. Mime parts are usually encoded in E-mails.
Example:
int fd = open ("/tmp/attachment.png.base64enc", O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
TnyMimePart *part = ...
if (fd != -1)
{
TnyFsStream *stream = tny_fs_stream_new (fd);
tny_mime_part_write_to_stream (part, TNY_STREAM (stream));
g_object_unref (G_OBJECT (stream));
}
self : |
a TnyMimePart object |
stream : |
a TnyMsgStream stream |
gint tny_mime_part_construct_from_stream (TnyMimePart *self, TnyStream *stream, const gchar *type);
Set the stream from which the mime part will read its content
Example:
int fd = open ("/tmp/attachment.png", ...);
TnyMimePart *part = ...
if (fd != -1)
{
TnyFsStream *stream = tny_fs_stream_new (fd);
tny_mime_part_construct_from_stream (part, TNY_STREAM (stream));
}
self : |
a TnyMimePart object |
stream : |
a TnyMsgStream stream |
type : |
the type like text/plain |
| Returns : | 0 on success or -1 on failure |
const gchar* tny_mime_part_get_filename (TnyMimePart *self);
Get the filename of self if it's an attachment or NULL otherwise. The
returned value should not be freed.
self : |
a TnyMimePart object |
| Returns : | the filename of a mime part as a read-only string |
const gchar* tny_mime_part_get_content_id (TnyMimePart *self);
Get the content-id of self. The returned value should not be freed.
self : |
a TnyMimePart object |
| Returns : | the content-id of a mime part as a read-only string |
const gchar* tny_mime_part_get_description (TnyMimePart *self);
Get the description of self. The returned value should not be freed.
self : |
a TnyMimePart object |
| Returns : | the description of a mime part as a read-only string |
const gchar* tny_mime_part_get_content_location (TnyMimePart *self);
Get the content location of self. The returned value should not be freed.
self : |
a TnyMimePart object |
| Returns : | the content-location of a mime part as a read-only string |
gboolean tny_mime_part_is_purged (TnyMimePart *self);
Get if this attachment has been purged from cache.
self : |
a TnyMimePart object |
| Returns : | a gboolean |
void tny_mime_part_set_content_location (TnyMimePart *self, const gchar *content_location);
Set the content location of self.
self : |
a TnyMimePart object |
content_location : |
the location |
void tny_mime_part_set_description (TnyMimePart *self, const gchar *description);
Set the description of self.
self : |
a TnyMimePart object |
description : |
the description |
void tny_mime_part_set_content_id (TnyMimePart *self, const gchar *content_id);
Set the content id of self.
self : |
a TnyMimePart object |
content_id : |
the content id |
void tny_mime_part_set_filename (TnyMimePart *self, const gchar *filename);
Set the filename of self.
self : |
a TnyMimePart object |
filename : |
the filename |
void tny_mime_part_set_content_type (TnyMimePart *self, const gchar *contenttype);
Set the content type of self. Formatted as "type/subtype"
self : |
a TnyMimePart object |
contenttype : |
the content_type |
void tny_mime_part_set_purged (TnyMimePart *self);
Set the message as purged in cache
self : |
a TnyMimePart object |
gboolean tny_mime_part_is_attachment (TnyMimePart *self);
Figures out whether or not a mime part is an attachment. An attachment is typically something with a original filename. Examples are attached files. Examples that will return FALSE are PGP signatures.
Example:
TnyMsg *message = ...
TnyList *parts = tny_simple_list_new ();
tny_mime_part_get_parts (TNY_MIME_PART (message), parts);
iter = tny_list_create_iterator (parts);
while (!tny_iterator_is_done (iter))
{
TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter));
if (tny_mime_part_is_attachment (part))
{
g_print ("Found an attachment (%s)\n",
tny_mime_part_get_filename (part));
}
g_object_unref (G_OBJECT (part));
tny_iterator_next (iter);
}
g_object_unref (G_OBJECT (iter));
g_object_unref (G_OBJECT (parts));
self : |
a TnyMimePart object |
| Returns : | whether or not the mime part is an attachment |
void tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream);
Efficiently decode self to a stream. This will not read the data of the
part in a memory buffer. In stead it will read the part data while already
writing it to the stream efficiently.
Example:
int fd = open ("/tmp/attachment.png", O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
TnyMimePart *part = ...
if (fd != -1)
{
TnyFsStream *stream = tny_fs_stream_new (fd);
tny_mime_part_decode_to_stream (part, TNY_STREAM (stream));
g_object_unref (G_OBJECT (stream));
}
self : |
a TnyMimePart object |
stream : |
a TnyMsgStream stream |
void tny_mime_part_get_parts (TnyMimePart *self, TnyList *list);
Get a read-only list of mime-parts in self.
Example:
TnyMsg *message = ...
TnyList *parts = tny_simple_list_new ();
tny_mime_part_get_parts (TNY_MIME_PART (message), parts);
iter = tny_list_create_iterator (parts);
while (!tny_iterator_is_done (iter))
{
TnyMimePart *part = TNY_MIME_PART (tny_iterator_get_current (iter));
g_object_unref (G_OBJECT (part));
tny_iterator_next (iter);
}
g_object_unref (G_OBJECT (iter));
g_object_unref (G_OBJECT (parts));
self : |
a TnyMimePart object |
list : |
a TnyList object |
gint tny_mime_part_add_part (TnyMimePart *self, TnyMimePart *part);
Add a mime-part to self.
self : |
a TnyMimePart object |
part : |
the mime-part to add |
| Returns : | The id of the added mime-part |
void tny_mime_part_del_part (TnyMimePart *self, TnyMimePart *part);
Delete a mime-part from self
self : |
a TnyMimePart object |
part : |
the mime-part to delete |
void tny_mime_part_get_header_pairs (TnyMimePart *self, TnyList *list);
Get a read-only list of header pairs (TnyPair) in self.
Example:
TnyMsg *message = ...
TnyList *pairs = tny_simple_list_new ();
tny_mime_part_get_header_pairs (TNY_MIME_PART (message), pairs);
iter = tny_list_create_iterator (pairs);
while (!tny_iterator_is_done (iter))
{
TnyPair *pair = TNY_PAIR (tny_iterator_get_current (iter));
g_print (%s: %s", tny_pair_get_name (pair),
tny_pair_get_value (pair));
g_object_unref (G_OBJECT (pair));
tny_iterator_next (iter);
}
g_object_unref (G_OBJECT (iter));
g_object_unref (G_OBJECT (pairs));
self : |
a TnyMimePart object |
list : |
a TnyList object |
void tny_mime_part_set_header_pair (TnyMimePart *self, const gchar *name, const gchar *value);
Set a header pair (name: value) or delete a header (use NULL as value).
Example:
TnyMsg *message = ...
tny_mime_part_set_header_pair (TNY_MIME_PART (message),
"X-MS-Has-Attach", "yes");
self : |
a TnyMimePart object |
name : |
the name of the header |
value : |
the value of the header or NULL to unset |