1 /*
2  * e-mail-parser-extension.c
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #include "e-mail-parser-extension.h"
19 
G_DEFINE_ABSTRACT_TYPE(EMailParserExtension,e_mail_parser_extension,G_TYPE_OBJECT)20 G_DEFINE_ABSTRACT_TYPE (
21 	EMailParserExtension,
22 	e_mail_parser_extension,
23 	G_TYPE_OBJECT)
24 
25 static void
26 e_mail_parser_extension_class_init (EMailParserExtensionClass *class)
27 {
28 	class->priority = G_PRIORITY_DEFAULT;
29 }
30 
31 static void
e_mail_parser_extension_init(EMailParserExtension * extension)32 e_mail_parser_extension_init (EMailParserExtension *extension)
33 {
34 }
35 
36 /**
37  * e_mail_parser_extension_parse
38  * @extension: an #EMailParserExtension
39  * @parser: an #EMailParser
40  * @mime_part: (allow-none) a #CamelMimePart to parse
41  * @part_id: a #GString to which parser will append ID of the parsed part.
42  * @cancellable: (allow-none) A #GCancellable
43  * @out_mail_parts: a #GQueue to deposit #EMailPart instances
44  *
45  * A virtual function reimplemented in all mail parser extensions. The function
46  * decodes and parses the @mime_part, appending one or more #EMailPart<!-- -->s
47  * to the @out_mail_parts queue.
48  *
49  * When the function is unable to parse the @mime_part (either because it's
50  * broken or because it is a different MIME type then the extension is
51  * specialized for), the function will return %FALSE to indicate to the
52  * #EMailParser that it should pick another extension.
53  *
54  * When the @mime_part contains for example multipart/mixed of one RFC822
55  * message with an attachment and of one image, then parser must make sure
56  * that parts are appeded to @out_mail_parts in the correct order.
57  *
58  * part1.rfc822.plain_text
59  * part1.rfc822.attachment
60  * part2.image
61  *
62  * Implementation of this function must be thread-safe.
63  *
64  * Returns: %TRUE if the @mime_part was handled (even if no
65  *          #EMailPart<!-- -->s were added to @out_mail_parts), or
66  *          %FALSE if the @mime_part was not handled
67  */
68 gboolean
e_mail_parser_extension_parse(EMailParserExtension * extension,EMailParser * parser,CamelMimePart * mime_part,GString * part_id,GCancellable * cancellable,GQueue * out_mail_parts)69 e_mail_parser_extension_parse (EMailParserExtension *extension,
70                                EMailParser *parser,
71                                CamelMimePart *mime_part,
72                                GString *part_id,
73                                GCancellable *cancellable,
74                                GQueue *out_mail_parts)
75 {
76 	EMailParserExtensionClass *class;
77 
78 	g_return_val_if_fail (E_IS_MAIL_PARSER_EXTENSION (extension), FALSE);
79 	g_return_val_if_fail (E_IS_MAIL_PARSER (parser), FALSE);
80 
81 	class = E_MAIL_PARSER_EXTENSION_GET_CLASS (extension);
82 	g_return_val_if_fail (class != NULL, FALSE);
83 	g_return_val_if_fail (class->parse != NULL, FALSE);
84 
85 	/* Check for cancellation before calling the method. */
86 	if (g_cancellable_is_cancelled (cancellable))
87 		return FALSE;
88 
89 	return class->parse (
90 		extension, parser, mime_part, part_id,
91 		cancellable, out_mail_parts);
92 }
93 
94