dovecot-2.1: lib-storage: Fixed mail_storage_copy() error handling.

dovecot at dovecot.org dovecot at dovecot.org
Fri Sep 16 16:59:32 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/858298eb101f
changeset: 13475:858298eb101f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 08 11:50:23 2011 +0300
description:
lib-storage: Fixed mail_storage_copy() error handling.

diffstat:

 src/lib-storage/mail-copy.c |  31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diffs (62 lines):

diff -r 1903d5fd7e76 -r 858298eb101f src/lib-storage/mail-copy.c
--- a/src/lib-storage/mail-copy.c	Thu Sep 08 11:16:55 2011 +0300
+++ b/src/lib-storage/mail-copy.c	Thu Sep 08 11:50:23 2011 +0300
@@ -5,6 +5,21 @@
 #include "mail-storage-private.h"
 #include "mail-copy.h"
 
+static void
+mail_copy_set_failed(struct mail_save_context *ctx, struct mail *mail,
+		     const char *func)
+{
+	const char *errstr;
+	enum mail_error error;
+
+	if (ctx->transaction->box->storage == mail->box->storage)
+		return;
+
+	errstr = mail_storage_get_last_error(mail->box->storage, &error);
+	mail_storage_set_error(ctx->transaction->box->storage, error,
+			       t_strdup_printf("%s (%s)", errstr, func));
+}
+
 static int
 mail_storage_try_copy(struct mail_save_context **_ctx, struct mail *mail)
 {
@@ -20,24 +35,32 @@
 	   to help anything. */
 	pmail->v.set_uid_cache_updates(mail, TRUE);
 
-	if (mail_get_stream(mail, NULL, NULL, &input) < 0)
+	if (mail_get_stream(mail, NULL, NULL, &input) < 0) {
+		mail_copy_set_failed(ctx, mail, "stream");
 		return -1;
+	}
 
 	if (ctx->received_date == (time_t)-1) {
-		if (mail_get_received_date(mail, &received_date) < 0)
+		if (mail_get_received_date(mail, &received_date) < 0) {
+			mail_copy_set_failed(ctx, mail, "received-date");
 			return -1;
+		}
 		mailbox_save_set_received_date(ctx, received_date, 0);
 	}
 	if (ctx->from_envelope == NULL) {
 		if (mail_get_special(mail, MAIL_FETCH_FROM_ENVELOPE,
-				     &from_envelope) < 0)
+				     &from_envelope) < 0) {
+			mail_copy_set_failed(ctx, mail, "from-envelope");
 			return -1;
+		}
 		if (*from_envelope != '\0')
 			mailbox_save_set_from_envelope(ctx, from_envelope);
 	}
 	if (ctx->guid == NULL) {
-		if (mail_get_special(mail, MAIL_FETCH_GUID, &guid) < 0)
+		if (mail_get_special(mail, MAIL_FETCH_GUID, &guid) < 0) {
+			mail_copy_set_failed(ctx, mail, "guid");
 			return -1;
+		}
 		if (*guid != '\0')
 			mailbox_save_set_guid(ctx, guid);
 	}


More information about the dovecot-cvs mailing list