2 * e-mail-parser-message.c
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.
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
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/>.
18 #include "evolution-config.h"
21 #include <glib/gi18n-lib.h>
23 #include <e-util/e-util.h>
24 #include <libemail-engine/libemail-engine.h>
26 #include "e-mail-parser-extension.h"
27 #include "e-mail-part-attachment.h"
28 #include "e-mail-part-utils.h"
30 typedef EMailParserExtension EMailParserMessage
;
31 typedef EMailParserExtensionClass EMailParserMessageClass
;
33 GType
e_mail_parser_message_get_type (void);
37 e_mail_parser_message
,
38 E_TYPE_MAIL_PARSER_EXTENSION
)
40 static const gchar
*parser_mime_types
[] = {
41 "application/vnd.evolution.message",
46 empe_message_parse (EMailParserExtension
*extension
,
50 GCancellable
*cancellable
,
51 GQueue
*out_mail_parts
)
53 GQueue work_queue
= G_QUEUE_INIT
;
59 e_mail_parser_parse_part_as (
60 parser
, part
, part_id
,
61 "application/vnd.evolution.headers",
62 cancellable
, out_mail_parts
);
64 ct
= camel_mime_part_get_content_type (part
);
65 mime_type
= camel_content_type_simple (ct
);
67 if (camel_content_type_is (ct
, "message", "*")) {
68 /* get mime type of the content of the message,
69 * instead of using a generic message/rfc822 */
70 CamelDataWrapper
*content
;
72 content
= camel_medium_get_content (CAMEL_MEDIUM (part
));
74 ct
= camel_data_wrapper_get_mime_type_field (content
);
77 mime_type
= camel_content_type_simple (ct
);
81 /* Actual message body */
83 e_mail_parser_parse_part_as (
84 parser
, part
, part_id
, mime_type
,
85 cancellable
, &work_queue
);
87 /* If the EMailPart representing the message body is marked as an
88 * attachment, wrap it as such so it gets added to the attachment
89 * bar but also set the "force_inline" flag since it doesn't make
90 * sense to collapse the message body if we can render it. */
91 mail_part
= g_queue_peek_head (&work_queue
);
92 if (mail_part
!= NULL
&& !E_IS_MAIL_PART_ATTACHMENT (mail_part
)) {
93 if (e_mail_part_get_is_attachment (mail_part
)) {
94 e_mail_parser_wrap_as_attachment (
95 parser
, part
, part_id
, &work_queue
);
97 mail_part
= g_queue_peek_head (&work_queue
);
99 if (mail_part
!= NULL
)
100 mail_part
->force_inline
= TRUE
;
104 if (CAMEL_IS_MIME_MESSAGE (part
)) {
105 CamelInternetAddress
*from_address
;
107 from_address
= camel_mime_message_get_from (CAMEL_MIME_MESSAGE (part
));
111 for (link
= g_queue_peek_head_link (&work_queue
); link
; link
= g_list_next (link
)) {
112 mail_part
= link
->data
;
115 e_mail_part_verify_validity_sender (mail_part
, from_address
);
120 e_queue_transfer (&work_queue
, out_mail_parts
);
128 e_mail_parser_message_class_init (EMailParserExtensionClass
*class)
130 class->mime_types
= parser_mime_types
;
131 class->priority
= G_PRIORITY_LOW
;
132 class->parse
= empe_message_parse
;
136 e_mail_parser_message_init (EMailParserExtension
*extension
)