From 35f7d17342a33a93bdea972eef6bccf92a19003d Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Fri, 6 Mar 2015 18:59:46 +0100
Subject: [PATCH] lda sieve plugin: Started using smtp_client_deinit_timeout()
 to give a session timeout.

---
 src/lib-sieve/sieve-smtp.c               |  6 +++---
 src/lib-sieve/sieve-types.h              | 11 ++++++++---
 src/plugins/lda-sieve/lda-sieve-plugin.c | 15 +++++++++++----
 src/sieve-tools/sieve-test.c             | 10 +++++++---
 src/testsuite/testsuite-smtp.c           | 16 +++++++---------
 src/testsuite/testsuite-smtp.h           | 11 ++++++++---
 6 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/src/lib-sieve/sieve-smtp.c b/src/lib-sieve/sieve-smtp.c
index a4b7cdc63..28923100c 100644
--- a/src/lib-sieve/sieve-smtp.c
+++ b/src/lib-sieve/sieve-smtp.c
@@ -42,7 +42,7 @@ void sieve_smtp_add_rcpt
 (struct sieve_smtp_context *sctx, const char *address)
 {
 	i_assert(!sctx->sent);
-	sctx->senv->smtp_add_rcpt(sctx->handle, address);
+	sctx->senv->smtp_add_rcpt(sctx->senv, sctx->handle, address);
 }
 
 struct ostream *sieve_smtp_send
@@ -51,7 +51,7 @@ struct ostream *sieve_smtp_send
 	i_assert(!sctx->sent);
 	sctx->sent = TRUE;
 
-	return sctx->senv->smtp_send(sctx->handle);
+	return sctx->senv->smtp_send(sctx->senv, sctx->handle);
 }
 
 struct sieve_smtp_context *sieve_smtp_start_single
@@ -74,6 +74,6 @@ int sieve_smtp_finish
 	void *handle = sctx->handle;
 
 	i_free(sctx);
-	return senv->smtp_finish(handle, error_r);
+	return senv->smtp_finish(senv, handle, error_r);
 }
 
diff --git a/src/lib-sieve/sieve-types.h b/src/lib-sieve/sieve-types.h
index ddcebca7d..0b6b803c1 100644
--- a/src/lib-sieve/sieve-types.h
+++ b/src/lib-sieve/sieve-types.h
@@ -193,12 +193,17 @@ struct sieve_script_env {
 	void *(*smtp_start)
 		(const struct sieve_script_env *senv, const char *return_path);
 	/* Add a new recipient */
-	void (*smtp_add_rcpt)	(void *handle, const char *address);
+	void (*smtp_add_rcpt)	
+		(const struct sieve_script_env *senv, void *handle,
+			const char *address);
 	/* Get an output stream where the message can be written to. The recipients
 	   must already be added before calling this. */
-	struct ostream *(*smtp_send)(void *handle);
+	struct ostream *(*smtp_send)
+		(const struct sieve_script_env *senv, void *handle);
 	/* Returns 1 on success, 0 on permanent failure, -1 on temporary failure. */
-	int (*smtp_finish)(void *handle, const char **error_r);
+	int (*smtp_finish)
+		(const struct sieve_script_env *senv, void *handle,
+			const char **error_r);
 
 	/* Interface for marking and checking duplicates */
 	int (*duplicate_check)
diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c
index 52023a35b..1187a40f1 100644
--- a/src/plugins/lda-sieve/lda-sieve-plugin.c
+++ b/src/plugins/lda-sieve/lda-sieve-plugin.c
@@ -77,14 +77,17 @@ static void *lda_sieve_smtp_start
 	return (void *)smtp_client_init(dctx->set, return_path);
 }
 
-static void lda_sieve_smtp_add_rcpt(void *handle, const char *address)
+static void lda_sieve_smtp_add_rcpt
+(const struct sieve_script_env *senv ATTR_UNUSED, void *handle,
+	const char *address)
 {
 	struct smtp_client *smtp_client = (struct smtp_client *) handle;
 
 	smtp_client_add_rcpt(smtp_client, address);
 }
 
-static struct ostream *lda_sieve_smtp_send(void *handle)
+static struct ostream *lda_sieve_smtp_send
+(const struct sieve_script_env *senv ATTR_UNUSED, void *handle)
 {
 	struct smtp_client *smtp_client = (struct smtp_client *) handle;
 
@@ -92,11 +95,15 @@ static struct ostream *lda_sieve_smtp_send(void *handle)
 }
 
 static int lda_sieve_smtp_finish
-(void *handle, const char **error_r)
+(const struct sieve_script_env *senv, void *handle,
+	const char **error_r)
 {
+	struct mail_deliver_context *dctx =
+		(struct mail_deliver_context *) senv->script_context;
 	struct smtp_client *smtp_client = (struct smtp_client *) handle;
 
-	return smtp_client_deinit(smtp_client, error_r);
+	return smtp_client_deinit_timeout
+		(smtp_client, dctx->timeout_secs, error_r);
 }
 
 static int lda_sieve_reject_mail
diff --git a/src/sieve-tools/sieve-test.c b/src/sieve-tools/sieve-test.c
index 84e02aca7..09a08715b 100644
--- a/src/sieve-tools/sieve-test.c
+++ b/src/sieve-tools/sieve-test.c
@@ -70,12 +70,15 @@ static void *sieve_smtp_start
 }
 
 static void sieve_smtp_add_rcpt
-(void *handle ATTR_UNUSED, const char *address)
+(const struct sieve_script_env *senv ATTR_UNUSED,
+	void *handle ATTR_UNUSED, const char *address)
 {
 	printf("\nRECIPIENT: %s\n", address);
 }
 
-static struct ostream *sieve_smtp_send(void *handle)
+static struct ostream *sieve_smtp_send
+(const struct sieve_script_env *senv ATTR_UNUSED,
+	void *handle)
 {
 	printf("START MESSAGE:\n");
 
@@ -83,7 +86,8 @@ static struct ostream *sieve_smtp_send(void *handle)
 }
 
 static int sieve_smtp_finish
-(void *handle, const char **error_r ATTR_UNUSED)
+(const struct sieve_script_env *senv ATTR_UNUSED,
+	void *handle, const char **error_r ATTR_UNUSED)
 {
 	struct ostream *output = (struct ostream *)handle;
 
diff --git a/src/testsuite/testsuite-smtp.c b/src/testsuite/testsuite-smtp.c
index 6696f711f..e8fee7260 100644
--- a/src/testsuite/testsuite-smtp.c
+++ b/src/testsuite/testsuite-smtp.c
@@ -74,12 +74,6 @@ struct testsuite_smtp {
 	struct ostream *output;
 };
 
-void testsuite_smtp_add_rcpt(void *handle, const char *address);
-struct ostream *testsuite_smtp_send(void *handle);
-int testsuite_smtp_finish
-	(void *handle, const char **error_r);
-
-
 void *testsuite_smtp_start
 (const struct sieve_script_env *senv ATTR_UNUSED, const char *return_path)
 {
@@ -102,7 +96,9 @@ void *testsuite_smtp_start
 	return (void *) smtp;
 }
 
-void testsuite_smtp_add_rcpt(void *handle, const char *address)
+void testsuite_smtp_add_rcpt
+(const struct sieve_script_env *senv ATTR_UNUSED,
+	void *handle, const char *address)
 {
 	struct testsuite_smtp *smtp = (struct testsuite_smtp *) handle;
 	struct testsuite_smtp_message *msg;
@@ -114,7 +110,8 @@ void testsuite_smtp_add_rcpt(void *handle, const char *address)
 	msg->envelope_to = p_strdup(testsuite_smtp_pool, address);
 }
 
-struct ostream *testsuite_smtp_send(void *handle)
+struct ostream *testsuite_smtp_send
+(const struct sieve_script_env *senv ATTR_UNUSED, void *handle)
 {
 	struct testsuite_smtp *smtp = (struct testsuite_smtp *) handle;
 
@@ -122,7 +119,8 @@ struct ostream *testsuite_smtp_send(void *handle)
 }
 
 int testsuite_smtp_finish
-(void *handle,	const char **error_r ATTR_UNUSED)
+(const struct sieve_script_env *senv ATTR_UNUSED,
+	void *handle, const char **error_r ATTR_UNUSED)
 {
 	struct testsuite_smtp *smtp = (struct testsuite_smtp *) handle;
 
diff --git a/src/testsuite/testsuite-smtp.h b/src/testsuite/testsuite-smtp.h
index 62b472528..dd0bf7303 100644
--- a/src/testsuite/testsuite-smtp.h
+++ b/src/testsuite/testsuite-smtp.h
@@ -15,10 +15,15 @@ void testsuite_smtp_reset(void);
 void *testsuite_smtp_start
 	(const struct sieve_script_env *senv ATTR_UNUSED,
 		const char *return_path);
-void testsuite_smtp_add_rcpt(void *handle, const char *address);
-struct ostream *testsuite_smtp_send(void *handle);
+void testsuite_smtp_add_rcpt
+	(const struct sieve_script_env *senv ATTR_UNUSED,
+		void *handle, const char *address);
+struct ostream *testsuite_smtp_send
+	(const struct sieve_script_env *senv ATTR_UNUSED,
+		void *handle);
 int testsuite_smtp_finish
-	(void *handle, const char **error_r);
+	(const struct sieve_script_env *senv ATTR_UNUSED,
+		void *handle, const char **error_r);
 
 /*
  * Access
-- 
GitLab