[PATCH 6/6] lib/index: add simple html filter

David Bremner david at tethera.net
Wed May 10 04:39:10 PDT 2017


Just drop all (HTML) tags
---
 lib/index.cc               | 38 +++++++++++++++++++++++++++++++++++++-
 test/T680-html-indexing.sh |  5 ++++-
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/lib/index.cc b/lib/index.cc
index 1b420b75..217b58c0 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -211,6 +211,39 @@ filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, si
 }
 
 static void
+filter_filter_html (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
+		    char **outbuf, size_t *outlen, size_t *outprespace)
+{
+/* The following table is intended to implement this DFA (in 'dot'
+   format). Note that 2 and 3 are "hidden" states used to step through
+   the possible out edges of state 1.
+
+digraph html_filter {
+	0 -> 1  [label="<"];
+	0 -> 0;
+	1 -> 4 [label="'"];
+	1 -> 5 [label="\""];
+	1 -> 0 [label=">"];
+	1 -> 1;
+	4 -> 1 [label="'"];
+	4 -> 4;
+	5 -> 1 [label="\""];
+	5 -> 5;
+}
+*/
+    static const scanner_state_t states[] = {
+	{0,  '<',  '<',  1,  0},
+	{1,  '\'', '\'', 4,  2},  /* scanning for quote or > */
+	{1,  '"',  '"',  5,  3},
+	{1,  '>',  '>',  0,  1},
+	{4,  '\'', '\'', 1,  4},  /* inside single quotes */
+	{5,  '"', '"',   1,  5},  /* inside double quotes */
+    };
+    do_filter(states, 1,
+	      gmime_filter, inbuf, inlen, prespace, outbuf, outlen, outprespace);
+}
+
+static void
 filter_complete (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace,
 		 char **outbuf, size_t *outlen, size_t *outprespace)
 {
@@ -257,7 +290,10 @@ notmuch_filter_discard_non_terms_new (GMimeContentType *content_type)
     filter = (NotmuchFilterDiscardNonTerms *) g_object_newv (type, 0, NULL);
     filter->state = 0;
     filter->content_type = content_type;
-    filter->real_filter = filter_filter_uuencode;
+    if (g_mime_content_type_is_type (content_type, "text", "html"))
+	filter->real_filter = filter_filter_html;
+    else
+	filter->real_filter = filter_filter_uuencode;
     return (GMimeFilter *) filter;
 }
 
diff --git a/test/T680-html-indexing.sh b/test/T680-html-indexing.sh
index 5e9cc4cb..74f33708 100755
--- a/test/T680-html-indexing.sh
+++ b/test/T680-html-indexing.sh
@@ -5,10 +5,13 @@ test_description="indexing of html parts"
 add_email_corpus html
 
 test_begin_subtest 'embedded images should not be indexed'
-test_subtest_known_broken
 notmuch search kwpza7svrgjzqwi8fhb2msggwtxtwgqcxp4wbqr4wjddstqmeqa7 > OUTPUT
 test_expect_equal_file /dev/null OUTPUT
 
+test_begin_subtest 'ignore > in attribute text'
+notmuch search swordfish | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file /dev/null OUTPUT
+
 test_begin_subtest 'non tag text should be indexed'
 notmuch search hunter2 | notmuch_search_sanitize > OUTPUT
 cat <<EOF > EXPECTED
-- 
2.11.0



More information about the notmuch mailing list