]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail, fts: Put application/xhtml+xml MIME parts through html parser as well.
authorTimo Sirainen <tss@iki.fi>
Tue, 27 Oct 2015 21:56:48 +0000 (23:56 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 27 Oct 2015 21:56:48 +0000 (23:56 +0200)
src/lib-mail/mail-html2text.h
src/lib-mail/message-snippet.c
src/lib-mail/test-message-snippet.c
src/plugins/fts/fts-parser-html.c

index 7a2b54530cb34c0c70e3240850f1b23f4acb4c2d..6af484e33db76de67e714ea6d4fa66dd83f7e364 100644 (file)
@@ -12,4 +12,11 @@ void mail_html2text_more(struct mail_html2text *ht,
                         buffer_t *output);
 void mail_html2text_deinit(struct mail_html2text **ht);
 
+static inline bool
+mail_html2text_content_type_match(const char *content_type)
+{
+       return strcasecmp(content_type, "text/html") == 0 ||
+               strcasecmp(content_type, "application/xhtml+xml") == 0;
+}
+
 #endif
index 244625879123971ddb510e73c475e0e93d8f3751..f690bff46870e74e8deacccf814229535eef1ab3 100644 (file)
@@ -115,7 +115,7 @@ int message_snippet_generate(struct istream *input,
                        ct = message_decoder_current_content_type(decoder);
                        if (ct == NULL)
                                /* text/plain */ ;
-                       else if (strcasecmp(ct, "text/html") == 0) {
+                       else if (mail_html2text_content_type_match(ct)) {
                                ctx.html2text = mail_html2text_init(MAIL_HTML2TEXT_FLAG_SKIP_QUOTED);
                                ctx.plain_output = buffer_create_dynamic(pool, 1024);
                        } else if (strncasecmp(ct, "text/", 5) != 0)
index 2444a9b70d1dd314119f77b213cc058e4993ecd4..af4683deaace40cd0ac19d71e83af59697ed5f5a 100644 (file)
@@ -51,6 +51,20 @@ static struct {
          "</div><br =class=3D\"\"></body></html>=\n",
          100,
          "Hi, How is it going? > -foo" },
+
+       { "Content-Transfer-Encoding: quoted-printable\n"
+         "Content-Type: application/xhtml+xml;\n"
+         "      charset=utf-8\n"
+         "\n"
+         "<html><head><meta http-equiv=3D\"Content-Type\" content=3D\"text/html =\n"
+         "charset=3Dutf-8\"></head><body style=3D\"word-wrap: break-word; =\n"
+         "-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\" =\n"
+         "class=3D\"\">Hi,<div class=3D\"\"><br class=3D\"\"></div><div class=3D\"\">How =\n"
+         "is it going? <blockquote>quoted text is ignored</blockquote>\n"
+         "&gt; -foo\n"
+         "</div><br =class=3D\"\"></body></html>=\n",
+         100,
+         "Hi, How is it going? > -foo" },
 };
 
 static void test_message_snippet(void)
index 1a5b2ae29dc01ebc4db9a8c5060fa02f574d936d..b9c1d1e919102450b8fcb3cabbc4c0a68716c765 100644 (file)
@@ -19,7 +19,7 @@ fts_parser_html_try_init(struct mail_user *user ATTR_UNUSED,
 {
        struct html_fts_parser *parser;
 
-       if (strcasecmp(content_type, "text/html") != 0)
+       if (!mail_html2text_content_type_match(content_type))
                return NULL;
 
        parser = i_new(struct html_fts_parser, 1);