diff --git a/include/struct.h b/include/struct.h index 94adec1d7..2f2c52011 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1116,6 +1116,7 @@ struct crule_context Client *client; /**< Client that is being processed (can be NULL) */ const char *text; /**< The input string, if any (can be NULL) */ const char *destination; /**< Destination of the message, like '#xyz' for spamfilter (can be NULL, eg for 'u') */ + ClientContext *clictx; /**< Client context (can be NULL) */ }; /** Evaluation function for a connection rule. */ diff --git a/src/modules/crule.c b/src/modules/crule.c index 5dce7a568..13a68102d 100644 --- a/src/modules/crule.c +++ b/src/modules/crule.c @@ -144,6 +144,7 @@ static int crule_match_country(crule_context *, int, void **); static int crule_match_asn(crule_context *, int, void **); static int crule_match_certfp(crule_context *, int, void **); static int crule_match_realname(crule_context *, int, void **); +static int crule_unicode_count(crule_context *, int, void **); /* parsing function prototypes - local! */ static int crule_gettoken(crule_token *next_tokp, const char **str); @@ -204,6 +205,7 @@ struct crule_funclistent crule_funclist[] = { {"match_asn", 1, crule_match_asn}, {"match_certfp", 1, crule_match_certfp}, {"match_realname", 1, crule_match_realname}, + {"unicode_count", 1, crule_unicode_count}, {"", 0, NULL} /* this must be here to mark end of list */ }; @@ -550,6 +552,20 @@ static int crule_match_realname(crule_context *context, int numargs, void *crule return 0; } +static int crule_unicode_count(crule_context *context, int numargs, void *crulearg[]) +{ + const char *arg = (char *)crulearg[0]; + + if (context && context->clictx && context->clictx->textanalysis) + { + int i = utf8_get_block_number(arg); + if (i < 0) + return -1; /* Block name not found */ + return context->clictx->textanalysis->unicode_blockmap[i]; + } + return 0; +} + /** Evaluate a connection rule. * @param[in] rule Rule to evalute. * @return Non-zero if the rule allows the connection, zero otherwise. diff --git a/src/modules/tkl.c b/src/modules/tkl.c index 53e77e06a..304db10d4 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -5516,6 +5516,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char context.client = client; context.text = str_in; context.destination = destination; + context.clictx = clictx; /* Client exempt from spamfilter checking? * Let's check that early: going through elines is likely faster than running the regex(es). @@ -5678,6 +5679,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char context.client = client; context.text = str_in; context.destination = destination; + context.clictx = clictx; if (!crule_eval(&context, tkl->ptr.spamfilter->rule)) continue;