diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-06 15:48:39 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-06 15:48:39 +0200 |
commit | cab2fd5c0479d16a3dcd746c98de8be771a8963d (patch) | |
tree | 22ec3d11998b5d25e6ce08a55fd6fdfc0c12cb09 | |
parent | df608ed0cfb5f0db57d1ff97eb208ceb46f06e17 (diff) | |
download | mailutils-cab2fd5c0479d16a3dcd746c98de8be771a8963d.tar.gz mailutils-cab2fd5c0479d16a3dcd746c98de8be771a8963d.tar.bz2 |
Use glob API in sieve
* libmu_sieve/comparator.c: Use mu_glob_compile instead of fnmatch.
m--------- | gint | 0 | ||||
-rw-r--r-- | gnulib.modules | 2 | ||||
-rw-r--r-- | libmu_sieve/comparator.c | 26 |
3 files changed, 24 insertions, 4 deletions
diff --git a/gint b/gint -Subproject 42f4712085b40173eaea58e14b1a579291a6fe3 +Subproject fd86bf7d44b0c970771830692ae7491447ebe8b diff --git a/gnulib.modules b/gnulib.modules index b672acc25..4e7fcd20a 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -1,7 +1,7 @@ # List of gnulib modules needed for GNU mailutils. # A module name per line. Empty lines and comments are ignored. -# FIXME: fnmatch, regex and glob are used by libmailutils... +# FIXME: regex and glob are used by libmailutils... autobuild crypto/des diff --git a/libmu_sieve/comparator.c b/libmu_sieve/comparator.c index 591b4d4a8..5e10c83bd 100644 --- a/libmu_sieve/comparator.c +++ b/libmu_sieve/comparator.c @@ -25,7 +25,6 @@ #include <unistd.h> #include <string.h> #include <sieve-priv.h> -#include <fnmatch.h> #include <regex.h> #include <mailutils/cctype.h> #include <mailutils/cstr.h> @@ -102,6 +101,25 @@ compile_pattern (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, int flags) pattern->rx = preg; } +static void +compile_wildcard (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, + int flags) +{ + int rc; + regex_t *preg; + + if (pattern->rx) + return; + preg = mu_sieve_malloc (mach, sizeof (*preg)); + rc = mu_glob_compile (preg, pattern->orig, flags); + if (rc) + { + mu_sieve_error (mach, _("can't compile pattern")); + mu_sieve_abort (mach); + } + pattern->rx = preg; +} + static int comp_false (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, const char *text) @@ -263,7 +281,8 @@ static int i_octet_matches (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, const char *text) { - return fnmatch (pattern->orig, text, 0) == 0; + compile_wildcard (mach, pattern, 0); + return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0; } static int @@ -300,7 +319,8 @@ static int i_ascii_casemap_matches (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, const char *text) { - return fnmatch (pattern->orig, text, FNM_CASEFOLD) == 0; + compile_wildcard (mach, pattern, MU_GLOBF_ICASE); + return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0; } static int |