aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-12-06 08:42:15 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-12-08 03:01:04 +0800
commit3924dc759dbf38df0f9ff6941990dcf242478617 (patch)
treeaa00cb03ef21e3b11759dd9f094c9c2563d05956 /modules
parent4611bcd7b8958c5ffadccc8b68989c839cf3f144 (diff)
downloadgsoc2013-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 'modules')
-rw-r--r--modules/audio-inline/e-mail-parser-audio-inline.c25
-rw-r--r--modules/itip-formatter/e-mail-parser-itip.c17
-rw-r--r--modules/prefer-plain/e-mail-parser-prefer-plain.c179
-rw-r--r--modules/text-highlight/e-mail-parser-text-highlight.c26
-rw-r--r--modules/tnef-attachment/e-mail-parser-tnef-attachment.c34
-rw-r--r--modules/vcard-inline/e-mail-parser-vcard-inline.c29
6 files changed, 162 insertions, 148 deletions
diff --git a/modules/audio-inline/e-mail-parser-audio-inline.c b/modules/audio-inline/e-mail-parser-audio-inline.c
index 5509306118..ca87693fe4 100644
--- a/modules/audio-inline/e-mail-parser-audio-inline.c
+++ b/modules/audio-inline/e-mail-parser-audio-inline.c
@@ -101,15 +101,18 @@ mail_part_audio_inline_free (EMailPart *mail_part)
}
}
-static GSList *
+static gint
empe_audio_inline_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_queue)
{
EMailPartAudioInline *mail_part;
+ GQueue work_queue = G_QUEUE_INIT;
gint len;
+ gint n_parts_added = 0;
len = part_id->len;
g_string_append (part_id, ".org-gnome-audio-inline-button-panel");
@@ -117,16 +120,22 @@ empe_audio_inline_parse (EMailParserExtension *extension,
d (printf ("audio inline formatter: format classid %s\n", part_id->str));
mail_part = (EMailPartAudioInline *) e_mail_part_subclass_new (
- part, part_id->str, sizeof (EMailPartAudioInline),
- (GFreeFunc) mail_part_audio_inline_free);
+ part, part_id->str, sizeof (EMailPartAudioInline),
+ (GFreeFunc) mail_part_audio_inline_free);
mail_part->parent.mime_type = camel_content_type_simple (
- camel_mime_part_get_content_type (part));
+ camel_mime_part_get_content_type (part));
mail_part->parent.is_attachment = TRUE;
g_string_truncate (part_id, len);
- return e_mail_parser_wrap_as_attachment (
- parser, part, g_slist_append (NULL, mail_part),
- part_id, cancellable);
+ g_queue_push_tail (&work_queue, mail_part);
+ n_parts_added++;
+
+ e_mail_parser_wrap_as_attachment (
+ parser, part, part_id, &work_queue);
+
+ e_queue_transfer (&work_queue, out_mail_queue);
+
+ return TRUE;
}
static guint32
diff --git a/modules/itip-formatter/e-mail-parser-itip.c b/modules/itip-formatter/e-mail-parser-itip.c
index 56bbd53da1..505842807a 100644
--- a/modules/itip-formatter/e-mail-parser-itip.c
+++ b/modules/itip-formatter/e-mail-parser-itip.c
@@ -180,12 +180,13 @@ bind_itip_view (EMailPart *part,
/*******************************************************************************/
-static GSList *
+static gboolean
empe_itip_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
EShell *shell;
GSettings *settings;
@@ -195,7 +196,7 @@ empe_itip_parse (EMailParserExtension *extension,
GByteArray *byte_array;
gint len;
const CamelContentDisposition *disposition;
- GSList *parts;
+ GQueue work_queue = G_QUEUE_INIT;
len = part_id->len;
g_string_append_printf (part_id, ".itip");
@@ -234,18 +235,20 @@ empe_itip_parse (EMailParserExtension *extension,
g_object_unref (stream);
- parts = g_slist_append (NULL, itip_part);
+ g_queue_push_tail (&work_queue, itip_part);
disposition = camel_mime_part_get_content_disposition (part);
if (disposition &&
(g_strcmp0 (disposition->disposition, "attachment") == 0)) {
- parts = e_mail_parser_wrap_as_attachment (
- parser, part, parts, part_id, cancellable);
+ e_mail_parser_wrap_as_attachment (
+ parser, part, part_id, &work_queue);
}
+ e_queue_transfer (&work_queue, out_mail_parts);
+
g_string_truncate (part_id, len);
- return parts;
+ return TRUE;
}
static guint32
diff --git a/modules/prefer-plain/e-mail-parser-prefer-plain.c b/modules/prefer-plain/e-mail-parser-prefer-plain.c
index 66ff32106c..296369ed32 100644
--- a/modules/prefer-plain/e-mail-parser-prefer-plain.c
+++ b/modules/prefer-plain/e-mail-parser-prefer-plain.c
@@ -99,18 +99,19 @@ enum {
PROP_SHOW_SUPPRESSED
};
-static GSList *
+static void
make_part_attachment (EMailParser *parser,
CamelMimePart *part,
GString *part_id,
gboolean force_html,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
- GSList *parts;
-
if (camel_content_type_is (camel_mime_part_get_content_type (part), "text", "html")) {
+ GQueue work_queue = G_QUEUE_INIT;
EMailPart *mail_part;
gint len;
+
/* always show HTML as attachments and not inline */
camel_mime_part_set_disposition (part, "attachment");
@@ -126,9 +127,12 @@ make_part_attachment (EMailParser *parser,
mail_part->mime_type = g_strdup ("text/html");
g_string_truncate (part_id, len);
- parts = e_mail_parser_wrap_as_attachment (
- parser, part, g_slist_append (NULL, mail_part),
- part_id, cancellable);
+ g_queue_push_tail (&work_queue, mail_part);
+
+ e_mail_parser_wrap_as_attachment (
+ parser, part, part_id, &work_queue);
+
+ e_queue_transfer (&work_queue, out_mail_parts);
} else if (force_html && CAMEL_IS_MIME_MESSAGE (part)) {
/* message was asked to be formatted as text/html;
@@ -137,52 +141,51 @@ make_part_attachment (EMailParser *parser,
CamelDataWrapper *content;
content = camel_medium_get_content (CAMEL_MEDIUM (part));
- g_return_val_if_fail (content != NULL, NULL);
+ g_return_if_fail (content != NULL);
new_part = camel_mime_part_new ();
camel_medium_set_content (CAMEL_MEDIUM (new_part), content);
- parts = e_mail_parser_parse_part (
- parser, new_part, part_id, cancellable);
+ e_mail_parser_parse_part (
+ parser, new_part, part_id,
+ cancellable, out_mail_parts);
g_object_unref (new_part);
} else {
- parts = e_mail_parser_parse_part (
- parser, part, part_id, cancellable);
+ e_mail_parser_parse_part (
+ parser, part, part_id, cancellable, out_mail_parts);
}
-
- return parts;
}
static void
-hide_parts (GSList *parts)
+hide_parts (GQueue *work_queue)
{
- GSList *iter;
+ GList *head, *link;
- for (iter = parts; iter; iter = g_slist_next (iter)) {
- EMailPart *p = iter->data;
+ head = g_queue_peek_head_link (work_queue);
- if (!p)
- continue;
+ for (link = head; link != NULL; link = g_list_next (link)) {
+ EMailPart *mail_part = link->data;
- p->is_hidden = TRUE;
+ mail_part->is_hidden = TRUE;
}
}
-static GSList *
+static gboolean
empe_prefer_plain_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
EMailParserPreferPlain *emp_pp;
CamelMultipart *mp;
gint i, nparts, partidlen;
- GSList *parts;
CamelContentType *ct;
gboolean has_calendar = FALSE;
- GSList *plain_text_parts = NULL;
+ GQueue plain_text_parts = G_QUEUE_INIT;
+ GQueue work_queue = G_QUEUE_INIT;
emp_pp = (EMailParserPreferPlain *) extension;
@@ -194,36 +197,35 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
/* Prevent recursion, fall back to next (real text/html) parser */
if (strstr (part_id->str, ".alternative-prefer-plain.") != NULL)
- return NULL;
+ return FALSE;
/* Not enforcing text/plain, so use real parser */
if (emp_pp->mode != ONLY_PLAIN)
- return NULL;
+ return FALSE;
/* Enforcing text/plain, but got only HTML part, so add it
* as attachment, to not show empty message preview, which
* is confusing. */
- return make_part_attachment (
- parser, part, part_id,
- FALSE, cancellable);
+ make_part_attachment (
+ parser, part, part_id, FALSE,
+ cancellable, out_mail_parts);
+
+ return TRUE;
}
- parts = NULL;
partidlen = part_id->len;
mp = (CamelMultipart *) camel_medium_get_content (CAMEL_MEDIUM (part));
- if (!CAMEL_IS_MULTIPART (mp)) {
+ if (!CAMEL_IS_MULTIPART (mp))
return e_mail_parser_parse_part_as (
parser, part, part_id,
- "application/vnd.evolution.source", cancellable);
- }
+ "application/vnd.evolution.source",
+ cancellable, out_mail_parts);
nparts = camel_multipart_get_number (mp);
for (i = 0; i < nparts; i++) {
-
CamelMimePart *sp;
- GSList *sparts = NULL;
sp = camel_multipart_get_part (mp, i);
ct = camel_mime_part_get_content_type (sp);
@@ -232,61 +234,52 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
g_string_append_printf (part_id, ".alternative-prefer-plain.%d", i);
if (camel_content_type_is (ct, "text", "html")) {
-
if (emp_pp->mode != PREFER_HTML) {
if (emp_pp->show_suppressed) {
- sparts = make_part_attachment (
- parser, sp, part_id,
- FALSE, cancellable);
+ make_part_attachment (
+ parser, sp, part_id, FALSE,
+ cancellable, &work_queue);
}
} else {
- sparts = e_mail_parser_parse_part (
- parser, sp, part_id, cancellable);
+ e_mail_parser_parse_part (
+ parser, sp, part_id,
+ cancellable, &work_queue);
}
- parts = g_slist_concat (parts, sparts);
- continue;
- }
-
- if (camel_content_type_is (ct, "text", "plain")) {
-
- sparts = e_mail_parser_parse_part (
- parser, sp, part_id, cancellable);
-
- plain_text_parts = g_slist_concat (plain_text_parts, sparts);
- continue;
- }
+ } else if (camel_content_type_is (ct, "text", "plain")) {
+ e_mail_parser_parse_part (
+ parser, sp, part_id,
+ cancellable, &plain_text_parts);
/* Always show calendar part! */
- if (camel_content_type_is (ct, "text", "calendar") ||
+ } else if (camel_content_type_is (ct, "text", "calendar") ||
camel_content_type_is (ct, "text", "x-calendar")) {
- /* Hide everything else, displaying native calendar part only */
- hide_parts (parts);
+ /* Hide everything else, displaying
+ * native calendar part only. */
+ hide_parts (&work_queue);
- sparts = e_mail_parser_parse_part (
- parser, sp, part_id, cancellable);
+ e_mail_parser_parse_part (
+ parser, sp, part_id, cancellable, &work_queue);
- parts = g_slist_concat (parts, sparts);
has_calendar = TRUE;
- continue;
- }
/* Multiparts can represent a text/html with inline images or so */
- if (camel_content_type_is (ct, "multipart", "*")) {
- GSList *iter;
+ } else if (camel_content_type_is (ct, "multipart", "*")) {
+ GQueue inner_queue = G_QUEUE_INIT;
+ GList *head, *link;
gboolean has_html = FALSE;
- sparts = e_mail_parser_parse_part (
- parser, sp, part_id, cancellable);
+ e_mail_parser_parse_part (
+ parser, sp, part_id, cancellable, &inner_queue);
+
+ head = g_queue_peek_head_link (&inner_queue);
/* Check whether the multipart contains a text/html part */
- for (iter = sparts; iter; iter = g_slist_next (iter)) {
- EMailPart *p = iter->data;
- if (!p)
- continue;
+ for (link = head; link != NULL; link = g_list_next (link)) {
+ EMailPart *mail_part = link->data;
- if (strstr (p->id, ".text_html") != NULL) {
+ if (strstr (mail_part->id, ".text_html") != NULL) {
has_html = TRUE;
break;
}
@@ -294,41 +287,41 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
if (has_html && (emp_pp->mode != PREFER_HTML)) {
if (emp_pp->show_suppressed) {
- sparts = e_mail_parser_wrap_as_attachment (
- parser, sp, sparts, part_id,
- cancellable);
+ e_mail_parser_wrap_as_attachment (
+ parser, sp, part_id,
+ &inner_queue);
} else {
- hide_parts (sparts);
+ hide_parts (&inner_queue);
}
}
- parts = g_slist_concat (parts, sparts);
- continue;
- }
+ e_queue_transfer (&inner_queue, &work_queue);
/* Parse everything else as an attachment */
- sparts = e_mail_parser_parse_part (
- parser, sp, part_id, cancellable);
- parts = g_slist_concat (
- parts,
- e_mail_parser_wrap_as_attachment (
- parser, sp, sparts, part_id,
- cancellable));
+ } else {
+ GQueue inner_queue = G_QUEUE_INIT;
+
+ e_mail_parser_parse_part (
+ parser, sp, part_id,
+ cancellable, &inner_queue);
+ e_mail_parser_wrap_as_attachment (
+ parser, sp, part_id, &inner_queue);
+
+ e_queue_transfer (&inner_queue, &work_queue);
+ }
}
/* Don't hide the plain text if there's nothing else to display */
- if (has_calendar || (nparts > 1 && emp_pp->mode == PREFER_HTML)) {
- hide_parts (plain_text_parts);
- }
+ if (has_calendar || (nparts > 1 && emp_pp->mode == PREFER_HTML))
+ hide_parts (&plain_text_parts);
- if (plain_text_parts) {
- /* plain_text parts should be always first */
- parts = g_slist_concat (plain_text_parts, parts);
- }
+ /* plain_text parts should be always first */
+ e_queue_transfer (&plain_text_parts, out_mail_parts);
+ e_queue_transfer (&work_queue, out_mail_parts);
g_string_truncate (part_id, partidlen);
- return parts;
+ return TRUE;
}
static const gchar **
diff --git a/modules/text-highlight/e-mail-parser-text-highlight.c b/modules/text-highlight/e-mail-parser-text-highlight.c
index 69aa1ccff2..eb56162a3d 100644
--- a/modules/text-highlight/e-mail-parser-text-highlight.c
+++ b/modules/text-highlight/e-mail-parser-text-highlight.c
@@ -58,21 +58,20 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (
E_TYPE_MAIL_PARSER_EXTENSION,
e_mail_parser_parser_extension_interface_init));
-static GSList *
+static gboolean
empe_text_highlight_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
- GSList *parts;
- gint len;
CamelContentType *ct;
+ gint len;
/* Prevent recursion */
- if (strstr (part_id->str, ".text-highlight") != NULL) {
- return NULL;
- }
+ if (strstr (part_id->str, ".text-highlight") != NULL)
+ return FALSE;
/* Don't parse text/html if it's not an attachment */
ct = camel_mime_part_get_content_type (part);
@@ -80,9 +79,8 @@ empe_text_highlight_parse (EMailParserExtension *extension,
const CamelContentDisposition *disp;
disp = camel_mime_part_get_content_disposition (part);
- if (!disp || (g_strcmp0 (disp->disposition, "attachment") != 0)) {
- return NULL;
- }
+ if (!disp || (g_strcmp0 (disp->disposition, "attachment") != 0))
+ return FALSE;
}
len = part_id->len;
@@ -90,12 +88,14 @@ empe_text_highlight_parse (EMailParserExtension *extension,
/* All source codes and scripts are in general plain texts,
* so let text/plain parser handle it. */
- parts = e_mail_parser_parse_part_as (
- parser, part, part_id, "text/plain", cancellable);
+
+ e_mail_parser_parse_part_as (
+ parser, part, part_id, "text/plain",
+ cancellable, out_mail_parts);
g_string_truncate (part_id, len);
- return parts;
+ return TRUE;
}
static const gchar **
diff --git a/modules/tnef-attachment/e-mail-parser-tnef-attachment.c b/modules/tnef-attachment/e-mail-parser-tnef-attachment.c
index 3de54e627f..a0342aaa37 100644
--- a/modules/tnef-attachment/e-mail-parser-tnef-attachment.c
+++ b/modules/tnef-attachment/e-mail-parser-tnef-attachment.c
@@ -114,12 +114,13 @@ sanitize_filename (const gchar *filename)
}
}
-static GSList *
+static gboolean
empe_tnef_attachment_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
gchar *tmpdir, *name;
CamelStream *out;
@@ -130,30 +131,30 @@ empe_tnef_attachment_parse (EMailParserExtension *extension,
CamelDataWrapper *content;
gint len;
TNEFStruct tnef;
- GSList *parts;
+ GQueue work_queue = G_QUEUE_INIT;
tmpdir = e_mkdtemp ("tnef-attachment-XXXXXX");
if (tmpdir == NULL)
- return NULL;
+ return FALSE;
name = g_build_filename (tmpdir, ".evo-attachment.tnef", NULL);
out = camel_stream_fs_new_with_name (name, O_RDWR | O_CREAT, 0666, NULL);
if (out == NULL) {
g_free (name);
- return NULL;
+ return FALSE;
}
content = camel_medium_get_content ((CamelMedium *) part);
if (content == NULL) {
g_free (name);
g_object_unref (out);
- return NULL;
+ return FALSE;
}
if (camel_data_wrapper_decode_to_stream_sync (content, out, NULL, NULL) == -1
|| camel_stream_close (out, NULL, NULL) == -1) {
g_object_unref (out);
g_free (name);
- return NULL;
+ return FALSE;
}
g_object_unref (out);
@@ -172,7 +173,7 @@ empe_tnef_attachment_parse (EMailParserExtension *extension,
if (dir == NULL) {
g_object_unref (out);
g_free (name);
- return NULL;
+ return FALSE;
}
mainpart = camel_mime_part_new ();
@@ -226,7 +227,6 @@ empe_tnef_attachment_parse (EMailParserExtension *extension,
len = part_id->len;
g_string_append_printf (part_id, ".tnef");
- parts = NULL;
if (camel_multipart_get_number (mp) > 0) {
CamelMimePart *part = camel_mime_part_new ();
@@ -235,18 +235,20 @@ empe_tnef_attachment_parse (EMailParserExtension *extension,
(CamelMedium *) part,
CAMEL_DATA_WRAPPER (mp));
- parts = e_mail_parser_parse_part_as (
- parser, part, part_id,
- "multipart/mixed", cancellable);
+ e_mail_parser_parse_part_as (
+ parser, part, part_id, "multipart/mixed",
+ cancellable, &work_queue);
g_object_unref (part);
}
g_string_truncate (part_id, len);
- if (parts)
- parts = e_mail_parser_wrap_as_attachment (
- parser, part, parts, part_id, cancellable);
+ if (!g_queue_is_empty (&work_queue))
+ e_mail_parser_wrap_as_attachment (
+ parser, part, part_id, &work_queue);
+
+ e_queue_transfer (&work_queue, out_mail_parts);
g_object_unref (mp);
g_object_unref (mainpart);
@@ -254,7 +256,7 @@ empe_tnef_attachment_parse (EMailParserExtension *extension,
g_free (name);
g_free (tmpdir);
- return parts;
+ return TRUE;
}
static const gchar **
diff --git a/modules/vcard-inline/e-mail-parser-vcard-inline.c b/modules/vcard-inline/e-mail-parser-vcard-inline.c
index 319775b6eb..84f4f2f538 100644
--- a/modules/vcard-inline/e-mail-parser-vcard-inline.c
+++ b/modules/vcard-inline/e-mail-parser-vcard-inline.c
@@ -328,39 +328,46 @@ decode_vcard (EMailPartVCardInline *vcard_part,
g_object_unref (stream);
}
-static GSList *
+static gboolean
empe_vcard_inline_parse (EMailParserExtension *extension,
EMailParser *parser,
CamelMimePart *part,
GString *part_id,
- GCancellable *cancellable)
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
EMailPartVCardInline *vcard_part;
+ GQueue work_queue = G_QUEUE_INIT;
gint len;
len = part_id->len;
g_string_append (part_id, ".org-gnome-vcard-inline-display");
vcard_part = (EMailPartVCardInline *) e_mail_part_subclass_new (
- part, part_id->str, sizeof (EMailPartVCardInline),
- (GFreeFunc) mail_part_vcard_inline_free);
+ part, part_id->str, sizeof (EMailPartVCardInline),
+ (GFreeFunc) mail_part_vcard_inline_free);
vcard_part->parent.mime_type = camel_content_type_simple (
- camel_mime_part_get_content_type (part));
+ camel_mime_part_get_content_type (part));
vcard_part->parent.bind_func = (EMailPartDOMBindFunc) bind_dom;
vcard_part->parent.is_attachment = TRUE;
vcard_part->formatter = g_object_new (
- EAB_TYPE_CONTACT_FORMATTER,
- "display-mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT,
- "render-maps", FALSE, NULL);
+ EAB_TYPE_CONTACT_FORMATTER,
+ "display-mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT,
+ "render-maps", FALSE, NULL);
g_object_ref (part);
decode_vcard (vcard_part, part);
g_string_truncate (part_id, len);
- return e_mail_parser_wrap_as_attachment (
- parser, part, g_slist_append (NULL, vcard_part),
- part_id, cancellable);
+ g_queue_push_tail (&work_queue, vcard_part);
+
+ e_mail_parser_wrap_as_attachment (
+ parser, part, part_id, &work_queue);
+
+ e_queue_transfer (&work_queue, out_mail_parts);
+
+ return TRUE;
}
static guint32