diff --git a/src/lib-sieve/ext-envelope.c b/src/lib-sieve/ext-envelope.c index 05dd7089a8db74f66de980b9c306c99671c70df9..a7c183f033a491edcc3fbeb2055c2472d84382c5 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 e2bcb8282906e363900a85c936dc1e402d276af2..95a5dc42225b1e074cc9cb2136bf33521a6e0bc8 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 9894c8e638e95bd9f84cc608e9c25bd4a010e49f..025a1e10e8a526580c596d44f24e3545ad2b6f17 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"; + } }