gmime r1334 - in trunk: . docs/reference examples gmime mono tests
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1334 - in trunk: . docs/reference examples gmime mono tests
- Date: Thu, 5 Jun 2008 14:17:58 +0000 (UTC)
Author: fejj
Date: Thu Jun 5 14:17:57 2008
New Revision: 1334
URL: http://svn.gnome.org/viewvc/gmime?rev=1334&view=rev
Log:
2008-06-05 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-object.c: Get rid of the 'init' class method,
GObject already has an initializer (must be a leftover from before
the port to GObject).
(g_mime_object_new_type): Don't call GMimeObject->init(),
g_object_new() has already initialized the object.
* gmime/gmime-multipart.c: Moved all fields into a private struct.
(g_mime_multipart_remove_part): Now returns TRUE or FALSE.
Modified:
trunk/ChangeLog
trunk/docs/reference/gmime.hierarchy
trunk/examples/imap-example.c
trunk/gmime/gmime-message-part.c
trunk/gmime/gmime-message-partial.c
trunk/gmime/gmime-message.c
trunk/gmime/gmime-multipart-encrypted.c
trunk/gmime/gmime-multipart-signed.c
trunk/gmime/gmime-multipart.c
trunk/gmime/gmime-multipart.h
trunk/gmime/gmime-object.c
trunk/gmime/gmime-object.h
trunk/gmime/gmime-part.c
trunk/mono/gmime-api.raw
trunk/tests/test-mbox.c
trunk/tests/test-parser.c
trunk/tests/test-partial.c
Modified: trunk/docs/reference/gmime.hierarchy
==============================================================================
--- trunk/docs/reference/gmime.hierarchy (original)
+++ trunk/docs/reference/gmime.hierarchy Thu Jun 5 14:17:57 2008
@@ -36,3 +36,4 @@
GMimeStreamMmap
GMimeStreamNull
GInterface
+ GTypePlugin
Modified: trunk/examples/imap-example.c
==============================================================================
--- trunk/examples/imap-example.c (original)
+++ trunk/examples/imap-example.c Thu Jun 5 14:17:57 2008
@@ -80,7 +80,6 @@
write_part_bodystructure (GMimeObject *part, FILE *fp)
{
GMimeParam *param;
- GList *l;
fputc ('(', fp);
@@ -104,10 +103,15 @@
}
if (GMIME_IS_MULTIPART (part)) {
- l = GMIME_MULTIPART (part)->subparts;
- while (l != NULL) {
- write_part_bodystructure (l->data, fp);
- l = l->next;
+ GMimeMultipart *multipart = (GMimeMultipart *) part;
+ GMimeObject *subpart;
+ int i, n;
+
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
+ write_part_bodystructure (subpart, fp);
+ g_object_unref (subpart);
}
} else if (GMIME_IS_MESSAGE_PART (part)) {
GMimeMessage *message;
@@ -272,10 +276,12 @@
write_part (GMimeObject *part, const char *uid, const char *spec)
{
GMimeStream *istream, *ostream;
+ GMimeMultipart *multipart;
+ GMimeMessage *message;
+ GMimeObject *subpart;
char *buf, *id;
- GList *l;
FILE *fp;
- int i;
+ int i, n;
buf = g_strdup_printf ("%s/%s.HEADER", uid, spec);
fp = fopen (buf, "wt");
@@ -288,20 +294,19 @@
fclose (fp);
if (GMIME_IS_MULTIPART (part)) {
+ multipart = (GMimeMultipart *) part;
buf = g_alloca (strlen (spec) + 14);
id = g_stpcpy (buf, spec);
*id++ = '.';
- i = 1;
- l = GMIME_MULTIPART (part)->subparts;
- while (l != NULL) {
- sprintf (id, "%d", i);
- write_part (l->data, uid, buf);
- l = l->next;
- i++;
+
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
+ sprintf (id, "%d", i + 1);
+ write_part (subpart, uid, buf);
+ g_object_unref (subpart);
}
} else if (GMIME_IS_MESSAGE_PART (part)) {
- GMimeMessage *message;
-
buf = g_strdup_printf ("%s/%s.TEXT", uid, spec);
fp = fopen (buf, "wt");
g_free (buf);
Modified: trunk/gmime/gmime-message-part.c
==============================================================================
--- trunk/gmime/gmime-message-part.c (original)
+++ trunk/gmime/gmime-message-part.c Thu Jun 5 14:17:57 2008
@@ -47,7 +47,6 @@
static void g_mime_message_part_finalize (GObject *object);
/* GMimeObject class methods */
-static void message_part_init (GMimeObject *object);
static void message_part_prepend_header (GMimeObject *object, const char *header, const char *value);
static void message_part_append_header (GMimeObject *object, const char *header, const char *value);
static void message_part_set_header (GMimeObject *object, const char *header, const char *value);
@@ -96,7 +95,6 @@
gobject_class->finalize = g_mime_message_part_finalize;
- object_class->init = message_part_init;
object_class->prepend_header = message_part_prepend_header;
object_class->append_header = message_part_append_header;
object_class->remove_header = message_part_remove_header;
@@ -124,14 +122,6 @@
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-static void
-message_part_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
static void
message_part_prepend_header (GMimeObject *object, const char *header, const char *value)
{
Modified: trunk/gmime/gmime-message-partial.c
==============================================================================
--- trunk/gmime/gmime-message-partial.c (original)
+++ trunk/gmime/gmime-message-partial.c Thu Jun 5 14:17:57 2008
@@ -48,7 +48,6 @@
static void g_mime_message_partial_finalize (GObject *object);
/* GMimeObject class methods */
-static void message_partial_init (GMimeObject *object);
static void message_partial_prepend_header (GMimeObject *object, const char *header, const char *value);
static void message_partial_append_header (GMimeObject *object, const char *header, const char *value);
static void message_partial_set_header (GMimeObject *object, const char *header, const char *value);
@@ -95,7 +94,6 @@
gobject_class->finalize = g_mime_message_partial_finalize;
- object_class->init = message_partial_init;
object_class->prepend_header = message_partial_prepend_header;
object_class->append_header = message_partial_append_header;
object_class->remove_header = message_partial_remove_header;
@@ -123,13 +121,6 @@
}
static void
-message_partial_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
-static void
message_partial_prepend_header (GMimeObject *object, const char *header, const char *value)
{
/* RFC 1864 states that you cannot set a Content-MD5 on a message part */
Modified: trunk/gmime/gmime-message.c
==============================================================================
--- trunk/gmime/gmime-message.c (original)
+++ trunk/gmime/gmime-message.c Thu Jun 5 14:17:57 2008
@@ -50,7 +50,6 @@
static void g_mime_message_finalize (GObject *object);
/* GMimeObject class methods */
-static void message_init (GMimeObject *object);
static void message_prepend_header (GMimeObject *object, const char *header, const char *value);
static void message_append_header (GMimeObject *object, const char *header, const char *value);
static void message_set_header (GMimeObject *object, const char *header, const char *value);
@@ -119,7 +118,6 @@
gobject_class->finalize = g_mime_message_finalize;
- object_class->init = message_init;
object_class->prepend_header = message_prepend_header;
object_class->append_header = message_append_header;
object_class->remove_header = message_remove_header;
@@ -195,15 +193,7 @@
}
-static void
-message_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
-
-typedef void (*token_skip_t) (const char **in);
+typedef void (* token_skip_t) (const char **in);
struct _received_token {
char *token;
Modified: trunk/gmime/gmime-multipart-encrypted.c
==============================================================================
--- trunk/gmime/gmime-multipart-encrypted.c (original)
+++ trunk/gmime/gmime-multipart-encrypted.c Thu Jun 5 14:17:57 2008
@@ -58,7 +58,6 @@
static void g_mime_multipart_encrypted_finalize (GObject *object);
/* GMimeObject class methods */
-static void multipart_encrypted_init (GMimeObject *object);
static void multipart_encrypted_prepend_header (GMimeObject *object, const char *header, const char *value);
static void multipart_encrypted_append_header (GMimeObject *object, const char *header, const char *value);
static void multipart_encrypted_set_header (GMimeObject *object, const char *header, const char *value);
@@ -107,7 +106,6 @@
gobject_class->finalize = g_mime_multipart_encrypted_finalize;
- object_class->init = multipart_encrypted_init;
object_class->prepend_header = multipart_encrypted_prepend_header;
object_class->append_header = multipart_encrypted_append_header;
object_class->remove_header = multipart_encrypted_remove_header;
@@ -142,14 +140,6 @@
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-static void
-multipart_encrypted_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
static void
multipart_encrypted_prepend_header (GMimeObject *object, const char *header, const char *value)
{
Modified: trunk/gmime/gmime-multipart-signed.c
==============================================================================
--- trunk/gmime/gmime-multipart-signed.c (original)
+++ trunk/gmime/gmime-multipart-signed.c Thu Jun 5 14:17:57 2008
@@ -58,7 +58,6 @@
static void g_mime_multipart_signed_finalize (GObject *object);
/* GMimeObject class methods */
-static void multipart_signed_init (GMimeObject *object);
static void multipart_signed_prepend_header (GMimeObject *object, const char *header, const char *value);
static void multipart_signed_append_header (GMimeObject *object, const char *header, const char *value);
static void multipart_signed_set_header (GMimeObject *object, const char *header, const char *value);
@@ -107,7 +106,6 @@
gobject_class->finalize = g_mime_multipart_signed_finalize;
- object_class->init = multipart_signed_init;
object_class->prepend_header = multipart_signed_prepend_header;
object_class->append_header = multipart_signed_append_header;
object_class->remove_header = multipart_signed_remove_header;
@@ -136,14 +134,6 @@
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-static void
-multipart_signed_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
static void
multipart_signed_prepend_header (GMimeObject *object, const char *header, const char *value)
{
@@ -238,21 +228,24 @@
sign_prepare (GMimeObject *mime_part)
{
GMimeContentEncoding encoding;
+ GMimeMultipart *multipart;
GMimeObject *subpart;
+ int i, n;
if (GMIME_IS_MULTIPART (mime_part)) {
- GList *lpart;
+ multipart = (GMimeMultipart *) mime_part;
- if (GMIME_IS_MULTIPART_SIGNED (mime_part) || GMIME_IS_MULTIPART_ENCRYPTED (mime_part)) {
+ if (GMIME_IS_MULTIPART_SIGNED (multipart) ||
+ GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
/* must not modify these parts as they must be treated as opaque */
return;
}
- lpart = GMIME_MULTIPART (mime_part)->subparts;
- while (lpart) {
- subpart = GMIME_OBJECT (lpart->data);
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
sign_prepare (subpart);
- lpart = lpart->next;
+ g_object_unref (subpart);
}
} else if (GMIME_IS_MESSAGE_PART (mime_part)) {
subpart = GMIME_MESSAGE_PART (mime_part)->message->mime_part;
Modified: trunk/gmime/gmime-multipart.c
==============================================================================
--- trunk/gmime/gmime-multipart.c (original)
+++ trunk/gmime/gmime-multipart.c Thu Jun 5 14:17:57 2008
@@ -47,13 +47,20 @@
**/
+struct _GMimeMultipartPrivate {
+ GPtrArray *children;
+ char *boundary;
+ char *preface;
+ char *postface;
+};
+
+
/* GObject class methods */
static void g_mime_multipart_class_init (GMimeMultipartClass *klass);
static void g_mime_multipart_init (GMimeMultipart *multipart, GMimeMultipartClass *klass);
static void g_mime_multipart_finalize (GObject *object);
/* GMimeObject class methods */
-static void multipart_init (GMimeObject *object);
static void multipart_prepend_header (GMimeObject *object, const char *header, const char *value);
static void multipart_append_header (GMimeObject *object, const char *header, const char *value);
static void multipart_set_header (GMimeObject *object, const char *header, const char *value);
@@ -66,7 +73,7 @@
/* GMimeMultipart class methods */
static void multipart_add_part (GMimeMultipart *multipart, GMimeObject *part);
static void multipart_add_part_at (GMimeMultipart *multipart, GMimeObject *part, int index);
-static void multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part);
+static gboolean multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part);
static GMimeObject *multipart_remove_part_at (GMimeMultipart *multipart, int index);
static GMimeObject *multipart_get_part (GMimeMultipart *multipart, int index);
static int multipart_get_number (GMimeMultipart *multipart);
@@ -112,7 +119,6 @@
gobject_class->finalize = g_mime_multipart_finalize;
- object_class->init = multipart_init;
object_class->prepend_header = multipart_prepend_header;
object_class->append_header = multipart_append_header;
object_class->remove_header = multipart_remove_header;
@@ -135,43 +141,33 @@
static void
g_mime_multipart_init (GMimeMultipart *multipart, GMimeMultipartClass *klass)
{
- multipart->boundary = NULL;
- multipart->preface = NULL;
- multipart->postface = NULL;
- multipart->subparts = NULL;
+ multipart->priv = g_new (struct _GMimeMultipartPrivate, 1);
+ multipart->priv->children = g_ptr_array_new ();
+ multipart->priv->boundary = NULL;
+ multipart->priv->preface = NULL;
+ multipart->priv->postface = NULL;
}
static void
g_mime_multipart_finalize (GObject *object)
{
GMimeMultipart *multipart = (GMimeMultipart *) object;
- GList *node;
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
+ guint i;
- g_free (multipart->boundary);
- g_free (multipart->preface);
- g_free (multipart->postface);
+ g_free (priv->boundary);
+ g_free (priv->preface);
+ g_free (priv->postface);
- node = multipart->subparts;
- while (node) {
- GMimeObject *part;
-
- part = node->data;
- g_object_unref (part);
- node = node->next;
- }
- g_list_free (multipart->subparts);
+ for (i = 0; i < priv->children->len; i++)
+ g_object_unref (priv->children->pdata[i]);
+
+ g_ptr_array_free (priv->children, TRUE);
+ g_free (priv);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-static void
-multipart_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
static void
multipart_prepend_header (GMimeObject *object, const char *header, const char *value)
{
@@ -232,8 +228,8 @@
const char *boundary;
boundary = g_mime_content_type_get_parameter (content_type, "boundary");
- g_free (multipart->boundary);
- multipart->boundary = g_strdup (boundary);
+ g_free (multipart->priv->boundary);
+ multipart->priv->boundary = g_strdup (boundary);
GMIME_OBJECT_CLASS (parent_class)->set_content_type (object, content_type);
}
@@ -248,15 +244,16 @@
multipart_write_to_stream (GMimeObject *object, GMimeStream *stream)
{
GMimeMultipart *multipart = (GMimeMultipart *) object;
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
ssize_t nwritten, total = 0;
GMimeObject *part;
- GList *node;
+ guint i;
/* make sure a boundary is set unless we are writing out a raw
* header (in which case it should already be set... or if
* not, then it's a broken multipart and so we don't want to
* alter it or we'll completely break the output) */
- if (!multipart->boundary && !g_mime_header_list_has_raw (object->headers))
+ if (!priv->boundary && !g_mime_header_list_has_raw (object->headers))
g_mime_multipart_set_boundary (multipart, NULL);
/* write the content headers */
@@ -266,25 +263,24 @@
total += nwritten;
/* write the preface */
- if (multipart->preface) {
+ if (priv->preface) {
/* terminate the headers */
if (g_mime_stream_write (stream, "\n", 1) == -1)
return -1;
total++;
- if ((nwritten = g_mime_stream_write_string (stream, multipart->preface)) == -1)
+ if ((nwritten = g_mime_stream_write_string (stream, priv->preface)) == -1)
return -1;
total += nwritten;
}
- node = multipart->subparts;
- while (node) {
- part = node->data;
+ for (i = 0; i < priv->children->len; i++) {
+ part = priv->children->pdata[i];
/* write the boundary */
- if ((nwritten = g_mime_stream_printf (stream, "\n--%s\n", multipart->boundary)) == -1)
+ if ((nwritten = g_mime_stream_printf (stream, "\n--%s\n", priv->boundary)) == -1)
return -1;
total += nwritten;
@@ -294,26 +290,24 @@
return -1;
total += nwritten;
-
- node = node->next;
}
/* write the end-boundary (but only if a boundary is set) */
- if (multipart->boundary) {
- if ((nwritten = g_mime_stream_printf (stream, "\n--%s--\n", multipart->boundary)) == -1)
+ if (priv->boundary) {
+ if ((nwritten = g_mime_stream_printf (stream, "\n--%s--\n", priv->boundary)) == -1)
return -1;
total += nwritten;
}
/* write the postface */
- if (multipart->postface) {
- if ((nwritten = g_mime_stream_write_string (stream, multipart->postface)) == -1)
+ if (priv->postface) {
+ if ((nwritten = g_mime_stream_write_string (stream, priv->postface)) == -1)
return -1;
total += nwritten;
}
-
+
return total;
}
@@ -379,8 +373,8 @@
{
g_return_if_fail (GMIME_IS_MULTIPART (multipart));
- g_free (multipart->preface);
- multipart->preface = g_strdup (preface);
+ g_free (multipart->priv->preface);
+ multipart->priv->preface = g_strdup (preface);
}
@@ -397,7 +391,7 @@
{
g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), NULL);
- return multipart->preface;
+ return multipart->priv->preface;
}
@@ -413,8 +407,8 @@
{
g_return_if_fail (GMIME_IS_MULTIPART (multipart));
- g_free (multipart->postface);
- multipart->postface = g_strdup (postface);
+ g_free (multipart->priv->postface);
+ multipart->priv->postface = g_strdup (postface);
}
@@ -431,15 +425,18 @@
{
g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), NULL);
- return multipart->postface;
+ return multipart->priv->postface;
}
static void
multipart_add_part (GMimeMultipart *multipart, GMimeObject *part)
{
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
+
g_object_ref (part);
- multipart->subparts = g_list_append (multipart->subparts, part);
+
+ g_ptr_array_add (priv->children, part);
}
@@ -461,10 +458,33 @@
static void
+ptr_array_insert (GPtrArray *array, guint index, gpointer object)
+{
+ unsigned char *dest, *src;
+ guint n;
+
+ g_ptr_array_set_size (array, array->len + 1);
+
+ if (index == array->len) {
+ /* need to move items down */
+ dest = ((unsigned char *) array->pdata) + (sizeof (void *) * (index + 1));
+ src = ((unsigned char *) array->pdata) + (sizeof (void *) * index);
+ n = array->len - index - 1;
+
+ g_memmove (dest, src, (sizeof (void *) * n));
+ }
+
+ array->pdata[index] = object;
+}
+
+static void
multipart_add_part_at (GMimeMultipart *multipart, GMimeObject *part, int index)
{
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
+
g_object_ref (part);
- multipart->subparts = g_list_insert (multipart->subparts, part, index);
+
+ ptr_array_insert (priv->children, index, part);
}
@@ -487,39 +507,17 @@
}
-static void
+static gboolean
multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part)
{
- GList *node;
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
- /* *sigh* fucking glist... */
-
- node = multipart->subparts;
- while (node) {
- if (node->data == (gpointer) part)
- break;
- node = node->next;
- }
-
- if (node == NULL) {
- d(g_warning ("multipart_remove_part: %p does not seem to be a subpart of %p",
- part, multipart));
- return;
- }
-
- if (node == multipart->subparts) {
- if (node->next)
- node->next->prev = NULL;
- multipart->subparts = node->next;
- } else {
- if (node->next)
- node->next->prev = node->prev;
- node->prev->next = node->next;
- }
-
- g_list_free_1 (node);
+ if (!g_ptr_array_remove (priv->children, part))
+ return FALSE;
g_object_unref (part);
+
+ return TRUE;
}
@@ -529,41 +527,31 @@
* @part: mime part
*
* Removes the specified mime part from the multipart.
+ *
+ * Returns: %TRUE if the part was removed or %FALSE otherwise.
**/
-void
+gboolean
g_mime_multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part)
{
g_return_if_fail (GMIME_IS_MULTIPART (multipart));
g_return_if_fail (GMIME_IS_OBJECT (part));
- GMIME_MULTIPART_GET_CLASS (multipart)->remove_part (multipart, part);
+ return GMIME_MULTIPART_GET_CLASS (multipart)->remove_part (multipart, part);
}
static GMimeObject *
multipart_remove_part_at (GMimeMultipart *multipart, int index)
{
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
GMimeObject *part;
- GList *node;
- if (!(node = g_list_nth (multipart->subparts, index))) {
- d(g_warning ("multipart_remove_part_at: no part at index %d within %p", index, multipart));
+ if (index >= priv->children->len)
return NULL;
- }
- part = node->data;
+ part = priv->children->pdata[index];
- if (node == multipart->subparts) {
- if (node->next)
- node->next->prev = NULL;
- multipart->subparts = node->next;
- } else {
- if (node->next)
- node->next->prev = node->prev;
- node->prev->next = node->next;
- }
-
- g_list_free_1 (node);
+ g_ptr_array_remove_index (priv->children, index);
return part;
}
@@ -591,16 +579,13 @@
static GMimeObject *
multipart_get_part (GMimeMultipart *multipart, int index)
{
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
GMimeObject *part;
- GList *node;
- if (!(node = g_list_nth (multipart->subparts, index))) {
- d(g_warning ("multipart_get_part: no part at index %d within %p", index, multipart));
+ if (index >= priv->children->len)
return NULL;
- }
-
- part = node->data;
+ part = priv->children->pdata[index];
g_object_ref (part);
return part;
@@ -629,10 +614,7 @@
static int
multipart_get_number (GMimeMultipart *multipart)
{
- if (!multipart->subparts)
- return 0;
-
- return g_list_length (multipart->subparts);
+ return multipart->priv->children->len;
}
@@ -682,6 +664,7 @@
static void
multipart_set_boundary (GMimeMultipart *multipart, const char *boundary)
{
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
char bbuf[35];
if (!boundary) {
@@ -700,8 +683,8 @@
boundary = bbuf;
}
- g_free (multipart->boundary);
- multipart->boundary = g_strdup (boundary);
+ g_free (priv->boundary);
+ priv->boundary = g_strdup (boundary);
g_mime_object_set_content_type_parameter (GMIME_OBJECT (multipart), "boundary", boundary);
}
@@ -727,10 +710,12 @@
static const char *
multipart_get_boundary (GMimeMultipart *multipart)
{
- if (!multipart->boundary)
+ struct _GMimeMultipartPrivate *priv = multipart->priv;
+
+ if (!priv->boundary)
multipart_set_boundary (multipart, NULL);
- return multipart->boundary;
+ return priv->boundary;
}
@@ -764,18 +749,17 @@
void
g_mime_multipart_foreach (GMimeMultipart *multipart, GMimePartFunc callback, gpointer user_data)
{
- GList *subpart;
+ struct _GMimeMultipartPrivate *priv;
+ GMimeObject *part;
+ guint i;
g_return_if_fail (GMIME_IS_MULTIPART (multipart));
g_return_if_fail (callback != NULL);
- subpart = multipart->subparts;
- while (subpart) {
- GMimeObject *part = subpart->data;
-
+ priv = multipart->priv;
+ for (i = 0; i < priv->children->len; i++) {
+ part = priv->children->pdata[i];
callback (part, user_data);
-
- subpart = subpart->next;
}
}
@@ -795,34 +779,32 @@
g_mime_multipart_get_subpart_from_content_id (GMimeMultipart *multipart, const char *content_id)
{
GMimeObject *object = (GMimeObject *) multipart;
- GList *subparts;
+ struct _GMimeMultipartPrivate *priv;
+ GMimeObject *subpart, *part;
+ GMimeMultipart *mpart;
+ guint i;
g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), NULL);
g_return_val_if_fail (content_id != NULL, NULL);
+ priv = multipart->priv;
+
if (object->content_id && !strcmp (object->content_id, content_id)) {
g_object_ref (object);
return object;
}
- subparts = multipart->subparts;
- while (subparts) {
- GMimeObject *part = NULL;
- GMimeObject *subpart;
-
- subpart = subparts->data;
+ for (i = 0; i < priv->children->len; i++) {
+ subpart = priv->children->pdata[i];
if (GMIME_IS_MULTIPART (subpart)) {
- part = g_mime_multipart_get_subpart_from_content_id (GMIME_MULTIPART (subpart), content_id);
+ mpart = (GMimeMultipart *) subpart;
+ if ((part = g_mime_multipart_get_subpart_from_content_id (mpart, content_id)))
+ return part;
} else if (subpart->content_id && !strcmp (subpart->content_id, content_id)) {
g_object_ref (subpart);
- part = subpart;
+ return subpart;
}
-
- if (part)
- return part;
-
- subparts = subparts->next;
}
return NULL;
Modified: trunk/gmime/gmime-multipart.h
==============================================================================
--- trunk/gmime/gmime-multipart.h (original)
+++ trunk/gmime/gmime-multipart.h Thu Jun 5 14:17:57 2008
@@ -41,12 +41,7 @@
struct _GMimeMultipart {
GMimeObject parent_object;
- char *boundary;
-
- char *preface;
- char *postface;
-
- GList *subparts;
+ struct _GMimeMultipartPrivate *priv;
};
struct _GMimeMultipartClass {
@@ -54,7 +49,7 @@
void (* add_part) (GMimeMultipart *multipart, GMimeObject *part);
void (* add_part_at) (GMimeMultipart *multipart, GMimeObject *part, int index);
- void (* remove_part) (GMimeMultipart *multipart, GMimeObject *part);
+ gboolean (* remove_part) (GMimeMultipart *multipart, GMimeObject *part);
GMimeObject * (* remove_part_at) (GMimeMultipart *multipart, int index);
GMimeObject * (* get_part) (GMimeMultipart *multipart, int index);
@@ -80,7 +75,7 @@
void g_mime_multipart_add_part (GMimeMultipart *multipart, GMimeObject *part);
void g_mime_multipart_add_part_at (GMimeMultipart *multipart, GMimeObject *part, int index);
-void g_mime_multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part);
+gboolean g_mime_multipart_remove_part (GMimeMultipart *multipart, GMimeObject *part);
GMimeObject *g_mime_multipart_remove_part_at (GMimeMultipart *multipart, int index);
GMimeObject *g_mime_multipart_get_part (GMimeMultipart *multipart, int index);
Modified: trunk/gmime/gmime-object.c
==============================================================================
--- trunk/gmime/gmime-object.c (original)
+++ trunk/gmime/gmime-object.c Thu Jun 5 14:17:57 2008
@@ -58,7 +58,6 @@
static void g_mime_object_init (GMimeObject *object, GMimeObjectClass *klass);
static void g_mime_object_finalize (GObject *object);
-static void init (GMimeObject *object);
static void prepend_header (GMimeObject *object, const char *name, const char *value);
static void append_header (GMimeObject *object, const char *name, const char *value);
static void set_header (GMimeObject *object, const char *name, const char *value);
@@ -113,7 +112,6 @@
object_class->finalize = g_mime_object_finalize;
- klass->init = init;
klass->prepend_header = prepend_header;
klass->append_header = append_header;
klass->remove_header = remove_header;
@@ -287,13 +285,6 @@
}
-static void
-init (GMimeObject *object)
-{
- /* no-op */
-}
-
-
/**
* g_mime_object_new_type:
* @type: mime type
@@ -344,8 +335,6 @@
object = g_object_new (obj_type, NULL);
- GMIME_OBJECT_GET_CLASS (object)->init (object);
-
return object;
}
Modified: trunk/gmime/gmime-object.h
==============================================================================
--- trunk/gmime/gmime-object.h (original)
+++ trunk/gmime/gmime-object.h Thu Jun 5 14:17:57 2008
@@ -55,8 +55,6 @@
struct _GMimeObjectClass {
GObjectClass parent_class;
- void (* init) (GMimeObject *object);
-
void (* prepend_header) (GMimeObject *object, const char *header, const char *value);
void (* append_header) (GMimeObject *object, const char *header, const char *value);
void (* set_header) (GMimeObject *object, const char *header, const char *value);
Modified: trunk/gmime/gmime-part.c
==============================================================================
--- trunk/gmime/gmime-part.c (original)
+++ trunk/gmime/gmime-part.c Thu Jun 5 14:17:57 2008
@@ -59,7 +59,6 @@
static void g_mime_part_finalize (GObject *object);
/* GMimeObject class methods */
-static void mime_part_init (GMimeObject *object);
static void mime_part_prepend_header (GMimeObject *object, const char *header, const char *value);
static void mime_part_append_header (GMimeObject *object, const char *header, const char *value);
static void mime_part_set_header (GMimeObject *object, const char *header, const char *value);
@@ -107,7 +106,6 @@
gobject_class->finalize = g_mime_part_finalize;
- object_class->init = mime_part_init;
object_class->prepend_header = mime_part_prepend_header;
object_class->append_header = mime_part_append_header;
object_class->remove_header = mime_part_remove_header;
@@ -143,13 +141,6 @@
}
-static void
-mime_part_init (GMimeObject *object)
-{
- /* no-op */
- GMIME_OBJECT_CLASS (parent_class)->init (object);
-}
-
enum {
HEADER_CONTENT_TRANSFER_ENCODING,
HEADER_CONTENT_DESCRIPTION,
Modified: trunk/mono/gmime-api.raw
==============================================================================
--- trunk/mono/gmime-api.raw (original)
+++ trunk/mono/gmime-api.raw Thu Jun 5 14:17:57 2008
@@ -830,10 +830,7 @@
</method>
</object>
<object name="Multipart" cname="GMimeMultipart" parent="GMimeObject">
- <field name="Boundary" cname="boundary" type="char*" />
- <field name="Preface" cname="preface" type="char*" />
- <field name="Postface" cname="postface" type="char*" />
- <field name="Subparts" cname="subparts" type="GList*" />
+ <field name="Priv" cname="priv" type="struct-_GMimeMultipartPrivate*" />
<virtual_method name="AddPart" cname="add_part">
<return-type type="void" />
<parameters>
@@ -850,7 +847,7 @@
</parameters>
</virtual_method>
<virtual_method name="RemovePart" cname="remove_part">
- <return-type type="void" />
+ <return-type type="gboolean" />
<parameters>
<parameter type="GMimeMultipart*" name="multipart" />
<parameter type="GMimeObject*" name="part" />
@@ -937,7 +934,7 @@
</parameters>
</constructor>
<method name="RemovePart" cname="g_mime_multipart_remove_part">
- <return-type type="void" />
+ <return-type type="gboolean" />
<parameters>
<parameter type="GMimeObject*" name="part" />
</parameters>
@@ -1027,12 +1024,6 @@
<field name="ContentType" cname="content_type" type="GMimeContentType*" />
<field name="Headers" cname="headers" type="GMimeHeaderList*" />
<field name="ContentId" cname="content_id" type="char*" />
- <virtual_method name="Init" cname="init">
- <return-type type="void" />
- <parameters>
- <parameter type="GMimeObject*" name="object" />
- </parameters>
- </virtual_method>
<virtual_method name="PrependHeader" cname="prepend_header">
<return-type type="void" />
<parameters>
Modified: trunk/tests/test-mbox.c
==============================================================================
--- trunk/tests/test-mbox.c (original)
+++ trunk/tests/test-mbox.c Thu Jun 5 14:17:57 2008
@@ -60,6 +60,10 @@
print_mime_struct (GMimeStream *stream, GMimeObject *part, int depth)
{
const GMimeContentType *type;
+ GMimeMultipart *multipart;
+ GMimeMessagePart *mpart;
+ GMimeObject *subpart;
+ int i, n;
print_depth (stream, depth);
@@ -68,15 +72,16 @@
g_mime_stream_printf (stream, "Content-Type: %s/%s\n", type->type, type->subtype);
if (GMIME_IS_MULTIPART (part)) {
- GList *subpart;
+ multipart = (GMimeMultipart *) part;
- subpart = GMIME_MULTIPART (part)->subparts;
- while (subpart) {
- print_mime_struct (stream, subpart->data, depth + 1);
- subpart = subpart->next;
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
+ print_mime_struct (stream, subpart, depth + 1);
+ g_object_unref (subpart);
}
} else if (GMIME_IS_MESSAGE_PART (part)) {
- GMimeMessagePart *mpart = (GMimeMessagePart *) part;
+ mpart = (GMimeMessagePart *) part;
if (mpart->message)
print_mime_struct (stream, mpart->message->mime_part, depth + 1);
Modified: trunk/tests/test-parser.c
==============================================================================
--- trunk/tests/test-parser.c (original)
+++ trunk/tests/test-parser.c Thu Jun 5 14:17:57 2008
@@ -55,7 +55,11 @@
print_mime_struct (GMimeObject *part, int depth)
{
const GMimeContentType *type;
+ GMimeMultipart *multipart;
+ GMimeMessagePart *mpart;
+ GMimeObject *subpart;
gboolean has_md5;
+ int i, n;
print_depth (depth);
type = g_mime_object_get_content_type (part);
@@ -64,15 +68,16 @@
has_md5 ? "; md5sum=" : "\n");
if (GMIME_IS_MULTIPART (part)) {
- GList *subpart;
+ multipart = (GMimeMultipart *) part;
- subpart = GMIME_MULTIPART (part)->subparts;
- while (subpart) {
- print_mime_struct (subpart->data, depth + 1);
- subpart = subpart->next;
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
+ print_mime_struct (subpart, depth + 1);
+ g_object_unref (subpart);
}
} else if (GMIME_IS_MESSAGE_PART (part)) {
- GMimeMessagePart *mpart = (GMimeMessagePart *) part;
+ mpart = (GMimeMessagePart *) part;
if (mpart->message)
print_mime_struct (mpart->message->mime_part, depth + 1);
Modified: trunk/tests/test-partial.c
==============================================================================
--- trunk/tests/test-partial.c (original)
+++ trunk/tests/test-partial.c Thu Jun 5 14:17:57 2008
@@ -41,18 +41,22 @@
print_mime_struct (GMimeObject *part, int depth)
{
const GMimeContentType *type;
+ GMimeMultipart *multipart;
+ GMimeObject *subpart;
+ int i, n;
print_depth (depth);
type = g_mime_object_get_content_type (part);
fprintf (stdout, "Content-Type: %s/%s\n", type->type, type->subtype);
if (GMIME_IS_MULTIPART (part)) {
- GList *subpart;
+ multipart = (GMimeMultipart *) part;
- subpart = GMIME_MULTIPART (part)->subparts;
- while (subpart) {
- print_mime_struct (subpart->data, depth + 1);
- subpart = subpart->next;
+ n = g_mime_multipart_get_number (multipart);
+ for (i = 0; i < n; i++) {
+ subpart = g_mime_multipart_get_part (multipart, i);
+ print_mime_struct (subpart, depth + 1);
+ g_object_unref (subpart);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]