[PATCH 7/7] lib/index: add simple html filter
David Bremner
david at tethera.net
Wed Mar 22 04:23:06 PDT 2017
Just drop all tags
---
lib/index.cc | 21 ++++++++++++++++++++-
test/T680-html-indexing.sh | 5 ++++-
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index fd66762c..324e6e79 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -206,6 +206,22 @@ 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)
+{
+ 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)
{
@@ -252,7 +268,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