diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-12-06 08:42:15 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-12-08 03:01:04 +0800 |
commit | 3924dc759dbf38df0f9ff6941990dcf242478617 (patch) | |
tree | aa00cb03ef21e3b11759dd9f094c9c2563d05956 /em-format/e-mail-parser-application-mbox.c | |
parent | 4611bcd7b8958c5ffadccc8b68989c839cf3f144 (diff) | |
download | gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar.gz gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar.bz2 gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar.lz gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar.xz gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.tar.zst gsoc2013-evolution-3924dc759dbf38df0f9ff6941990dcf242478617.zip |
EMailParserExtension: Collect EMailParts in a GQueue.
Collect EMailParts in a GQueue provided to the EMailParserExtension,
and change the return type of parse() to gboolean to indicate whether
the given CamelMimePart was handled (even if no parts were added to
the output GQueue).
This avoids the awkward corner case of a parser extension returning a
linked list node with a NULL data member to indicate the CamelMimePart
was handled but no EMailParts produced, and then having to watch out
for that NULL data member corner case throughout the application.
Also, remove the GCancellable parameter from e_mail_parser_error() and
e_mail_parser_wrap_as_attachment() since neither function blocks.
Diffstat (limited to 'em-format/e-mail-parser-application-mbox.c')
-rw-r--r-- | em-format/e-mail-parser-application-mbox.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/em-format/e-mail-parser-application-mbox.c b/em-format/e-mail-parser-application-mbox.c index fb901afdea..35eedf9a5e 100644 --- a/em-format/e-mail-parser-application-mbox.c +++ b/em-format/e-mail-parser-application-mbox.c @@ -60,24 +60,21 @@ G_DEFINE_TYPE_EXTENDED ( static const gchar * parser_mime_types[] = { "application/mbox", NULL }; -static GSList * +static gboolean empe_app_mbox_parse (EMailParserExtension *extension, EMailParser *parser, CamelMimePart *part, GString *part_id, - GCancellable *cancellable) + GCancellable *cancellable, + GQueue *out_mail_parts) { CamelMimeParser *mime_parser; CamelStream *mem_stream; camel_mime_parser_state_t state; gint old_len; gint messages; - GSList *parts; GError *error = NULL; - if (g_cancellable_is_cancelled (cancellable)) - return NULL; - /* Extract messages from the application/mbox part and * render them as a flat list of messages. */ @@ -103,14 +100,14 @@ empe_app_mbox_parse (EMailParserExtension *extension, camel_mime_parser_init_with_stream (mime_parser, mem_stream, &error); if (error != NULL) { - parts = e_mail_parser_error ( - parser, cancellable, + e_mail_parser_error ( + parser, out_mail_parts, _("Error parsing MBOX part: %s"), error->message); g_object_unref (mem_stream); g_object_unref (mime_parser); g_error_free (error); - return parts; + return TRUE; } g_object_unref (mem_stream); @@ -121,11 +118,10 @@ empe_app_mbox_parse (EMailParserExtension *extension, messages = 0; state = camel_mime_parser_step (mime_parser, NULL, NULL); - parts = NULL; while (state == CAMEL_MIME_PARSER_STATE_FROM) { + GQueue work_queue = G_QUEUE_INIT; CamelMimeMessage *message; CamelMimePart *opart; - GSList *new_parts; message = camel_mime_message_new (); opart = CAMEL_MIME_PART (message); @@ -142,23 +138,22 @@ empe_app_mbox_parse (EMailParserExtension *extension, camel_medium_set_content (CAMEL_MEDIUM (opart), CAMEL_DATA_WRAPPER (message)); camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (opart), "message/rfc822"); - new_parts = e_mail_parser_parse_part_as ( - parser, opart, - part_id, "message/rfc822", cancellable); + e_mail_parser_parse_part_as ( + parser, opart, part_id, "message/rfc822", + cancellable, &work_queue); /* Wrap every message as attachment */ - new_parts = e_mail_parser_wrap_as_attachment ( - parser, opart, - new_parts, part_id, cancellable); + e_mail_parser_wrap_as_attachment ( + parser, opart, part_id, &work_queue); /* Inline all messages in mbox */ - if (new_parts && new_parts->data) { - EMailPart *p = new_parts->data; + if (!g_queue_is_empty (&work_queue)) { + EMailPart *p = g_queue_peek_head (&work_queue); p->force_inline = TRUE; } - parts = g_slist_concat (parts, new_parts); + e_queue_transfer (&work_queue, out_mail_parts); g_string_truncate (part_id, old_len); @@ -175,7 +170,7 @@ empe_app_mbox_parse (EMailParserExtension *extension, g_object_unref (mime_parser); - return parts; + return TRUE; } static guint32 |