diff --git a/Makefile.am b/Makefile.am index a761fde6a42fe6314cc84e58207acadb6a872d52..c5794b9a7d82c26b831664ed8a524ec1ff585f75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ if BUILD_ENOTIFY ENOTIFY_TESTS = \ tests/extensions/enotify/basic.svtest \ tests/extensions/enotify/encodeurl.svtest \ + tests/extensions/enotify/errors.svtest \ tests/extensions/enotify/execute.svtest endif diff --git a/src/lib-sieve/plugins/enotify/ntfy-mailto.c b/src/lib-sieve/plugins/enotify/ntfy-mailto.c index 7ce3873b56a9157c0aa56580b92e665140ba9f34..6657f388a8d2226b1c3a86f9fb600876e3a0eab1 100644 --- a/src/lib-sieve/plugins/enotify/ntfy-mailto.c +++ b/src/lib-sieve/plugins/enotify/ntfy-mailto.c @@ -49,7 +49,7 @@ const struct sieve_enotify_method mailto_notify = { /* FIXME: much of this implementation will be common to other URI schemes. This * should be merged into a common implementation. */ - + static inline int _decode_hex_digit(char digit) { switch ( digit ) { @@ -114,6 +114,8 @@ static bool _uri_parse_recipients recipient = str_c(to); /* Verify recipient */ + + // FIXME .... /* Add recipient to the list */ if ( recipients_r != NULL ) { @@ -141,7 +143,7 @@ static bool _uri_parse_recipients /* Verify recipient */ - // .... + // FIXME .... if ( recipients_r != NULL ) { /* Add recipient to the list */ @@ -192,11 +194,19 @@ static bool _uri_parse_headers } if ( *p != '\0' ) p++; + /* Verify field name */ + if ( !rfc2822_header_field_name_verify(str_c(field), str_len(field)) ) { + *error_r = "invalid header field name"; + return FALSE; + } + + /* Add new header field to array and assign its name */ if ( headers_r != NULL ) { hdrf = array_append_space(&headers); hdrf->name = t_strdup(str_c(field)); } + /* Reset for body */ str_truncate(field, 0); /* Parse field body */ @@ -215,6 +225,12 @@ static bool _uri_parse_headers } if ( *p != '\0' ) p++; + /* Verify field body */ + + // FIXME .... + + /* Assign field body */ + if ( headers_r != NULL ) { hdrf->body = t_strdup(str_c(field)); str_truncate(field, 0); diff --git a/tests/extensions/enotify/errors.svtest b/tests/extensions/enotify/errors.svtest new file mode 100644 index 0000000000000000000000000000000000000000..40fb6d1eb72ca05d256a9f60baa8afeb7b31554b --- /dev/null +++ b/tests/extensions/enotify/errors.svtest @@ -0,0 +1,26 @@ +require "vnd.dovecot.testsuite"; +require "comparator-i;ascii-numeric"; +require "relational"; + +require "enotify"; + + +test "Invalid URL (FIXME: count only)" { + if test_compile "errors/url.sieve" { + test_fail "compile should have failed"; + } + + if not test_error :count "eq" :comparator "i;ascii-numeric" "2" { + test_fail "wrong number of errors reported"; + } +} + +test "Invalid mailto URL (FIXME: count only)" { + if test_compile "errors/url-mailto.sieve" { + test_fail "compile should have failed"; + } + + if not test_error :count "eq" :comparator "i;ascii-numeric" "2" { + test_fail "wrong number of errors reported"; + } +} diff --git a/tests/extensions/enotify/errors/url-mailto.sieve b/tests/extensions/enotify/errors/url-mailto.sieve new file mode 100644 index 0000000000000000000000000000000000000000..5a4d32f6c40bbf0276fbacd5bfeb0f4cb59f8f5b --- /dev/null +++ b/tests/extensions/enotify/errors/url-mailto.sieve @@ -0,0 +1,5 @@ +require "enotify"; + +# 1: Invalid header name +notify "mailto:stephan@rename-it.nl?header:=frop"; + diff --git a/tests/extensions/enotify/errors/url.sieve b/tests/extensions/enotify/errors/url.sieve new file mode 100644 index 0000000000000000000000000000000000000000..06e86d764f6d384ce86443addb3580132d7b6c23 --- /dev/null +++ b/tests/extensions/enotify/errors/url.sieve @@ -0,0 +1,5 @@ +require "enotify"; + +# 1: Invalid url scheme +notify "snailto:stephan@rename-it.nl"; +