| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 2020 Red Hat (www.redhat.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include <em-format/e-mail-parser.h> |
| 9 |
#include <em-format/e-mail-parser-extension.h> |
| 10 |
|
| 11 |
#include "e-mail-parser-ews-sharing-metadata.h" |
| 12 |
#include "e-mail-parser-ews-multipart-mixed.h" |
| 13 |
|
| 14 |
typedef EMailParserExtension EMailParserEwsMultipartMixed; |
| 15 |
typedef EMailParserExtensionClass EMailParserEwsMultipartMixedClass; |
| 16 |
|
| 17 |
GType e_mail_parser_ews_multipart_mixed_get_type (void); |
| 18 |
|
| 19 |
G_DEFINE_DYNAMIC_TYPE (EMailParserEwsMultipartMixed, e_mail_parser_ews_multipart_mixed, E_TYPE_MAIL_PARSER_EXTENSION) |
| 20 |
|
| 21 |
static const gchar *parser_mime_types[] = { |
| 22 |
"multipart/mixed", |
| 23 |
NULL |
| 24 |
}; |
| 25 |
|
| 26 |
static gboolean |
| 27 |
emp_ews_mp_mixed_parse (EMailParserExtension *extension, |
| 28 |
EMailParser *parser, |
| 29 |
CamelMimePart *part, |
| 30 |
GString *part_id, |
| 31 |
GCancellable *cancellable, |
| 32 |
GQueue *out_mail_parts) |
| 33 |
{ |
| 34 |
CamelMultipart *mp; |
| 35 |
gboolean handled = FALSE; |
| 36 |
|
| 37 |
/* Allow this only in an EWS folder, because the EWS connection is needed */ |
| 38 |
if (!e_mail_parser_ews_sharing_metadata_is_ews_folder (parser, cancellable)) |
| 39 |
return FALSE; |
| 40 |
|
| 41 |
mp = (CamelMultipart *) camel_medium_get_content (CAMEL_MEDIUM (part)); |
| 42 |
|
| 43 |
if (CAMEL_IS_MULTIPART (mp)) { |
| 44 |
CamelMimePart *sharing_subpart = NULL; |
| 45 |
gint ii, nparts, ntexts = 0, nsharings = 0; |
| 46 |
|
| 47 |
nparts = camel_multipart_get_number (mp); |
| 48 |
|
| 49 |
for (ii = 0; ii < nparts; ii++) { |
| 50 |
CamelMimePart *subpart; |
| 51 |
CamelContentType *ct; |
| 52 |
|
| 53 |
subpart = camel_multipart_get_part (mp, ii); |
| 54 |
ct = camel_mime_part_get_content_type (subpart); |
| 55 |
|
| 56 |
if (ct && (camel_content_type_is (ct, "text", "plain") || camel_content_type_is (ct, "text", "html"))) { |
| 57 |
ntexts++; |
| 58 |
} else if (ct && camel_content_type_is (ct, "application", "x-sharing-metadata-xml")) { |
| 59 |
sharing_subpart = subpart; |
| 60 |
nsharings++; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/* Hide the text parts only if there is only a single sharing subpart */ |
| 65 |
if (nsharings == 1 && nsharings + ntexts == nparts) { |
| 66 |
gint len; |
| 67 |
|
| 68 |
len = part_id->len; |
| 69 |
|
| 70 |
g_string_append_printf (part_id, ".mixed.ews-sharing"); |
| 71 |
handled = e_mail_parser_parse_part (parser, sharing_subpart, part_id, cancellable, out_mail_parts); |
| 72 |
g_string_truncate (part_id, len); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return handled; |
| 77 |
} |
| 78 |
|
| 79 |
static void |
| 80 |
e_mail_parser_ews_multipart_mixed_class_init (EMailParserExtensionClass *klass) |
| 81 |
{ |
| 82 |
klass->mime_types = parser_mime_types; |
| 83 |
klass->priority = G_PRIORITY_LOW - 1; |
| 84 |
klass->flags = E_MAIL_PARSER_EXTENSION_COMPOUND_TYPE; |
| 85 |
klass->parse = emp_ews_mp_mixed_parse; |
| 86 |
} |
| 87 |
|
| 88 |
static void |
| 89 |
e_mail_parser_ews_multipart_mixed_class_finalize (EMailParserExtensionClass *klass) |
| 90 |
{ |
| 91 |
} |
| 92 |
|
| 93 |
static void |
| 94 |
e_mail_parser_ews_multipart_mixed_init (EMailParserExtension *extension) |
| 95 |
{ |
| 96 |
} |
| 97 |
|
| 98 |
void |
| 99 |
e_mail_parser_ews_multipart_mixed_type_register (GTypeModule *type_module) |
| 100 |
{ |
| 101 |
e_mail_parser_ews_multipart_mixed_register_type (type_module); |
| 102 |
} |