* v2 of drop HTML tags when indexing
@ 2017-05-10 11:39 David Bremner
2017-05-10 11:39 ` [PATCH 1/6] lib: add content type argument to uuencode filter David Bremner
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
This obsoletes id:20170322112306.12060-1-david@tethera.net
Compared to the previous version:
- drop test already pushed upstream
- add diagram of new state machine
- add longer, and hopefully more illuminating comment about how the
(new) state machines are encoded
- don't create the variable 'current', stick with the existing 'next'
as a state index/pointer
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] lib: add content type argument to uuencode filter.
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
@ 2017-05-10 11:39 ` David Bremner
2017-05-10 11:39 ` [PATCH 2/6] lib/index: Add another layer of indirection in filtering David Bremner
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
The idea is to support more general types of filtering, based on
content type.
---
lib/index.cc | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index 8c145540..1c04cc3d 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -56,6 +56,7 @@ typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeCl
**/
struct _NotmuchFilterDiscardUuencode {
GMimeFilter parent_object;
+ GMimeContentType *content_type;
int state;
};
@@ -63,7 +64,7 @@ struct _NotmuchFilterDiscardUuencodeClass {
GMimeFilterClass parent_class;
};
-static GMimeFilter *notmuch_filter_discard_uuencode_new (void);
+static GMimeFilter *notmuch_filter_discard_uuencode_new (GMimeContentType *content);
static void notmuch_filter_discard_uuencode_finalize (GObject *object);
@@ -102,8 +103,9 @@ notmuch_filter_discard_uuencode_finalize (GObject *object)
static GMimeFilter *
filter_copy (GMimeFilter *gmime_filter)
{
- (void) gmime_filter;
- return notmuch_filter_discard_uuencode_new ();
+ NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+
+ return notmuch_filter_discard_uuencode_new (filter->content_type);
}
static void
@@ -196,7 +198,7 @@ filter_reset (GMimeFilter *gmime_filter)
* Returns: a new #NotmuchFilterDiscardUuencode filter.
**/
static GMimeFilter *
-notmuch_filter_discard_uuencode_new (void)
+notmuch_filter_discard_uuencode_new (GMimeContentType *content_type)
{
static GType type = 0;
NotmuchFilterDiscardUuencode *filter;
@@ -220,6 +222,7 @@ notmuch_filter_discard_uuencode_new (void)
filter = (NotmuchFilterDiscardUuencode *) g_object_newv (type, 0, NULL);
filter->state = 0;
+ filter->content_type = content_type;
return (GMimeFilter *) filter;
}
@@ -396,7 +399,7 @@ _index_mime_part (notmuch_message_t *message,
g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE);
filter = g_mime_stream_filter_new (stream);
- discard_uuencode_filter = notmuch_filter_discard_uuencode_new ();
+ discard_uuencode_filter = notmuch_filter_discard_uuencode_new (content_type);
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
discard_uuencode_filter);
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] lib/index: Add another layer of indirection in filtering
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
2017-05-10 11:39 ` [PATCH 1/6] lib: add content type argument to uuencode filter David Bremner
@ 2017-05-10 11:39 ` David Bremner
2017-05-10 11:39 ` [PATCH 3/6] lib/index: separate state table definition from scanner David Bremner
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
We could add a second gmime filter subclass, but prefer to avoid
duplicating the boilerplate.
---
lib/index.cc | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index 1c04cc3d..74a750b9 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -29,6 +29,8 @@
typedef struct _NotmuchFilterDiscardUuencode NotmuchFilterDiscardUuencode;
typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeClass;
+typedef void (*filter_fun) (GMimeFilter *filter, char *in, size_t len, size_t prespace,
+ char **out, size_t *outlen, size_t *outprespace);
/**
* NotmuchFilterDiscardUuencode:
*
@@ -57,6 +59,7 @@ typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeCl
struct _NotmuchFilterDiscardUuencode {
GMimeFilter parent_object;
GMimeContentType *content_type;
+ filter_fun real_filter;
int state;
};
@@ -110,7 +113,14 @@ filter_copy (GMimeFilter *gmime_filter)
static void
filter_filter (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
- char **outbuf, size_t *outlen, size_t *outprespace)
+ char **outbuf, size_t *outlen, size_t *outprespace) {
+ NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+ (*filter->real_filter)(gmime_filter, inbuf, inlen, prespace, outbuf, outlen, outprespace);
+}
+
+static void
+filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
+ char **outbuf, size_t *outlen, size_t *outprespace)
{
NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
register const char *inptr = inbuf;
@@ -223,7 +233,7 @@ notmuch_filter_discard_uuencode_new (GMimeContentType *content_type)
filter = (NotmuchFilterDiscardUuencode *) g_object_newv (type, 0, NULL);
filter->state = 0;
filter->content_type = content_type;
-
+ filter->real_filter = filter_filter_uuencode;
return (GMimeFilter *) filter;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] lib/index: separate state table definition from scanner.
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
2017-05-10 11:39 ` [PATCH 1/6] lib: add content type argument to uuencode filter David Bremner
2017-05-10 11:39 ` [PATCH 2/6] lib/index: Add another layer of indirection in filtering David Bremner
@ 2017-05-10 11:39 ` David Bremner
2017-05-10 11:39 ` [PATCH 4/6] lib/index: generalize filter name David Bremner
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
We want to reuse the scanner definition with a different table
---
lib/index.cc | 81 +++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 47 insertions(+), 34 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index 74a750b9..02b35b81 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -31,6 +31,15 @@ typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeCl
typedef void (*filter_fun) (GMimeFilter *filter, char *in, size_t len, size_t prespace,
char **out, size_t *outlen, size_t *outprespace);
+
+typedef struct {
+ int state;
+ int a;
+ int b;
+ int next_if_match;
+ int next_if_not_match;
+} scanner_state_t;
+
/**
* NotmuchFilterDiscardUuencode:
*
@@ -119,46 +128,18 @@ filter_filter (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t pres
}
static void
-filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
- char **outbuf, size_t *outlen, size_t *outprespace)
+do_filter (const scanner_state_t states[],
+ int first_skipping_state,
+ GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
+ char **outbuf, size_t *outlen, size_t *outprespace)
{
NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
register const char *inptr = inbuf;
const char *inend = inbuf + inlen;
char *outptr;
-
+ int next;
(void) prespace;
- /* Simple, linear state-transition diagram for our filter.
- *
- * If the character being processed is within the range of [a, b]
- * for the current state then we transition next_if_match
- * state. If not, we transition to the next_if_not_match state.
- *
- * The final two states are special in that they are the states in
- * which we discard data. */
- static const struct {
- int state;
- int a;
- int b;
- int next_if_match;
- int next_if_not_match;
- } states[] = {
- {0, 'b', 'b', 1, 0},
- {1, 'e', 'e', 2, 0},
- {2, 'g', 'g', 3, 0},
- {3, 'i', 'i', 4, 0},
- {4, 'n', 'n', 5, 0},
- {5, ' ', ' ', 6, 0},
- {6, '0', '7', 7, 0},
- {7, '0', '7', 8, 0},
- {8, '0', '7', 9, 0},
- {9, ' ', ' ', 10, 0},
- {10, '\n', '\n', 11, 10},
- {11, 'M', 'M', 12, 0},
- {12, ' ', '`', 12, 11}
- };
- int next;
g_mime_filter_set_size (gmime_filter, inlen, FALSE);
outptr = gmime_filter->outbuf;
@@ -174,7 +155,7 @@ filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, si
next = states[filter->state].next_if_not_match;
}
- if (filter->state < 11)
+ if (filter->state < first_skipping_state)
*outptr++ = *inptr;
filter->state = next;
@@ -187,6 +168,38 @@ filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, si
}
static void
+filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
+ char **outbuf, size_t *outlen, size_t *outprespace)
+{
+ /* Simple, linear state-transition diagram for our filter.
+ *
+ * If the character being processed is within the range of [a, b]
+ * for the current state then we transition next_if_match
+ * state. If not, we transition to the next_if_not_match state.
+ *
+ * The final two states are special in that they are the states in
+ * which we discard data. */
+ static const scanner_state_t states[] = {
+ {0, 'b', 'b', 1, 0},
+ {1, 'e', 'e', 2, 0},
+ {2, 'g', 'g', 3, 0},
+ {3, 'i', 'i', 4, 0},
+ {4, 'n', 'n', 5, 0},
+ {5, ' ', ' ', 6, 0},
+ {6, '0', '7', 7, 0},
+ {7, '0', '7', 8, 0},
+ {8, '0', '7', 9, 0},
+ {9, ' ', ' ', 10, 0},
+ {10, '\n', '\n', 11, 10},
+ {11, 'M', 'M', 12, 0},
+ {12, ' ', '`', 12, 11}
+ };
+
+ do_filter(states, 11,
+ 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)
{
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] lib/index: generalize filter name
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
` (2 preceding siblings ...)
2017-05-10 11:39 ` [PATCH 3/6] lib/index: separate state table definition from scanner David Bremner
@ 2017-05-10 11:39 ` David Bremner
2017-05-10 11:39 ` [PATCH 5/6] lib/index.cc: generalize filter state machine David Bremner
2017-05-10 11:39 ` [PATCH 6/6] lib/index: add simple html filter David Bremner
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
We can't very well call it uuencode if it is going to filter other
things as well.
---
lib/index.cc | 92 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 48 insertions(+), 44 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index 02b35b81..3bb1ac1c 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -26,8 +26,8 @@
/* Oh, how I wish that gobject didn't require so much noisy boilerplate!
* (Though I have at least eliminated some of the stock set...) */
-typedef struct _NotmuchFilterDiscardUuencode NotmuchFilterDiscardUuencode;
-typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeClass;
+typedef struct _NotmuchFilterDiscardNonTerms NotmuchFilterDiscardNonTerms;
+typedef struct _NotmuchFilterDiscardNonTermsClass NotmuchFilterDiscardNonTermsClass;
typedef void (*filter_fun) (GMimeFilter *filter, char *in, size_t len, size_t prespace,
char **out, size_t *outlen, size_t *outprespace);
@@ -41,44 +41,29 @@ typedef struct {
} scanner_state_t;
/**
- * NotmuchFilterDiscardUuencode:
+ * NotmuchFilterDiscardNonTerms:
*
* @parent_object: parent #GMimeFilter
* @encode: encoding vs decoding
* @state: State of the parser
*
- * A filter to discard uuencoded portions of an email.
- *
- * A uuencoded portion is identified as beginning with a line
- * matching:
- *
- * begin [0-7][0-7][0-7] .*
- *
- * After that detection, and beginning with the following line,
- * characters will be discarded as long as the first character of each
- * line begins with M and subsequent characters on the line are within
- * the range of ASCII characters from ' ' to '`'.
- *
- * This is not a perfect UUencode filter. It's possible to have a
- * message that will legitimately match that pattern, (so that some
- * legitimate content is discarded). And for most UUencoded files, the
- * final line of encoded data (the line not starting with M) will be
- * indexed.
+ * A filter to discard non terms portions of an email, i.e. stuff not
+ * worth indexing.
**/
-struct _NotmuchFilterDiscardUuencode {
+struct _NotmuchFilterDiscardNonTerms {
GMimeFilter parent_object;
GMimeContentType *content_type;
filter_fun real_filter;
int state;
};
-struct _NotmuchFilterDiscardUuencodeClass {
+struct _NotmuchFilterDiscardNonTermsClass {
GMimeFilterClass parent_class;
};
-static GMimeFilter *notmuch_filter_discard_uuencode_new (GMimeContentType *content);
+static GMimeFilter *notmuch_filter_discard_non_terms_new (GMimeContentType *content);
-static void notmuch_filter_discard_uuencode_finalize (GObject *object);
+static void notmuch_filter_discard_non_terms_finalize (GObject *object);
static GMimeFilter *filter_copy (GMimeFilter *filter);
static void filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace,
@@ -91,14 +76,14 @@ static void filter_reset (GMimeFilter *filter);
static GMimeFilterClass *parent_class = NULL;
static void
-notmuch_filter_discard_uuencode_class_init (NotmuchFilterDiscardUuencodeClass *klass)
+notmuch_filter_discard_non_terms_class_init (NotmuchFilterDiscardNonTermsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
- object_class->finalize = notmuch_filter_discard_uuencode_finalize;
+ object_class->finalize = notmuch_filter_discard_non_terms_finalize;
filter_class->copy = filter_copy;
filter_class->filter = filter_filter;
@@ -107,7 +92,7 @@ notmuch_filter_discard_uuencode_class_init (NotmuchFilterDiscardUuencodeClass *k
}
static void
-notmuch_filter_discard_uuencode_finalize (GObject *object)
+notmuch_filter_discard_non_terms_finalize (GObject *object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -115,15 +100,15 @@ notmuch_filter_discard_uuencode_finalize (GObject *object)
static GMimeFilter *
filter_copy (GMimeFilter *gmime_filter)
{
- NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+ NotmuchFilterDiscardNonTerms *filter = (NotmuchFilterDiscardNonTerms *) gmime_filter;
- return notmuch_filter_discard_uuencode_new (filter->content_type);
+ return notmuch_filter_discard_non_terms_new (filter->content_type);
}
static void
filter_filter (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
char **outbuf, size_t *outlen, size_t *outprespace) {
- NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+ NotmuchFilterDiscardNonTerms *filter = (NotmuchFilterDiscardNonTerms *) gmime_filter;
(*filter->real_filter)(gmime_filter, inbuf, inlen, prespace, outbuf, outlen, outprespace);
}
@@ -133,7 +118,7 @@ do_filter (const scanner_state_t states[],
GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
char **outbuf, size_t *outlen, size_t *outprespace)
{
- NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+ NotmuchFilterDiscardNonTerms *filter = (NotmuchFilterDiscardNonTerms *) gmime_filter;
register const char *inptr = inbuf;
const char *inend = inbuf + inlen;
char *outptr;
@@ -167,6 +152,25 @@ do_filter (const scanner_state_t states[],
*outbuf = gmime_filter->outbuf;
}
+/*
+ *
+ * A uuencoded portion is identified as beginning with a line
+ * matching:
+ *
+ * begin [0-7][0-7][0-7] .*
+ *
+ * After that detection, and beginning with the following line,
+ * characters will be discarded as long as the first character of each
+ * line begins with M and subsequent characters on the line are within
+ * the range of ASCII characters from ' ' to '`'.
+ *
+ * This is not a perfect UUencode filter. It's possible to have a
+ * message that will legitimately match that pattern, (so that some
+ * legitimate content is discarded). And for most UUencoded files, the
+ * final line of encoded data (the line not starting with M) will be
+ * indexed.
+ */
+
static void
filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace,
char **outbuf, size_t *outlen, size_t *outprespace)
@@ -210,7 +214,7 @@ filter_complete (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace
static void
filter_reset (GMimeFilter *gmime_filter)
{
- NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter;
+ NotmuchFilterDiscardNonTerms *filter = (NotmuchFilterDiscardNonTerms *) gmime_filter;
filter->state = 0;
}
@@ -218,32 +222,32 @@ filter_reset (GMimeFilter *gmime_filter)
/**
* notmuch_filter_discard_uuencode_new:
*
- * Returns: a new #NotmuchFilterDiscardUuencode filter.
+ * Returns: a new #NotmuchFilterDiscardNonTerms filter.
**/
static GMimeFilter *
-notmuch_filter_discard_uuencode_new (GMimeContentType *content_type)
+notmuch_filter_discard_non_terms_new (GMimeContentType *content_type)
{
static GType type = 0;
- NotmuchFilterDiscardUuencode *filter;
+ NotmuchFilterDiscardNonTerms *filter;
if (!type) {
static const GTypeInfo info = {
- sizeof (NotmuchFilterDiscardUuencodeClass),
+ sizeof (NotmuchFilterDiscardNonTermsClass),
NULL, /* base_class_init */
NULL, /* base_class_finalize */
- (GClassInitFunc) notmuch_filter_discard_uuencode_class_init,
+ (GClassInitFunc) notmuch_filter_discard_non_terms_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
- sizeof (NotmuchFilterDiscardUuencode),
+ sizeof (NotmuchFilterDiscardNonTerms),
0, /* n_preallocs */
NULL, /* instance_init */
NULL /* value_table */
};
- type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardUuencode", &info, (GTypeFlags) 0);
+ type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardNonTerms", &info, (GTypeFlags) 0);
}
- filter = (NotmuchFilterDiscardUuencode *) g_object_newv (type, 0, NULL);
+ filter = (NotmuchFilterDiscardNonTerms *) g_object_newv (type, 0, NULL);
filter->state = 0;
filter->content_type = content_type;
filter->real_filter = filter_filter_uuencode;
@@ -332,7 +336,7 @@ _index_mime_part (notmuch_message_t *message,
GMimeObject *part)
{
GMimeStream *stream, *filter;
- GMimeFilter *discard_uuencode_filter;
+ GMimeFilter *discard_non_terms_filter;
GMimeDataWrapper *wrapper;
GByteArray *byte_array;
GMimeContentDisposition *disposition;
@@ -422,10 +426,10 @@ _index_mime_part (notmuch_message_t *message,
g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (stream), FALSE);
filter = g_mime_stream_filter_new (stream);
- discard_uuencode_filter = notmuch_filter_discard_uuencode_new (content_type);
+ discard_non_terms_filter = notmuch_filter_discard_non_terms_new (content_type);
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filter),
- discard_uuencode_filter);
+ discard_non_terms_filter);
charset = g_mime_object_get_content_type_parameter (part, "charset");
if (charset) {
@@ -447,7 +451,7 @@ _index_mime_part (notmuch_message_t *message,
g_object_unref (stream);
g_object_unref (filter);
- g_object_unref (discard_uuencode_filter);
+ g_object_unref (discard_non_terms_filter);
g_byte_array_append (byte_array, (guint8 *) "\0", 1);
body = (char *) g_byte_array_free (byte_array, FALSE);
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] lib/index.cc: generalize filter state machine
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
` (3 preceding siblings ...)
2017-05-10 11:39 ` [PATCH 4/6] lib/index: generalize filter name David Bremner
@ 2017-05-10 11:39 ` David Bremner
2017-05-10 11:39 ` [PATCH 6/6] lib/index: add simple html filter David Bremner
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
To match things more complicated than fixed strings, we need states
with multiple out arrows.
---
lib/index.cc | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/index.cc b/lib/index.cc
index 3bb1ac1c..1b420b75 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -129,16 +129,23 @@ do_filter (const scanner_state_t states[],
g_mime_filter_set_size (gmime_filter, inlen, FALSE);
outptr = gmime_filter->outbuf;
+ next = filter->state;
while (inptr < inend) {
- if (*inptr >= states[filter->state].a &&
- *inptr <= states[filter->state].b)
- {
- next = states[filter->state].next_if_match;
- }
- else
- {
- next = states[filter->state].next_if_not_match;
- }
+ /* Each state is defined by a contiguous set of rows of the
+ * state table marked by a common value for '.state'. The
+ * state numbers must be equal to the index of the first row
+ * in a given state; thus the loop condition here looks for a
+ * jump to a first row of a state, which is a real transition
+ * in the underlying DFA.
+ */
+ do {
+ if (*inptr >= states[next].a && *inptr <= states[next].b) {
+ next = states[next].next_if_match;
+ } else {
+ next = states[next].next_if_not_match;
+ }
+
+ } while (next != states[next].state);
if (filter->state < first_skipping_state)
*outptr++ = *inptr;
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] lib/index: add simple html filter
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
` (4 preceding siblings ...)
2017-05-10 11:39 ` [PATCH 5/6] lib/index.cc: generalize filter state machine David Bremner
@ 2017-05-10 11:39 ` David Bremner
5 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2017-05-10 11:39 UTC (permalink / raw)
To: notmuch, notmuch
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-05-10 11:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-10 11:39 v2 of drop HTML tags when indexing David Bremner
2017-05-10 11:39 ` [PATCH 1/6] lib: add content type argument to uuencode filter David Bremner
2017-05-10 11:39 ` [PATCH 2/6] lib/index: Add another layer of indirection in filtering David Bremner
2017-05-10 11:39 ` [PATCH 3/6] lib/index: separate state table definition from scanner David Bremner
2017-05-10 11:39 ` [PATCH 4/6] lib/index: generalize filter name David Bremner
2017-05-10 11:39 ` [PATCH 5/6] lib/index.cc: generalize filter state machine David Bremner
2017-05-10 11:39 ` [PATCH 6/6] lib/index: add simple html filter David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).