dovecot-2.2: lda/lmtp: If mail delivery fails with tempfail, don...

dovecot at dovecot.org dovecot at dovecot.org
Sat Jun 1 17:17:57 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/fa87cd91a11a
changeset: 16448:fa87cd91a11a
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Jun 01 17:17:47 2013 +0300
description:
lda/lmtp: If mail delivery fails with tempfail, don't fallback to saving to INBOX.

diffstat:

 src/lda/main.c             |   9 ++++++---
 src/lib-lda/mail-deliver.c |  18 ++++++++++++++++++
 src/lib-lda/mail-deliver.h |   4 ++++
 src/lmtp/commands.c        |  18 +++++++++++-------
 4 files changed, 39 insertions(+), 10 deletions(-)

diffs (114 lines):

diff -r 74875424373d -r fa87cd91a11a src/lda/main.c
--- a/src/lda/main.c	Sat Jun 01 17:11:55 2013 +0300
+++ b/src/lda/main.c	Sat Jun 01 17:17:47 2013 +0300
@@ -436,14 +436,17 @@
 	lda_set_dest_addr(&ctx, user, destaddr_source);
 
 	if (mail_deliver(&ctx, &storage) < 0) {
-		if (storage == NULL) {
+		if (storage != NULL) {
+			errstr = mail_storage_get_last_error(storage, &error);
+		} else if (ctx.tempfail_error != NULL) {
+			errstr = ctx.tempfail_error;
+			error = MAIL_ERROR_TEMP;
+		} else {
 			/* This shouldn't happen */
 			i_error("BUG: Saving failed to unknown storage");
 			return EX_TEMPFAIL;
 		}
 
-		errstr = mail_storage_get_last_error(storage, &error);
-
 		if (stderr_rejection) {
 			/* write to stderr also for tempfails so that MTA
 			   can log the reason if it wants to. */
diff -r 74875424373d -r fa87cd91a11a src/lib-lda/mail-deliver.c
--- a/src/lib-lda/mail-deliver.c	Sat Jun 01 17:11:55 2013 +0300
+++ b/src/lib-lda/mail-deliver.c	Sat Jun 01 17:17:47 2013 +0300
@@ -371,6 +371,20 @@
 			       count++, ctx->set->hostname);
 }
 
+static bool mail_deliver_is_tempfailed(struct mail_deliver_context *ctx,
+				       struct mail_storage *storage)
+{
+	enum mail_error error;
+
+	if (ctx->tempfail_error != NULL)
+		return TRUE;
+	if (storage != NULL) {
+		(void)mail_storage_get_last_error(storage, &error);
+		return error == MAIL_ERROR_TEMP;
+	}
+	return FALSE;
+}
+
 int mail_deliver(struct mail_deliver_context *ctx,
 		 struct mail_storage **storage_r)
 {
@@ -390,12 +404,16 @@
 			ret = 0;
 		}
 		duplicate_deinit(&ctx->dup_ctx);
+		if (ret < 0 && mail_deliver_is_tempfailed(ctx, *storage_r))
+			return -1;
 	}
 
 	if (ret < 0 && !ctx->tried_default_save) {
 		/* plugins didn't handle this. save into the default mailbox. */
 		ret = mail_deliver_save(ctx, ctx->dest_mailbox_name, 0, NULL,
 					storage_r);
+		if (ret < 0 && mail_deliver_is_tempfailed(ctx, *storage_r))
+			return -1;
 	}
 	if (ret < 0 && strcasecmp(ctx->dest_mailbox_name, "INBOX") != 0) {
 		/* still didn't work. try once more to save it
diff -r 74875424373d -r fa87cd91a11a src/lib-lda/mail-deliver.h
--- a/src/lib-lda/mail-deliver.h	Sat Jun 01 17:11:55 2013 +0300
+++ b/src/lib-lda/mail-deliver.h	Sat Jun 01 17:17:47 2013 +0300
@@ -48,6 +48,10 @@
 	/* mail_deliver_log() caches the var expand table here */
 	struct var_expand_table *var_expand_table;
 
+	/* Error message for a temporary failure. This is necessary only when
+	   there is no storage where to get the error message from. */
+	const char *tempfail_error;
+
 	bool tried_default_save;
 	bool saved_mail;
 	bool save_dest_mail;
diff -r 74875424373d -r fa87cd91a11a src/lmtp/commands.c
--- a/src/lmtp/commands.c	Sat Jun 01 17:11:55 2013 +0300
+++ b/src/lmtp/commands.c	Sat Jun 01 17:17:47 2013 +0300
@@ -694,13 +694,7 @@
 		client_send_line(client, "250 2.0.0 <%s> %s Saved",
 				 rcpt->address, client->state.session_id);
 		ret = 0;
-	} else if (storage == NULL) {
-		/* This shouldn't happen */
-		i_error("BUG: Saving failed to unknown storage");
-		client_send_line(client, ERRSTR_TEMP_MAILBOX_FAIL,
-				 rcpt->address);
-		ret = -1;
-	} else {
+	} else if (storage != NULL) {
 		error = mail_storage_get_last_error(storage, &mail_error);
 		if (mail_error == MAIL_ERROR_NOSPACE) {
 			client_send_line(client, "%s <%s> %s",
@@ -712,6 +706,16 @@
 					 rcpt->address, error);
 		}
 		ret = -1;
+	} else if (dctx.tempfail_error != NULL) {
+		client_send_line(client, "451 4.2.0 <%s> %s",
+				 rcpt->address, dctx.tempfail_error);
+		ret = -1;
+	} else {
+		/* This shouldn't happen */
+		i_error("BUG: Saving failed to unknown storage");
+		client_send_line(client, ERRSTR_TEMP_MAILBOX_FAIL,
+				 rcpt->address);
+		ret = -1;
 	}
 	return ret;
 }


More information about the dovecot-cvs mailing list