From be8b4eb07e172b61982e8fb76d3861b17818e160 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Fri, 1 Aug 2008 02:26:16 +0200 Subject: [PATCH] Envelope: fixed one bug in the path parsing (printfs active). --- src/lib-sieve/ext-envelope.c | 81 +++++++++++++++++++++++++------- src/lib-sieve/sieve-address.c | 4 +- tests/extensions/envelope.svtest | 41 +++++++++++++++- 3 files changed, 104 insertions(+), 22 deletions(-) diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c index 05dd7089a..a7c183f03 100644 --- a/src/lib-sieve/ext-envelope.c +++ b/src/lib-sieve/ext-envelope.c @@ -129,23 +129,27 @@ struct sieve_envelope_part { (const struct sieve_runtime_env *renv); }; -const struct sieve_address *const *_from_part_get_addresses +static const struct sieve_address *const *_from_part_get_addresses (const struct sieve_runtime_env *renv); -const struct sieve_address *const *_to_part_get_addresses +static const char *const *_from_part_get_values (const struct sieve_runtime_env *renv); -const char *const *_auth_part_get_values +static const struct sieve_address *const *_to_part_get_addresses + (const struct sieve_runtime_env *renv); +static const char *const *_to_part_get_values + (const struct sieve_runtime_env *renv); +static const char *const *_auth_part_get_values (const struct sieve_runtime_env *renv); static const struct sieve_envelope_part _from_part = { "from", _from_part_get_addresses, - NULL + _from_part_get_values, }; static const struct sieve_envelope_part _to_part = { "to", _to_part_get_addresses, - NULL + _to_part_get_values, }; static const struct sieve_envelope_part _auth_part = { @@ -317,42 +321,83 @@ static bool ext_envelope_operation_dump * Interpretation */ -const struct sieve_address *const *_from_part_get_addresses +static const struct sieve_address *const *_from_part_get_addresses (const struct sieve_runtime_env *renv) { ARRAY_DEFINE(envelope_values, const struct sieve_address *); const struct sieve_address *address = sieve_address_parse_envelope_path(renv->msgdata->return_path); - t_array_init(&envelope_values, 2); - if ( address != NULL ) { + t_array_init(&envelope_values, 2); + + printf("FROM: %s@%s\n", address->local_part, address->domain); + array_append(&envelope_values, &address, 1); + + (void)array_append_space(&envelope_values); + return array_idx(&envelope_values, 0); + } + + return NULL; +} + +static const char *const *_from_part_get_values +(const struct sieve_runtime_env *renv) +{ + ARRAY_DEFINE(envelope_values, const char *); + + t_array_init(&envelope_values, 2); + + if ( renv->msgdata->return_path != NULL ) { + printf("FROM: %s\n", renv->msgdata->return_path); + array_append(&envelope_values, &renv->msgdata->return_path, 1); } - (void)array_append_space(&envelope_values); - return array_idx(&envelope_values, 0); + (void)array_append_space(&envelope_values); + + return array_idx(&envelope_values, 0); } -const struct sieve_address *const *_to_part_get_addresses -( const struct sieve_runtime_env *renv) +static const struct sieve_address *const *_to_part_get_addresses +(const struct sieve_runtime_env *renv) { ARRAY_DEFINE(envelope_values, const struct sieve_address *); const struct sieve_address *address = sieve_address_parse_envelope_path(renv->msgdata->to_address); - - t_array_init(&envelope_values, 2); if ( address != NULL && address->local_part != NULL ) { + t_array_init(&envelope_values, 2); + + printf("TO: %s@%s\n", address->local_part, address->domain); + array_append(&envelope_values, &address, 1); + + (void)array_append_space(&envelope_values); + return array_idx(&envelope_values, 0); } - (void)array_append_space(&envelope_values); - return array_idx(&envelope_values, 0); + return NULL; } -const char *const *_auth_part_get_values -( const struct sieve_runtime_env *renv) +static const char *const *_to_part_get_values +(const struct sieve_runtime_env *renv) +{ + ARRAY_DEFINE(envelope_values, const char *); + + t_array_init(&envelope_values, 2); + + if ( renv->msgdata->to_address != NULL ) + array_append(&envelope_values, &renv->msgdata->to_address, 1); + + (void)array_append_space(&envelope_values); + + return array_idx(&envelope_values, 0); +} + + +static const char *const *_auth_part_get_values +(const struct sieve_runtime_env *renv) { ARRAY_DEFINE(envelope_values, const char *); diff --git a/src/lib-sieve/sieve-address.c b/src/lib-sieve/sieve-address.c index e2bcb8282..95a5dc422 100644 --- a/src/lib-sieve/sieve-address.c +++ b/src/lib-sieve/sieve-address.c @@ -569,7 +569,7 @@ static int path_parse_mailbox(struct sieve_envelope_address_parser *parser) /* Mailbox = Local-part "@" Domain */ if ( (ret=path_parse_local_part(parser)) <= 0 ) - return ret; + return -1; if ( (ret=path_skip_white_space(parser)) <= 0 ) return -1; @@ -578,7 +578,7 @@ static int path_parse_mailbox(struct sieve_envelope_address_parser *parser) return -1; parser->data++; - if ( (ret=path_skip_white_space(parser)) <= 0 ) + if ( (ret=path_skip_white_space(parser)) <= 0 ) return -1; return path_parse_domain(parser, FALSE); diff --git a/tests/extensions/envelope.svtest b/tests/extensions/envelope.svtest index 9894c8e63..025a1e10e 100644 --- a/tests/extensions/envelope.svtest +++ b/tests/extensions/envelope.svtest @@ -2,8 +2,6 @@ require "vnd.dovecot.testsuite"; require "envelope"; -test_set "envelope.to" "stephan@rename-it.nl"; - test "Envelope - from empty" { /* Return_path: "" */ @@ -48,5 +46,44 @@ test "Envelope - from empty" { if envelope :all :is "from" "nico@vestingbar.nl" { test_fail "envelope test matches nonsense"; } + + /* Forward path: <> */ + + test_set "envelope.to" "<>"; + + if envelope :all :is "to" "" { + test_fail "successfully matched a <> forward path, which is wrong"; + } +} + +test "Envelope - invalid paths" { + /* Return_path: "hutsefluts" */ + + test_set "envelope.from" "hutsefluts"; + test_set "envelope.to" "knurft"; + + if not envelope :all :is "from" "hutsefluts" { + test_fail ":all address part mangled syntactically incorrect reverse path"; + } + + if envelope :localpart :is "from" "hutsefluts" { + test_fail ":localpart address part matched syntactically incorrect reverse path"; + } + + if envelope :domain :is "from" "hutsefluts" { + test_fail ":domain address part matched syntactically incorrect reverse path"; + } + + if not envelope :all :is "to" "knurft" { + test_fail ":all address part mangled syntactically incorrect forward path"; + } + + if envelope :localpart :is "to" "knurft" { + test_fail ":localpart address part matched syntactically incorrect forward path"; + } + + if envelope :domain :is "to" "knurft" { + test_fail ":domain address part matched syntactically incorrect forward path"; + } } -- GitLab