dovecot-2.2-pigeonhole: lib-sieve: enotify extension: mailto met...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Wed Oct 21 21:35:06 UTC 2015
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/400be376fe02
changeset: 2121:400be376fe02
user: Stephan Bosch <stephan at rename-it.nl>
date: Wed Oct 21 23:31:06 2015 +0200
description:
lib-sieve: enotify extension: mailto method: Implemented sieve_notify_mailto_envelope_from setting.
This allows setting the MAIL FROM of the SMTP envelope for the notification e-mails.
The syntax is identical to the sieve_redirect_envelope_from setting.
diffstat:
src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c | 100 ++++++++++++++++-
tests/extensions/enotify/mailto.svtest | 118 ++++++++++++++++++++-
2 files changed, 211 insertions(+), 7 deletions(-)
diffs (284 lines):
diff -r 637307bdbdf2 -r 400be376fe02 src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c
--- a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c Wed Oct 21 23:27:36 2015 +0200
+++ b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c Wed Oct 21 23:31:06 2015 +0200
@@ -31,6 +31,7 @@
#include "sieve-address.h"
#include "sieve-message.h"
#include "sieve-smtp.h"
+#include "sieve-settings.h"
#include "sieve-ext-enotify.h"
@@ -47,9 +48,22 @@
#define NTFY_MAILTO_MAX_SUBJECT 256
/*
+ * Mailto notification configuration
+ */
+
+struct ntfy_mailto_config {
+ struct sieve_mail_sender envelope_from;
+};
+
+/*
* Mailto notification method
*/
+static bool ntfy_mailto_load
+ (const struct sieve_enotify_method *nmth, void **context);
+static void ntfy_mailto_unload
+ (const struct sieve_enotify_method *nmth);
+
static bool ntfy_mailto_compile_check_uri
(const struct sieve_enotify_env *nenv, const char *uri, const char *uri_body);
static bool ntfy_mailto_compile_check_from
@@ -80,7 +94,8 @@
const struct sieve_enotify_method_def mailto_notify = {
"mailto",
- NULL, NULL,
+ ntfy_mailto_load,
+ ntfy_mailto_unload,
ntfy_mailto_compile_check_uri,
NULL,
ntfy_mailto_compile_check_from,
@@ -133,6 +148,45 @@
};
/*
+ * Method registration
+ */
+
+static bool ntfy_mailto_load
+(const struct sieve_enotify_method *nmth, void **context)
+{
+ struct sieve_instance *svinst = nmth->svinst;
+ struct ntfy_mailto_config *config;
+
+ if ( *context != NULL ) {
+ ntfy_mailto_unload(nmth);
+ }
+
+ config = i_new(struct ntfy_mailto_config, 1);
+
+ if (!sieve_setting_get_mail_sender_value
+ (svinst, default_pool, "sieve_notify_mailto_envelope_from",
+ &config->envelope_from)) {
+ config->envelope_from.source =
+ SIEVE_MAIL_SENDER_SOURCE_DEFAULT;
+ }
+
+ *context = (void *) config;
+
+ return TRUE;
+}
+
+static void ntfy_mailto_unload
+(const struct sieve_enotify_method *nmth)
+{
+ struct ntfy_mailto_config *config =
+ (struct ntfy_mailto_config *) nmth->context;
+ char *address = (char *)config->envelope_from.address;
+
+ i_free(address);
+ i_free(config);
+}
+
+/*
* Validation
*/
@@ -382,6 +436,10 @@
const struct sieve_script_env *senv = nenv->scriptenv;
struct ntfy_mailto_context *mtctx =
(struct ntfy_mailto_context *) nact->method_context;
+ struct ntfy_mailto_config *mth_config =
+ (struct ntfy_mailto_config *)nenv->method->context;
+ struct sieve_mail_sender *env_from =
+ &mth_config->envelope_from;
const char *from = NULL, *from_smtp = NULL;
const char *subject = mtctx->uri->subject;
const char *body = mtctx->uri->body;
@@ -417,12 +475,42 @@
from = nact->from;
}
- /* Determine SMTP from address */
- if ( sieve_message_get_sender(nenv->msgctx) != NULL ) {
- if ( mtctx->from_normalized == NULL ) {
+ /* Determine which sender to use
+
+ From RFC 5436, Section 2.3:
+
+ The ":from" tag overrides the default sender of the notification
+ message. "Sender", here, refers to the value used in the [RFC5322]
+ "From" header. Implementations MAY also use this value in the
+ [RFC5321] "MAIL FROM" command (the "envelope sender"), or they may
+ prefer to establish a mailbox that receives bounces from notification
+ messages.
+ */
+ from_smtp = sieve_message_get_sender(nenv->msgctx);
+ if ( from_smtp != NULL ) {
+ switch ( env_from->source ) {
+ case SIEVE_MAIL_SENDER_SOURCE_SENDER:
+ break;
+ case SIEVE_MAIL_SENDER_SOURCE_RECIPIENT:
+ from_smtp = sieve_message_get_final_recipient(nenv->msgctx);
+ break;
+ case SIEVE_MAIL_SENDER_SOURCE_ORIG_RECIPIENT:
+ from_smtp = sieve_message_get_orig_recipient(nenv->msgctx);
+ break;
+ case SIEVE_MAIL_SENDER_SOURCE_EXPLICIT:
+ from_smtp = env_from->address;
+ break;
+ case SIEVE_MAIL_SENDER_SOURCE_DEFAULT:
+ if ( mtctx->from_normalized != NULL ) {
+ from_smtp = mtctx->from_normalized;
+ break;
+ }
+ /* Fall through */
+ case SIEVE_MAIL_SENDER_SOURCE_POSTMASTER:
from_smtp = senv->postmaster_address;
- } else {
- from_smtp = mtctx->from_normalized;
+ break;
+ default:
+ break;
}
}
diff -r 637307bdbdf2 -r 400be376fe02 tests/extensions/enotify/mailto.svtest
--- a/tests/extensions/enotify/mailto.svtest Wed Oct 21 23:27:36 2015 +0200
+++ b/tests/extensions/enotify/mailto.svtest Wed Oct 21 23:31:06 2015 +0200
@@ -294,7 +294,7 @@
}
if not envelope :is "to" "stephan at example.org" {
- test_fail "envelope sender set incorrectly";
+ test_fail "envelope recipient set incorrectly";
}
test_message :smtp 1;
@@ -304,6 +304,122 @@
}
if not envelope :is "to" "timo at example.com" {
+ test_fail "envelope recipient set incorrectly";
+ }
+}
+
+/*
+ * Envelope config - sender
+ */
+
+test_set "message" text:
+From: stephan at example.org
+To: nico at frop.example.org
+Subject: Frop!
+
+Klutsefluts.
+.
+;
+
+test_set "envelope.from" "sirius at example.org";
+test_set "envelope.to" "bertus at frop.example.org";
+
+test_config_set "sieve_notify_mailto_envelope_from"
+ "sender";
+test_config_reload :extension "enotify";
+test_result_reset;
+
+test "Envelope config - sender" {
+ notify :from "nico at frop.example.org"
+ "mailto:stephan at example.org?cc=timo at example.com";
+
+ if not test_result_execute {
+ test_fail "failed to execute notify";
+ }
+
+ test_message :smtp 0;
+
+ if not header :is "from" "nico at frop.example.org" {
+ test_fail "from set incorrectly";
+ }
+
+ if not envelope :is "from" "sirius at example.org" {
test_fail "envelope sender set incorrectly";
}
+
+ if not envelope :is "to" "stephan at example.org" {
+ test_fail "envelope recipient set incorrectly";
+ }
+
+ test_message :smtp 1;
+
+ if not header :is "from" "nico at frop.example.org" {
+ test_fail "from set incorrectly";
+ }
+
+ if not envelope :is "from" "sirius at example.org" {
+ test_fail "envelope sender set incorrectly";
+ }
+
+ if not envelope :is "to" "timo at example.com" {
+ test_fail "envelope recipient set incorrectly";
+ }
}
+
+/*
+ * Envelope config - recipient
+ */
+
+test_set "message" text:
+From: stephan at example.org
+To: nico at frop.example.org
+Subject: Frop!
+
+Klutsefluts.
+.
+;
+
+test_set "envelope.from" "sirius at example.org";
+test_set "envelope.to" "bertus at frop.example.org";
+
+test_config_set "sieve_notify_mailto_envelope_from"
+ "recipient";
+test_config_reload :extension "enotify";
+test_result_reset;
+
+test "Envelope config - recipient" {
+ notify :from "nico at frop.example.org"
+ "mailto:stephan at example.org?cc=timo at example.com";
+
+ if not test_result_execute {
+ test_fail "failed to execute notify";
+ }
+
+ test_message :smtp 0;
+
+ if not header :is "from" "nico at frop.example.org" {
+ test_fail "from set incorrectly";
+ }
+
+ if not envelope :is "from" "bertus at frop.example.org" {
+ test_fail "envelope sender set incorrectly";
+ }
+
+ if not envelope :is "to" "stephan at example.org" {
+ test_fail "envelope recipient set incorrectly";
+ }
+
+ test_message :smtp 1;
+
+ if not header :is "from" "nico at frop.example.org" {
+ test_fail "from set incorrectly";
+ }
+
+ if not envelope :is "from" "bertus at frop.example.org" {
+ test_fail "envelope sender set incorrectly";
+ }
+
+ if not envelope :is "to" "timo at example.com" {
+ test_fail "envelope recipient set incorrectly";
+ }
+}
More information about the dovecot-cvs
mailing list