dovecot-2.2: lib-storage: Log mail istream read failures in one ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 4 11:03:32 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/0902eded882f
changeset: 17598:0902eded882f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jul 04 14:01:53 2014 +0300
description:
lib-storage: Log mail istream read failures in one place.
Also handle ENOENT errors by checking if the mail has already been expunged,
and if so don't log an error, just return "mail is already expunged" error
to client.

diffstat:

 src/lib-storage/index/index-mail-binary.c  |   8 ++-
 src/lib-storage/index/index-mail-headers.c |   6 +--
 src/lib-storage/index/index-mail.c         |  51 +++++++++++++++++++----------
 src/lib-storage/index/index-mail.h         |   2 +
 4 files changed, 41 insertions(+), 26 deletions(-)

diffs (140 lines):

diff -r 82c9a9b7e6e6 -r 0902eded882f src/lib-storage/index/index-mail-binary.c
--- a/src/lib-storage/index/index-mail-binary.c	Fri Jul 04 13:16:59 2014 +0300
+++ b/src/lib-storage/index/index-mail-binary.c	Fri Jul 04 14:01:53 2014 +0300
@@ -116,7 +116,8 @@
 	if (ctx->input->stream_errno != 0) {
 		errno = ctx->input->stream_errno;
 		mail_storage_set_critical(ctx->mail->box->storage,
-			"read(%s) failed: %m", i_stream_get_name(ctx->input));
+			"read(%s) failed: %s", i_stream_get_name(ctx->input),
+			i_stream_get_error(ctx->input));
 		return -1;
 	}
 
@@ -407,8 +408,9 @@
 					       "Invalid data in MIME part");
 		} else {
 			mail_storage_set_critical(_mail->box->storage,
-				"read(%s) failed: %m",
-				i_stream_get_name(cache->input));
+				"read(%s) failed: %s",
+				i_stream_get_name(cache->input),
+				i_stream_get_error(cache->input));
 		}
 		mail_storage_free_binary_cache(_mail->box->storage);
 		binary_streams_free(&ctx);
diff -r 82c9a9b7e6e6 -r 0902eded882f src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c	Fri Jul 04 13:16:59 2014 +0300
+++ b/src/lib-storage/index/index-mail-headers.c	Fri Jul 04 14:01:53 2014 +0300
@@ -489,11 +489,7 @@
 		message_parse_header(stream, NULL, hdr_parser_flags,
 				     imap_envelope_parse_callback, mail);
 		if (stream->stream_errno != 0) {
-			errno = stream->stream_errno;
-			mail_storage_set_critical(mail->mail.mail.box->storage,
-				"read(%s) failed: %m (uid=%u)",
-				i_stream_get_name(mail->data.stream),
-				mail->mail.mail.uid);
+			index_mail_stream_log_failure_for(mail, stream);
 			return -1;
 		}
 		mail->data.save_envelope = FALSE;
diff -r 82c9a9b7e6e6 -r 0902eded882f src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Fri Jul 04 13:16:59 2014 +0300
+++ b/src/lib-storage/index/index-mail.c	Fri Jul 04 14:01:53 2014 +0300
@@ -855,11 +855,7 @@
 				 (i_stream_read(parser_input) == -1 &&
 				  !i_stream_have_bytes_left(parser_input)));
 		} else {
-			errno = parser_input->stream_errno;
-			mail_storage_set_critical(mail->mail.mail.box->storage,
-				"mail parser: read(%s, box=%s) failed: %m",
-				i_stream_get_name(parser_input),
-				mail->mail.mail.box->vname);
+			index_mail_stream_log_failure_for(mail, parser_input);
 			ret = -1;
 		}
 		i_stream_unref(&parser_input);
@@ -891,18 +887,41 @@
 	return 0;
 }
 
+static void index_mail_stream_log_failure(struct index_mail *mail)
+{
+	index_mail_stream_log_failure_for(mail, mail->data.stream);
+}
+
 int index_mail_stream_check_failure(struct index_mail *mail)
 {
 	if (mail->data.stream->stream_errno == 0)
 		return 0;
+	index_mail_stream_log_failure(mail);
+	return -1;
+}
 
-	errno = mail->data.stream->stream_errno;
-	mail_storage_set_critical(mail->mail.mail.box->storage,
-		"read(%s) failed: %s (uid=%u)",
-		i_stream_get_name(mail->data.stream),
-		i_stream_get_error(mail->data.stream),
-		mail->mail.mail.uid);
-	return -1;
+void index_mail_stream_log_failure_for(struct index_mail *mail,
+				       struct istream *input)
+{
+	struct mail *_mail = &mail->mail.mail;
+
+	i_assert(input->stream_errno != 0);
+
+	errno = input->stream_errno;
+	if (errno == ENOENT) {
+		/* was the mail just expunged? we could get here especially if
+		   external attachments are used and the attachment is deleted
+		   before we've opened the file. */
+		mail_index_refresh(_mail->box->index);
+		if (mail_index_is_expunged(_mail->transaction->view, _mail->seq)) {
+			mail_set_expunged(_mail);
+			return;
+		}
+	}
+	mail_storage_set_critical(_mail->box->storage,
+		"read(%s) failed: %s (uid=%u, box=%s)",
+		i_stream_get_name(input), i_stream_get_error(input),
+		_mail->uid, mailbox_get_vname(_mail->box));
 }
 
 static int index_mail_parse_body(struct index_mail *mail,
@@ -1001,9 +1020,7 @@
 				if (message_get_header_size(data->stream,
 							    &data->hdr_size,
 							    &has_nuls) < 0) {
-					mail_storage_set_critical(_mail->box->storage,
-						"read(%s) failed: %m",
-						i_stream_get_name(data->stream));
+					index_mail_stream_log_failure(mail);
 					return -1;
 				}
 				data->hdr_size_set = TRUE;
@@ -1027,9 +1044,7 @@
 				if (message_get_body_size(data->stream,
 							  &data->body_size,
 							  &has_nuls) < 0) {
-					mail_storage_set_critical(_mail->box->storage,
-						"read(%s) failed: %m",
-						i_stream_get_name(data->stream));
+					index_mail_stream_log_failure(mail);
 					return -1;
 				}
 				data->body_size_set = TRUE;
diff -r 82c9a9b7e6e6 -r 0902eded882f src/lib-storage/index/index-mail.h
--- a/src/lib-storage/index/index-mail.h	Fri Jul 04 13:16:59 2014 +0300
+++ b/src/lib-storage/index/index-mail.h	Fri Jul 04 14:01:53 2014 +0300
@@ -232,6 +232,8 @@
 				    enum mail_fetch_field field);
 int index_mail_opened(struct mail *mail, struct istream **stream);
 int index_mail_stream_check_failure(struct index_mail *mail);
+void index_mail_stream_log_failure_for(struct index_mail *mail,
+				       struct istream *input);
 struct index_mail *index_mail_get_index_mail(struct mail *mail);
 
 bool index_mail_get_cached_uoff_t(struct index_mail *mail,


More information about the dovecot-cvs mailing list