dovecot-2.2-pigeonhole: lib-sieve: Adjusted to more SMTP API cha...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Apr 29 00:15:01 UTC 2014
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/439b1b2fe05d
changeset: 1849:439b1b2fe05d
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Apr 29 02:13:35 2014 +0200
description:
lib-sieve: Adjusted to more SMTP API changes in Dovecot.
SMTP API now supports adding multiple recipients to a single SMTP transaction. This makes enotify/notify more efficient, since only one message is actually sent.
diffstat:
src/lib-sieve/cmd-redirect.c | 6 +-
src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c | 50 ++++++++-----
src/lib-sieve/plugins/notify/cmd-notify.c | 78 ++++++++++++---------
src/lib-sieve/plugins/vacation/cmd-vacation.c | 7 +-
src/lib-sieve/sieve-actions.c | 11 +-
src/lib-sieve/sieve-smtp.c | 69 ++++++++++++++++---
src/lib-sieve/sieve-smtp.h | 20 +++-
src/lib-sieve/sieve-types.h | 14 ++-
src/plugins/lda-sieve/lda-sieve-plugin.c | 33 ++++++--
src/sieve-tools/sieve-filter.c | 2 -
src/sieve-tools/sieve-test.c | 40 +++++++---
src/testsuite/testsuite-script.c | 12 ++-
src/testsuite/testsuite-smtp.c | 60 +++++++++++-----
src/testsuite/testsuite-smtp.h | 12 +-
src/testsuite/testsuite.c | 6 +-
tests/deprecated/notify/mailto.svtest | 4 +-
16 files changed, 274 insertions(+), 150 deletions(-)
diffs (truncated from 754 to 300 lines):
diff -r c6c320f4918b -r 439b1b2fe05d src/lib-sieve/cmd-redirect.c
--- a/src/lib-sieve/cmd-redirect.c Mon Apr 28 22:08:47 2014 +0200
+++ b/src/lib-sieve/cmd-redirect.c Tue Apr 29 02:13:35 2014 +0200
@@ -321,7 +321,7 @@
struct istream *input;
struct ostream *output;
const char *error;
- void *smtp_handle;
+ struct sieve_smtp_context *sctx;
int ret;
/* Just to be sure */
@@ -335,7 +335,7 @@
return SIEVE_EXEC_TEMP_FAILURE;
/* Open SMTP transport */
- smtp_handle = sieve_smtp_open(senv, ctx->to_address, sender, &output);
+ sctx = sieve_smtp_start_single(senv, ctx->to_address, sender, &output);
/* Remove unwanted headers */
input = i_stream_create_header_filter
@@ -358,7 +358,7 @@
i_stream_unref(&input);
/* Close SMTP transport */
- if ( (ret=sieve_smtp_close(senv, smtp_handle, &error)) <= 0 ) {
+ if ( (ret=sieve_smtp_finish(sctx, &error)) <= 0 ) {
if ( ret < 0 ) {
sieve_result_global_log_error(aenv,
"failed to redirect message to <%s>: %s "
diff -r c6c320f4918b -r 439b1b2fe05d src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c
--- a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c Mon Apr 28 22:08:47 2014 +0200
+++ b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c Tue Apr 29 02:13:35 2014 +0200
@@ -385,10 +385,10 @@
const char *from = NULL, *from_smtp = NULL;
const char *subject = mtctx->uri->subject;
const char *body = mtctx->uri->body;
- string_t *to, *cc;
+ string_t *to, *cc, *all;
const struct uri_mailto_recipient *recipients;
const struct uri_mailto_header_field *headers;
- void *smtp_handle;
+ struct sieve_smtp_context *sctx;
struct ostream *output;
string_t *msg;
unsigned int count, i, hcount, h;
@@ -445,6 +445,7 @@
/* Compose To and Cc headers */
to = NULL;
cc = NULL;
+ all = t_str_new(256);
for ( i = 0; i < count; i++ ) {
if ( recipients[i].carbon_copy ) {
if ( cc == NULL ) {
@@ -463,6 +464,15 @@
str_append(to, recipients[i].full);
}
}
+ if ( i < 3) {
+ if ( i > 0 )
+ str_append(all, ", ");
+ str_append_c(all, '<');
+ str_append(all, str_sanitize(recipients[i].normalized, 256));
+ str_append_c(all, '>');
+ } else if (i == 3) {
+ str_printfa(all, ", ... (%u total)", count);
+ }
}
msg = t_str_new(512);
@@ -534,30 +544,28 @@
str_append(msg, "\r\nNotification of new message.\r\n");
}
+ sctx = sieve_smtp_start(senv, from_smtp);
+
/* Send message to all recipients */
- for ( i = 0; i < count; i++ ) {
- smtp_handle = sieve_smtp_open
- (senv, recipients[i].normalized, from_smtp, &output);
+ for ( i = 0; i < count; i++ )
+ sieve_smtp_add_rcpt(sctx, recipients[i].normalized);
- o_stream_send(output, str_data(msg), str_len(msg));
+ output = sieve_smtp_send(sctx);
+ o_stream_send(output, str_data(msg), str_len(msg));
- if ( (ret=sieve_smtp_close(senv, smtp_handle, &error)) <= 0 ) {
- if (ret < 0) {
- sieve_enotify_global_log_error(nenv,
- "failed to send mail notification to <%s>: %s (temporary failure)",
- str_sanitize(recipients[i].normalized, 256),
- str_sanitize(error, 512));
- } else {
- sieve_enotify_global_error(nenv,
- "failed to send mail notification to <%s>: %s (permanent failure)",
- str_sanitize(recipients[i].normalized, 256),
- str_sanitize(error, 512));
- }
+ if ( (ret=sieve_smtp_finish(sctx, &error)) <= 0 ) {
+ if (ret < 0) {
+ sieve_enotify_global_log_error(nenv,
+ "failed to send mail notification to %s: %s (temporary failure)",
+ str_c(all), str_sanitize(error, 512));
} else {
- sieve_enotify_global_info(nenv,
- "sent mail notification to <%s>",
- str_sanitize(recipients[i].normalized, 256));
+ sieve_enotify_global_error(nenv,
+ "failed to send mail notification to %s: %s (permanent failure)",
+ str_c(all), str_sanitize(error, 512));
}
+ } else {
+ sieve_enotify_global_info(nenv,
+ "sent mail notification to %s", str_c(all));
}
return TRUE;
diff -r c6c320f4918b -r 439b1b2fe05d src/lib-sieve/plugins/notify/cmd-notify.c
--- a/src/lib-sieve/plugins/notify/cmd-notify.c Mon Apr 28 22:08:47 2014 +0200
+++ b/src/lib-sieve/plugins/notify/cmd-notify.c Tue Apr 29 02:13:35 2014 +0200
@@ -689,12 +689,11 @@
{
const struct sieve_script_env *senv = aenv->scriptenv;
const struct ext_notify_recipient *recipients;
- void *smtp_handle;
+ struct sieve_smtp_context *sctx;
unsigned int count, i;
struct ostream *output;
- string_t *msg;
+ string_t *msg, *to, *all;
const char *outmsgid, *error;
- size_t hdr_size;
int ret;
/* Get recipients */
@@ -706,7 +705,7 @@
}
/* Just to be sure */
- if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) {
+ if ( !sieve_smtp_available(senv) ) {
sieve_result_global_warning(aenv,
"notify action has no means to send mail");
return TRUE;
@@ -753,45 +752,54 @@
rfc2822_header_write(msg, "Content-Transfer-Encoding", "7bit");
}
- hdr_size = str_len(msg);
+ outmsgid = sieve_message_get_new_id(aenv->svinst);
+ rfc2822_header_write(msg, "Message-ID", outmsgid);
- /* Send message to all recipients */
+ if ( sieve_message_get_sender(aenv->msgctx) != NULL )
+ sctx = sieve_smtp_start(senv, senv->postmaster_address);
+ else
+ sctx = sieve_smtp_start(senv, NULL);
+
+ /* Add all recipients (and compose To header field) */
+ to = t_str_new(128);
+ all = t_str_new(256);
for ( i = 0; i < count; i++ ) {
- if ( sieve_message_get_sender(aenv->msgctx) != NULL )
- smtp_handle = sieve_smtp_open
- (senv, recipients[i].normalized, senv->postmaster_address, &output);
- else
- smtp_handle = sieve_smtp_open
- (senv, recipients[i].normalized, NULL, &output);
+ sieve_smtp_add_rcpt(sctx, recipients[i].normalized);
+ if ( i > 0 )
+ str_append(to, ", ");
+ str_append(to, recipients[i].full);
+ if ( i < 3) {
+ if ( i > 0 )
+ str_append(all, ", ");
+ str_append_c(all, '<');
+ str_append(all, str_sanitize(recipients[i].normalized, 256));
+ str_append_c(all, '>');
+ } else if (i == 3) {
+ str_printfa(all, ", ... (%u total)", count);
+ }
+ }
- str_truncate(msg, hdr_size);
+ rfc2822_header_write(msg, "To", str_c(to));
- outmsgid = sieve_message_get_new_id(aenv->svinst);
- rfc2822_header_write(msg, "Message-ID", outmsgid);
- rfc2822_header_write(msg, "To", recipients[i].full);
+ /* Generate message body */
+ str_printfa(msg, "\r\n%s\r\n", act->message);
- /* Generate message body */
- str_printfa(msg, "\r\n%s\r\n", act->message);
+ output = sieve_smtp_send(sctx);
+ o_stream_send(output, str_data(msg), str_len(msg));
- o_stream_send(output, str_data(msg), str_len(msg));
-
- if ( (ret=sieve_smtp_close(senv, smtp_handle, &error)) <= 0 ) {
- if (ret < 0) {
- sieve_result_global_log_error(aenv,
- "failed to send mail notification to <%s>: %s (temporary failure)",
- str_sanitize(recipients[i].normalized, 256),
- str_sanitize(error, 512));
- } else {
- sieve_result_global_error(aenv,
- "failed to send mail notification to <%s>: %s (permanent failure)",
- str_sanitize(recipients[i].normalized, 256),
- str_sanitize(error, 512));
- }
+ if ( (ret=sieve_smtp_finish(sctx, &error)) <= 0 ) {
+ if (ret < 0) {
+ sieve_result_global_log_error(aenv,
+ "failed to send mail notification to %s: %s (temporary failure)",
+ str_c(all), str_sanitize(error, 512));
} else {
- sieve_result_global_log(aenv,
- "sent mail notification to <%s>",
- str_sanitize(recipients[i].normalized, 256));
+ sieve_result_global_error(aenv,
+ "failed to send mail notification to %s: %s (permanent failure)",
+ str_c(all), str_sanitize(error, 512));
}
+ } else {
+ sieve_result_global_log(aenv,
+ "sent mail notification to %s", str_c(all));
}
return TRUE;
diff -r c6c320f4918b -r 439b1b2fe05d src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Mon Apr 28 22:08:47 2014 +0200
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Apr 29 02:13:35 2014 +0200
@@ -901,7 +901,7 @@
{
const struct sieve_message_data *msgdata = aenv->msgdata;
const struct sieve_script_env *senv = aenv->scriptenv;
- void *smtp_handle;
+ struct sieve_smtp_context *sctx;
struct ostream *output;
string_t *msg;
const char *const *headers;
@@ -933,7 +933,8 @@
/* Open smtp session */
- smtp_handle = sieve_smtp_open(senv, reply_to, smtp_from, &output);
+ sctx = sieve_smtp_start_single(senv, reply_to, smtp_from, &output);
+
outmsgid = sieve_message_get_new_id(aenv->svinst);
/* Produce a proper reply */
@@ -992,7 +993,7 @@
o_stream_send(output, str_data(msg), str_len(msg));
/* Close smtp session */
- if ( (ret=sieve_smtp_close(senv, smtp_handle, &error)) <= 0 ) {
+ if ( (ret=sieve_smtp_finish(sctx, &error)) <= 0 ) {
if ( ret < 0 ) {
sieve_result_global_log_error(aenv,
"failed to send vacation response to <%s>: %s (temporary error)",
diff -r c6c320f4918b -r 439b1b2fe05d src/lib-sieve/sieve-actions.c
--- a/src/lib-sieve/sieve-actions.c Mon Apr 28 22:08:47 2014 +0200
+++ b/src/lib-sieve/sieve-actions.c Tue Apr 29 02:13:35 2014 +0200
@@ -783,20 +783,20 @@
const struct sieve_message_data *msgdata = aenv->msgdata;
struct istream *input;
struct ostream *output;
- void *smtp_handle;
+ struct sieve_smtp_context *sctx;
const char *new_msgid, *boundary, *header, *error;
string_t *hdr;
int ret;
+ sctx = sieve_smtp_start_single(senv, sender, NULL, &output);
+
/* Just to be sure */
- if ( !sieve_smtp_available(senv) ) {
+ if ( sctx == NULL ) {
sieve_result_global_warning
(aenv, "reject action has no means to send mail");
return TRUE;
}
- smtp_handle = sieve_smtp_open(senv, sender, NULL, &output);
-
new_msgid = sieve_message_get_new_id(svinst);
boundary = t_strdup_printf("%s/%s", my_pid, svinst->hostname);
@@ -874,7 +874,7 @@
str_printfa(hdr, "\r\n\r\n--%s--\r\n", boundary);
o_stream_send(output, str_data(hdr), str_len(hdr));
- if ( (ret=sieve_smtp_close(senv, smtp_handle, &error)) <= 0 ) {
+ if ( (ret=sieve_smtp_finish(sctx, &error)) <= 0 ) {
if ( ret < 0 ) {
sieve_result_global_log_error(aenv,
"failed to send rejection message to <%s>: %s "
@@ -885,7 +885,6 @@
More information about the dovecot-cvs
mailing list