aboutsummaryrefslogtreecommitdiffstats
path: root/em-format/e-mail-parser-extension.c
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 /em-format/e-mail-parser-extension.c
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 'em-format/e-mail-parser-extension.c')
-rw-r--r--em-format/e-mail-parser-extension.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/em-format/e-mail-parser-extension.c b/em-format/e-mail-parser-extension.c
index 72f1fd8445..df8fc54dcb 100644
--- a/em-format/e-mail-parser-extension.c
+++ b/em-format/e-mail-parser-extension.c
@@ -52,18 +52,20 @@ e_mail_parser_extension_default_init (EMailParserExtensionInterface *interface)
* @part_id: a #GString to which parser will append ID of the parsed part.
* @flags: #EMailParserFlags
* @cancellable: (allow-none) A #GCancellable
+ * @out_mail_parts: a #GQueue to deposit #EMailPart instances
*
* A virtual function reimplemented in all mail parser extensions. The function
- * decodes and parses the @mime_part, creating one or more #EMailPart<!-//>s.
+ * decodes and parses the @mime_part, appending one or more #EMailPart<!-//>s
+ * to the @out_mail_parts queue.
*
- * When the function is unable to parse the @mime_part (either because it's broken
- * or because it is a different mimetype then the extension is specialized for), the
- * function will return @NULL indicating the #EMailParser, that it should pick
- * another extension.
+ * When the function is unable to parse the @mime_part (either because it's
+ * broken or because it is a different MIME type then the extension is
+ * specialized for), the function will return %FALSE to indicate to the
+ * #EMailParser that it should pick another extension.
*
- * When the @mime_part contains for example multipart/mixed of one RFC822 message
- * with an attachment and of one image, then parser must make sure that the
- * returned #GSList is correctly ordered:
+ * When the @mime_part contains for example multipart/mixed of one RFC822
+ * message with an attachment and of one image, then parser must make sure
+ * that parts are appeded to @out_mail_parts in the correct order.
*
* part1.rfc822.plain_text
* part1.rfc822.attachment
@@ -71,25 +73,33 @@ e_mail_parser_extension_default_init (EMailParserExtensionInterface *interface)
*
* Implementation of this function must be thread-safe.
*
- * Return value: Returns #GSList of #EMailPart<!-//>s when the part was succesfully
- * parsed, returns @NULL when the parser is not able to parse the part.
+ * Returns: %TRUE if the @mime_part was handled (even if no
+ * #EMailPart<!-//>s were added to @out_mail_parts), or
+ * %FALSE if the @mime_part was not handled
*/
-GSList *
+gboolean
e_mail_parser_extension_parse (EMailParserExtension *extension,
- EMailParser *parser,
- CamelMimePart *mime_part,
- GString *part_id,
- GCancellable *cancellable)
+ EMailParser *parser,
+ CamelMimePart *mime_part,
+ GString *part_id,
+ GCancellable *cancellable,
+ GQueue *out_mail_parts)
{
EMailParserExtensionInterface *interface;
- g_return_val_if_fail (E_IS_MAIL_PARSER_EXTENSION (extension), NULL);
- g_return_val_if_fail (E_IS_MAIL_PARSER (parser), NULL);
+ g_return_val_if_fail (E_IS_MAIL_PARSER_EXTENSION (extension), FALSE);
+ g_return_val_if_fail (E_IS_MAIL_PARSER (parser), FALSE);
interface = E_MAIL_PARSER_EXTENSION_GET_INTERFACE (extension);
- g_return_val_if_fail (interface->parse != NULL, NULL);
+ g_return_val_if_fail (interface->parse != NULL, FALSE);
- return interface->parse (extension, parser, mime_part, part_id, cancellable);
+ /* Check for cancellation before calling the method. */
+ if (g_cancellable_is_cancelled (cancellable))
+ return FALSE;
+
+ return interface->parse (
+ extension, parser, mime_part, part_id,
+ cancellable, out_mail_parts);
}
guint32