Skip to content
Snippets Groups Projects
Commit 7dab1255 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Enotify/Mailto: prevented single recipient from receiving multiple...

Enotify/Mailto: prevented single recipient from receiving multiple notifications on the same message.
parent 5ef4fda9
No related branches found
No related tags found
No related merge requests found
Current: Current:
* Finish enotify extension: * Finish enotify extension:
- Mailto: prevent multiple notifications to a single recipient
- Cleanup method API. - Cleanup method API.
- Regorous testing - Regorous testing
* Test new multiscript support extensively. * Test new multiscript support extensively.
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
* Configuration * Configuration
*/ */
#define NTFY_MAILTO_MAX_RECIPIENTS 4 #define NTFY_MAILTO_MAX_RECIPIENTS 8
#define NTFY_MAILTO_MAX_HEADERS 16 #define NTFY_MAILTO_MAX_HEADERS 16
#define NTFY_MAILTO_MAX_SUBJECT 256 #define NTFY_MAILTO_MAX_SUBJECT 256
...@@ -344,7 +344,7 @@ static bool _uri_parse_recipients ...@@ -344,7 +344,7 @@ static bool _uri_parse_recipients
str_append_c(to, ch); str_append_c(to, ch);
} }
} else { } else {
if ( *p == ':' || *p == ';' || !_is_qchar(*p) ) { if ( *p == ':' || *p == ';' || *p == ',' || !_is_qchar(*p) ) {
_uri_parse_error _uri_parse_error
(nlog, "invalid character '%c' in 'to' part", *p); (nlog, "invalid character '%c' in 'to' part", *p);
return FALSE; return FALSE;
...@@ -758,12 +758,52 @@ static bool ntfy_mailto_runtime_check_operands ...@@ -758,12 +758,52 @@ static bool ntfy_mailto_runtime_check_operands
*/ */
static int ntfy_mailto_action_check_duplicates static int ntfy_mailto_action_check_duplicates
(const struct sieve_enotify_log *nlog, void *method_ctx1, void *method_ctx2, (const struct sieve_enotify_log *nlog ATTR_UNUSED,
const char *dupl_location) void *method_ctx1, void *method_ctx2,
const char *dupl_location ATTR_UNUSED)
{ {
/* FIXME: kill duplicate recipients */ struct ntfy_mailto_context *mt_new =
(struct ntfy_mailto_context *) method_ctx1;
struct ntfy_mailto_context *mt_old =
(struct ntfy_mailto_context *) method_ctx2;
const struct ntfy_mailto_recipient *new_rcpts, *old_rcpts;
unsigned int new_count, old_count, i, j;
unsigned int del_start = 0, del_len = 0;
new_rcpts = array_get(&mt_new->recipients, &new_count);
old_rcpts = array_get(&mt_old->recipients, &old_count);
for ( i = 0; i < new_count; i++ ) {
for ( j = 0; j < old_count; j++ ) {
if ( strcmp(new_rcpts[i].normalized, old_rcpts[j].normalized) == 0 )
break;
}
if ( j == old_count ) {
/* Not duplicate */
if ( del_len > 0 ) {
/* Perform pending deletion */
array_delete(&mt_new->recipients, del_start, del_len);
/* Make sure the loop integrity is maintained */
i -= del_len;
new_rcpts = array_get(&mt_new->recipients, &new_count);
}
del_len = 0;
} else {
/* Mark deletion */
if ( del_len == 0 )
del_start = i;
del_len++;
}
}
return 0; /* Perform pernding deletion */
if ( del_len > 0 ) {
array_delete(&mt_new->recipients, del_start, del_len);
}
return ( array_count(&mt_new->recipients) > 0 ? 0 : 1 );
} }
/* /*
...@@ -814,6 +854,8 @@ static void ntfy_mailto_action_print ...@@ -814,6 +854,8 @@ static void ntfy_mailto_action_print
if ( mtctx->body != NULL ) if ( mtctx->body != NULL )
sieve_result_printf(rpenv, " => body : \n--\n%s\n--\n\n", sieve_result_printf(rpenv, " => body : \n--\n%s\n--\n\n",
mtctx->body); mtctx->body);
sieve_result_printf(rpenv, "\n");
} }
/* /*
......
require "vnd.dovecot.testsuite"; require "vnd.dovecot.testsuite";
require "relational";
/* /*
* Execution testing (currently just meant to trigger any segfaults) * Execution testing (currently just meant to trigger any segfaults)
...@@ -87,6 +89,10 @@ test "Duplicate recipients" { ...@@ -87,6 +89,10 @@ test "Duplicate recipients" {
test_fail "script execute failed"; test_fail "script execute failed";
} }
if test_result :count "ne" "2" {
test_fail "second notify action was discarded entirely";
}
if not test_result_execute { if not test_result_execute {
test_fail "result execute failed"; test_fail "result execute failed";
} }
......
require "enotify"; require "enotify";
notify :message "Incoming stupidity." "mailto:stephan@rename-it.nl"; notify :message "Incoming stupidity." "mailto:stephan@rename-it.nl%2cstephan@drunksnipers.com%2cidiot@rename-it.nl";
notify :message "There it is." "mailto:tss@iki.fi,stephan@rename-it.nl"; notify :message "There it is." "mailto:tss@iki.fi%2cstephan@rename-it.nl%2cidiot@rename-it.nl%2cnico@vestingbar.nl%2cstephan@drunksnipers.com";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.