dovecot-1.2-sieve: Spamtest and virustest extensions: finished c...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Mon Jan 25 19:42:38 EET 2010
details: http://hg.rename-it.nl/dovecot-1.2-sieve/rev/b873b2ae075a
changeset: 1229:b873b2ae075a
user: Stephan Bosch <stephan at rename-it.nl>
date: Mon Jan 25 18:22:07 2010 +0100
description:
Spamtest and virustest extensions: finished configuration.
diffstat:
Makefile.am | 4 +-
src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c | 409 ++++++++-----
src/lib-sieve/plugins/spamvirustest/ext-spamvirustest.c | 9 +-
tests/extensions/spamvirustest/spamtest.svtest | 10 +-
tests/extensions/spamvirustest/spamtestplus.svtest | 136 ++++
tests/extensions/spamvirustest/virustest.svtest | 143 +++++
6 files changed, 536 insertions(+), 175 deletions(-)
diffs (truncated from 922 to 300 lines):
diff -r bd23b606958d -r b873b2ae075a Makefile.am
--- a/Makefile.am Mon Jan 25 11:19:18 2010 +0100
+++ b/Makefile.am Mon Jan 25 18:22:07 2010 +0100
@@ -45,7 +45,9 @@
if BUILD_UNFINISHED
test_unfinished = \
- tests/extensions/spamvirustest/spamtest.svtest
+ tests/extensions/spamvirustest/spamtest.svtest \
+ tests/extensions/spamvirustest/virustest.svtest \
+ tests/extensions/spamvirustest/spamtestplus.svtest
else
test_unfinished =
endif
diff -r bd23b606958d -r b873b2ae075a src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c
--- a/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c Mon Jan 25 11:19:18 2010 +0100
+++ b/src/lib-sieve/plugins/spamvirustest/ext-spamvirustest-common.c Mon Jan 25 18:22:07 2010 +0100
@@ -2,11 +2,13 @@
*/
#include "lib.h"
+#include "strfuncs.h"
#include "sieve-common.h"
#include "sieve-settings.h"
#include "sieve-error.h"
#include "sieve-extensions.h"
+#include "sieve-message.h"
#include "sieve-interpreter.h"
#include "ext-spamvirustest-common.h"
@@ -22,7 +24,7 @@
enum ext_spamvirustest_status_type {
EXT_SPAMVIRUSTEST_STATUS_TYPE_VALUE,
EXT_SPAMVIRUSTEST_STATUS_TYPE_STRLEN,
- EXT_SPAMVIRUSTEST_STATUS_TYPE_YESNO,
+ EXT_SPAMVIRUSTEST_STATUS_TYPE_TEXT,
};
struct ext_spamvirustest_header_spec {
@@ -34,13 +36,16 @@
struct ext_spamvirustest_data {
pool_t pool;
+ int reload;
+
struct ext_spamvirustest_header_spec status_header;
struct ext_spamvirustest_header_spec max_header;
enum ext_spamvirustest_status_type status_type;
float max_value;
- const char *yes_string;
+
+ const char *text_values[11];
};
/*
@@ -237,74 +242,22 @@
* Extension initialization
*/
-static bool ext_spamvirustest_config_load
-(struct ext_spamvirustest_data *ext_data, const char *ext_name,
- const char *status_header, const char *max_header,
- const char *status_type, const char *max_value)
+bool ext_spamvirustest_load
+(const struct sieve_extension *ext, void **context)
{
+ struct ext_spamvirustest_data *ext_data =
+ (struct ext_spamvirustest_data *) *context;
+ struct sieve_instance *svinst = ext->svinst;
+ const char *ext_name, *status_header, *max_header, *status_type,
+ *max_value;
+ enum ext_spamvirustest_status_type type;
const char *error;
-
- if ( !ext_spamvirustest_header_spec_parse
- (&ext_data->status_header, ext_data->pool, status_header, &error) ) {
- sieve_sys_error("%s: invalid status header specification "
- "'%s': %s", ext_name, status_header, error);
- return FALSE;
- }
-
- if ( max_header != NULL && !ext_spamvirustest_header_spec_parse
- (&ext_data->max_header, ext_data->pool, max_header, &error) ) {
- sieve_sys_error("%s: invalid max header specification "
- "'%s': %s", ext_name, max_header, error);
- return FALSE;
- }
-
- if ( status_type == NULL || strcmp(status_type, "value") == 0 ) {
- ext_data->status_type = EXT_SPAMVIRUSTEST_STATUS_TYPE_VALUE;
- } else if ( strcmp(status_type, "strlen") == 0 ) {
- ext_data->status_type = EXT_SPAMVIRUSTEST_STATUS_TYPE_STRLEN;
- } else if ( strcmp(status_type, "yesno") == 0 ) {
- ext_data->status_type = EXT_SPAMVIRUSTEST_STATUS_TYPE_YESNO;
- } else {
- sieve_sys_error("%s: invalid status type '%s'", ext_name, status_type);
- return FALSE;
- }
-
- if ( max_value != NULL ) {
- switch ( ext_data->status_type ) {
- case EXT_SPAMVIRUSTEST_STATUS_TYPE_STRLEN:
- case EXT_SPAMVIRUSTEST_STATUS_TYPE_VALUE:
- if ( !ext_spamvirustest_parse_decimal_value
- (max_value, &ext_data->max_value, &error) ) {
- sieve_sys_error("%s: invalid max value specification "
- "'%s': %s", ext_name, max_value, error);
- return FALSE;
- }
- break;
- case EXT_SPAMVIRUSTEST_STATUS_TYPE_YESNO:
- ext_data->yes_string = p_strdup(ext_data->pool, max_value);
- ext_data->max_value = 1;
- break;
- }
- }
-
- return TRUE;
-}
-
-static void ext_spamvirustest_config_free(struct ext_spamvirustest_data *ext_data)
-{
- ext_spamvirustest_header_spec_free(&ext_data->status_header);
- ext_spamvirustest_header_spec_free(&ext_data->max_header);
-}
-
-bool ext_spamvirustest_load(const struct sieve_extension *ext, void **context)
-{
- struct sieve_instance *svinst = ext->svinst;
- struct ext_spamvirustest_data *ext_data;
- const char *status_header, *max_header, *status_type, *max_value;
- const char *ext_name;
pool_t pool;
+ bool result = TRUE;
+ int reload = 0;
if ( *context != NULL ) {
+ reload = ext_data->reload + 1;
ext_spamvirustest_unload(ext);
*context = NULL;
}
@@ -325,49 +278,120 @@
status_header = sieve_setting_get
(svinst, t_strconcat("sieve_", ext_name, "_status_header", NULL));
+ status_type = sieve_setting_get
+ (svinst, t_strconcat("sieve_", ext_name, "_status_type", NULL));
max_header = sieve_setting_get
(svinst, t_strconcat("sieve_", ext_name, "_max_header", NULL));
- status_type = sieve_setting_get
- (svinst, t_strconcat("sieve_", ext_name, "_status_type", NULL));
max_value = sieve_setting_get
(svinst, t_strconcat("sieve_", ext_name, "_max_value", NULL));
- /* Verify settings */
+ /* Base configuration */
if ( status_header == NULL ) {
return TRUE;
}
- if ( max_header != NULL && max_value != NULL ) {
- sieve_sys_error("%s: sieve_%s_max_header and sieve_%s_max_value "
- "cannot both be configured", ext_name, ext_name, ext_name);
- return TRUE;
+ if ( status_type == NULL || strcmp(status_type, "value") == 0 ) {
+ type = EXT_SPAMVIRUSTEST_STATUS_TYPE_VALUE;
+ } else if ( strcmp(status_type, "strlen") == 0 ) {
+ type = EXT_SPAMVIRUSTEST_STATUS_TYPE_STRLEN;
+ } else if ( strcmp(status_type, "text") == 0 ) {
+ type = EXT_SPAMVIRUSTEST_STATUS_TYPE_TEXT;
+ } else {
+ sieve_sys_error("%s: invalid status type '%s'", ext_name, status_type);
+ return FALSE;
}
- if ( max_header == NULL && max_value == NULL ) {
- sieve_sys_error("%s: none of sieve_%s_max_header or sieve_%s_max_value "
- "is configured", ext_name, ext_name, ext_name);
- return TRUE;
+ /* Verify settings */
+
+ if ( type != EXT_SPAMVIRUSTEST_STATUS_TYPE_TEXT ) {
+
+ if ( max_header != NULL && max_value != NULL ) {
+ sieve_sys_error("%s: sieve_%s_max_header and sieve_%s_max_value "
+ "cannot both be configured", ext_name, ext_name, ext_name);
+ return TRUE;
+ }
+
+ if ( max_header == NULL && max_value == NULL ) {
+ sieve_sys_error("%s: none of sieve_%s_max_header or sieve_%s_max_value "
+ "is configured", ext_name, ext_name, ext_name);
+ return TRUE;
+ }
+ } else {
+ if ( max_header != NULL ) {
+ sieve_sys_warning("%s: setting sieve_%s_max_header has no meaning "
+ "for sieve_%s_status_type=text", ext_name, ext_name, ext_name);
+ }
+
+ if ( max_value != NULL ) {
+ sieve_sys_warning("%s: setting sieve_%s_max_value has no meaning "
+ "for sieve_%s_status_type=text", ext_name, ext_name, ext_name);
+ }
}
- /* Pre-process configuration */
-
pool = pool_alloconly_create("spamvirustest_data", 512);
ext_data = p_new(pool, struct ext_spamvirustest_data, 1);
ext_data->pool = pool;
+ ext_data->reload = reload;
+ ext_data->status_type = type;
- if ( !ext_spamvirustest_config_load
- (ext_data, ext_name, status_header, max_header, status_type, max_value) ) {
+ if ( !ext_spamvirustest_header_spec_parse
+ (&ext_data->status_header, ext_data->pool, status_header, &error) ) {
+ sieve_sys_error("%s: invalid status header specification "
+ "'%s': %s", ext_name, status_header, error);
+ result = FALSE;
+ }
+
+ if ( result ) {
+ if ( type != EXT_SPAMVIRUSTEST_STATUS_TYPE_TEXT ) {
+ /* Parse max header */
+
+ if ( max_header != NULL && !ext_spamvirustest_header_spec_parse
+ (&ext_data->max_header, ext_data->pool, max_header, &error) ) {
+ sieve_sys_error("%s: invalid max header specification "
+ "'%s': %s", ext_name, max_header, error);
+ result = FALSE;
+ }
+
+ /* Parse max value */
+
+ if ( result && max_value != NULL ) {
+ if ( !ext_spamvirustest_parse_decimal_value
+ (max_value, &ext_data->max_value, &error) ) {
+ sieve_sys_error("%s: invalid max value specification "
+ "'%s': %s", ext_name, max_value, error);
+ result = FALSE;
+ }
+ }
+
+ } else {
+ unsigned int i, max_text;
+
+ max_text = ( sieve_extension_is(ext, virustest_extension) ? 5 : 10 );
+
+ /* Get text values */
+ for ( i = 0; i <= max_text; i++ ) {
+ const char *value = sieve_setting_get
+ (svinst, t_strdup_printf("sieve_%s_text_value%d", ext_name, i));
+
+ if ( value != NULL && *value != '\0' )
+ ext_data->text_values[i] = p_strdup(ext_data->pool, value);
+ }
+
+ ext_data->max_value = 1;
+ }
+ }
+
+ if ( result ) {
+ *context = (void *) ext_data;
+ } else {
sieve_sys_warning("%s: extension not configured, "
"tests will always match against \"0\"", ext_name);
- ext_spamvirustest_config_free(ext_data);
- pool_unref(&pool);
+ ext_spamvirustest_unload(ext);
*context = NULL;
- } else {
- *context = (void *) ext_data;
}
- return TRUE;
+ return result;
}
void ext_spamvirustest_unload(const struct sieve_extension *ext)
@@ -378,97 +402,134 @@
if ( ext_data != NULL ) {
ext_spamvirustest_header_spec_free(&ext_data->status_header);
ext_spamvirustest_header_spec_free(&ext_data->max_header);
-
pool_unref(&ext_data->pool);
}
}
/*
- * Score extraction
+ * Runtime
*/
+struct ext_spamvirustest_message_context {
More information about the dovecot-cvs
mailing list