dovecot-2.2-pigeonhole: lib-sieve: vacation extension: Added sup...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Mon Sep 23 23:03:05 EEST 2013
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/4924724b7f4f
changeset: 1807:4924724b7f4f
user: Stephan Bosch <stephan at rename-it.nl>
date: Mon Sep 23 22:01:38 2013 +0200
description:
lib-sieve: vacation extension: Added support for sending vacation messages with an actual sender.
Use sieve_vacation_send_from_recipient to enable this behavior.
Documentation in doc/extensions/vacation.txt is updated.
diffstat:
doc/extensions/vacation.txt | 8 +
src/lib-sieve/plugins/vacation/cmd-vacation.c | 20 ++-
src/lib-sieve/plugins/vacation/ext-vacation-common.c | 8 +-
src/lib-sieve/plugins/vacation/ext-vacation-common.h | 1 +
tests/extensions/vacation/message.svtest | 90 ++++++++++++++++++++
5 files changed, 119 insertions(+), 8 deletions(-)
diffs (259 lines):
diff -r 9b78ef1584c6 -r 4924724b7f4f doc/extensions/vacation.txt
--- a/doc/extensions/vacation.txt Mon Sep 23 20:58:02 2013 +0200
+++ b/doc/extensions/vacation.txt Mon Sep 23 22:01:38 2013 +0200
@@ -73,6 +73,14 @@
Sieve standards and can cause vacation replies to be sent for messages not
directly addressed at the recipient.
+sieve_vacation_send_from_recipient = no
+ This setting determines whether vacation messages are sent with the SMTP MAIL
+ FROM envelope address set to the recipient address of the Sieve script owner.
+ Normally this is set to <>, which is the default as recommended in the
+ specification. This is meant to prevent mail loops. However, there are
+ situations for which a valid sender address is required and this setting can
+ be used to accommodate for those.
+
Invalid values for the settings above will make the Sieve interpreter log a
warning and revert to the default values.
diff -r 9b78ef1584c6 -r 4924724b7f4f src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Mon Sep 23 20:58:02 2013 +0200
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Mon Sep 23 22:01:38 2013 +0200
@@ -897,16 +897,15 @@
static bool act_vacation_send
(const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx,
- const char *reply_to, const char *reply_from)
+ const char *reply_to, const char *reply_from, const char *smtp_from)
{
const struct sieve_message_data *msgdata = aenv->msgdata;
const struct sieve_script_env *senv = aenv->scriptenv;
void *smtp_handle;
struct ostream *output;
string_t *msg;
- const char *outmsgid;
const char *const *headers;
- const char *subject;
+ const char *outmsgid, *subject;
int ret;
/* Check smpt functions just to be sure */
@@ -934,7 +933,7 @@
/* Open smtp session */
- smtp_handle = sieve_smtp_open(senv, reply_to, NULL, &output);
+ smtp_handle = sieve_smtp_open(senv, reply_to, smtp_from, &output);
outmsgid = sieve_message_get_new_id(aenv->svinst);
/* Produce a proper reply */
@@ -1035,7 +1034,7 @@
const char *recipient = sieve_message_get_final_recipient(aenv->msgctx);
const char *const *hdsp;
const char *const *headers;
- const char *reply_from = NULL, *orig_recipient = NULL;
+ const char *reply_from = NULL, *orig_recipient = NULL, *smtp_from = NULL;
bool result;
/* Is the recipient unset?
@@ -1162,6 +1161,7 @@
/* Final recipient directly listed in headers? */
if ( _contains_my_address(headers, recipient) ) {
reply_from = recipient;
+ smtp_from = recipient;
break;
}
@@ -1169,6 +1169,7 @@
if ( orig_recipient != NULL &&
_contains_my_address(headers, orig_recipient) ) {
reply_from = orig_recipient;
+ smtp_from = orig_recipient;
break;
}
@@ -1178,8 +1179,12 @@
const char * const *my_address = ctx->addresses;
while ( !found && *my_address != NULL ) {
- if ( (found=_contains_my_address(headers, *my_address)) )
+ if ( (found=_contains_my_address(headers, *my_address)) ) {
reply_from = *my_address;
+ /* Avoid letting user determine SMTP sender directly */
+ smtp_from =
+ ( orig_recipient == NULL ? recipient : orig_recipient );
+ }
my_address++;
}
@@ -1220,7 +1225,8 @@
/* Send the message */
T_BEGIN {
- result = act_vacation_send(aenv, ctx, sender, reply_from);
+ result = act_vacation_send(aenv, ctx, sender, reply_from,
+ (config->send_from_recipient ? smtp_from : NULL));
} T_END;
if ( result ) {
diff -r 9b78ef1584c6 -r 4924724b7f4f src/lib-sieve/plugins/vacation/ext-vacation-common.c
--- a/src/lib-sieve/plugins/vacation/ext-vacation-common.c Mon Sep 23 20:58:02 2013 +0200
+++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.c Mon Sep 23 22:01:38 2013 +0200
@@ -16,7 +16,7 @@
struct sieve_instance *svinst = ext->svinst;
struct ext_vacation_config *config;
sieve_number_t min_period, max_period, default_period;
- bool use_original_recipient, dont_check_recipient;
+ bool use_original_recipient, dont_check_recipient, send_from_recipient;
if ( *context != NULL ) {
ext_vacation_unload(ext);
@@ -60,12 +60,18 @@
dont_check_recipient = FALSE;
}
+ if ( !sieve_setting_get_bool_value
+ (svinst, "sieve_vacation_send_from_recipient", &send_from_recipient) ) {
+ send_from_recipient = FALSE;
+ }
+
config = i_new(struct ext_vacation_config, 1);
config->min_period = min_period;
config->max_period = max_period;
config->default_period = default_period;
config->use_original_recipient = use_original_recipient;
config->dont_check_recipient = dont_check_recipient;
+ config->send_from_recipient = send_from_recipient;
*context = (void *) config;
diff -r 9b78ef1584c6 -r 4924724b7f4f src/lib-sieve/plugins/vacation/ext-vacation-common.h
--- a/src/lib-sieve/plugins/vacation/ext-vacation-common.h Mon Sep 23 20:58:02 2013 +0200
+++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.h Mon Sep 23 22:01:38 2013 +0200
@@ -20,6 +20,7 @@
unsigned int default_period;
bool use_original_recipient;
bool dont_check_recipient;
+ bool send_from_recipient;
};
/*
diff -r 9b78ef1584c6 -r 4924724b7f4f tests/extensions/vacation/message.svtest
--- a/tests/extensions/vacation/message.svtest Mon Sep 23 20:58:02 2013 +0200
+++ b/tests/extensions/vacation/message.svtest Mon Sep 23 22:01:38 2013 +0200
@@ -1,8 +1,13 @@
require "vnd.dovecot.testsuite";
require "vacation";
require "variables";
+require "envelope";
require "body";
+/*
+ * References
+ */
+
test_set "message" text:
From: stephan at example.org
Subject: frop
@@ -43,12 +48,20 @@
}
}
+/*
+ * In-Reply-To
+ */
+
test "In-Reply-To" {
if not header :is "in-reply-to" "<432df324 at example.org>" {
test_fail "in-reply-to header set incorrectly";
}
}
+/*
+ * Variables
+ */
+
test_result_reset;
test_set "message" text:
@@ -88,3 +101,80 @@
test_fail "message not set properly";
}
}
+
+/*
+ * NULL Sender
+ */
+
+test_result_reset;
+
+test_set "message" text:
+From: stephan at example.org
+Subject: frop
+Message-ID: <432df324 at example.org>
+To: nico at frop.example.org
+
+Frop
+.
+;
+
+test_set "envelope.to" "nico at frop.example.org";
+
+test "NULL Sender" {
+ set "message" "I am not in today!";
+ set "subject" "Out of office";
+ set "from" "user at example.com";
+
+ vacation :from "${from}" :subject "${subject}" "${message}";
+
+ if not test_result_execute {
+ test_fail "execution of result failed";
+ }
+
+ test_message :smtp 0;
+
+ if not envelope :is "from" "" {
+ if envelope :matches "from" "*" {}
+ test_fail "envelope sender not set properly: ${1}";
+ }
+}
+
+/*
+ * Send from recipient
+ */
+
+test_result_reset;
+
+test_set "message" text:
+From: stephan at example.org
+Subject: frop
+Message-ID: <432df324 at example.org>
+To: nico at frop.example.org
+
+Frop
+.
+;
+
+test_set "envelope.to" "nico at frop.example.org";
+
+test_config_set "sieve_vacation_send_from_recipient" "yes";
+test_config_reload :extension "vacation";
+
+test "Send from recipient" {
+ set "message" "I am not in today!";
+ set "subject" "Out of office";
+ set "from" "user at example.com";
+
+ vacation :from "${from}" :subject "${subject}" "${message}";
+
+ if not test_result_execute {
+ test_fail "execution of result failed";
+ }
+
+ test_message :smtp 0;
+
+ if not envelope "from" "nico at frop.example.org" {
+ test_fail "envelope sender not set properly";
+ }
+}
+
More information about the dovecot-cvs
mailing list