diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c | |
parent | Initial commit. (diff) | |
download | dovecot-upstream.tar.xz dovecot-upstream.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c')
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c b/pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c new file mode 100644 index 0000000..e0c9b54 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c @@ -0,0 +1,146 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extensions spamtest, spamtestplus and virustest + * ----------------------------------------------- + * + * Authors: Stephan Bosch + * Specification: RFC 5235 + * Implementation: full + * Status: testing + * + */ + +/* Configuration examples: + * + * # 1: X-Spam-Score: No, score=-3.2 + * + * sieve_spamtest_status_header = \ + * X-Spam-Score: [[:alnum:]]+, score=(-?[[:digit:]]+\.[[:digit:]]) + * sieve_spamtest_max_value = 5.0 + * + * # 2: X-Spam-Status: Yes + * + * sieve_spamtest_status_header = X-Spam-Status + * sieve_spamtest_status_type = yesno + * sieve_spamtest_max_value = Yes + * + * # 3: X-Spam-Score: sssssss + * sieve_spamtest_status_header = X-Spam-Score + * sieve_spamtest_status_type = strlen + * sieve_spamtest_max_value = 5 + * + * # 4: X-Spam-Score: status=3.2 required=5.0 + * + * sieve_spamtest_status_header = \ + * X-Spam-Score: score=(-?[[:digit:]]+\.[[:digit:]]).* + * sieve_spamtest_max_header = \ + * X-Spam-Score: score=-?[[:digit:]]+\.[[:digit:]] required=([[:digit:]]+\.[[:digit:]]) + * + * # 5: X-Virus-Scan: Found to be clean. + * + * sieve_virustest_status_header = \ + * X-Virus-Scan: Found to be (.+)\. + * sieve_virustest_status_type = text + * sieve_virustest_text_value1 = clean + * sieve_virustest_text_value5 = infected + */ + +#include "lib.h" +#include "array.h" + +#include "sieve-common.h" + +#include "sieve-extensions.h" +#include "sieve-commands.h" + +#include "sieve-validator.h" + +#include "ext-spamvirustest-common.h" + +/* + * Extensions + */ + +/* Spamtest */ + +static bool ext_spamvirustest_validator_load +(const struct sieve_extension *ext, struct sieve_validator *validator); + +const struct sieve_extension_def spamtest_extension = { + .name = "spamtest", + .load = ext_spamvirustest_load, + .unload = ext_spamvirustest_unload, + .validator_load = ext_spamvirustest_validator_load, + SIEVE_EXT_DEFINE_OPERATION(spamtest_operation) +}; + +const struct sieve_extension_def spamtestplus_extension = { + .name = "spamtestplus", + .load = ext_spamvirustest_load, + .unload = ext_spamvirustest_unload, + .validator_load = ext_spamvirustest_validator_load, + SIEVE_EXT_DEFINE_OPERATION(spamtest_operation) +}; + +const struct sieve_extension_def virustest_extension = { + .name = "virustest", + .load = ext_spamvirustest_load, + .unload = ext_spamvirustest_unload, + .validator_load = ext_spamvirustest_validator_load, + SIEVE_EXT_DEFINE_OPERATION(virustest_operation) +}; + +/* + * Implementation + */ + +static bool ext_spamtest_validator_check_conflict + (const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context, + struct sieve_ast_argument *require_arg, + const struct sieve_extension *ext_other, + bool required); + +const struct sieve_validator_extension spamtest_validator_extension = { + .ext = &spamtest_extension, + .check_conflict = ext_spamtest_validator_check_conflict +}; + +static bool ext_spamvirustest_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register new test */ + + if ( sieve_extension_is(ext, virustest_extension) ) { + sieve_validator_register_command(valdtr, ext, &virustest_test); + } else { + if ( sieve_extension_is(ext, spamtest_extension) ) { + /* Register validator extension to warn for duplicate */ + sieve_validator_extension_register + (valdtr, ext, &spamtest_validator_extension, NULL); + } + + sieve_validator_register_command(valdtr, ext, &spamtest_test); + } + + return TRUE; +} + +static bool ext_spamtest_validator_check_conflict +(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_validator *valdtr, void *context ATTR_UNUSED, + struct sieve_ast_argument *require_arg, + const struct sieve_extension *ext_other, + bool required ATTR_UNUSED) +{ + if ( sieve_extension_name_is(ext_other, "spamtestplus") ) { + sieve_argument_validate_warning(valdtr, require_arg, + "the spamtest and spamtestplus extensions should " + "not be specified at the same time"); + } + + return TRUE; +} + + |