[PATCH 3/7] lib/index: Add another layer of indirection in filtering
David Bremner
david at tethera.net
Wed Mar 22 04:23:02 PDT 2017
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
More information about the notmuch
mailing list