From ce5d301cdd9793fa83d5e0d0375020cc93eda241 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sat, 11 Oct 2014 00:42:39 +0200
Subject: [PATCH] lib-sieve: Omitted handling errors from mail_get_headers() in
 message header stringlist. Mail storage errors now trigger a runtime error.

---
 src/lib-sieve/sieve-message.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/lib-sieve/sieve-message.c b/src/lib-sieve/sieve-message.c
index b69c4163b..271a5e58b 100644
--- a/src/lib-sieve/sieve-message.c
+++ b/src/lib-sieve/sieve-message.c
@@ -22,6 +22,7 @@
 #include "sieve-extensions.h"
 #include "sieve-runtime.h"
 #include "sieve-runtime-trace.h"
+#include "sieve-interpreter.h"
 #include "sieve-address.h"
 
 #include "sieve-message.h"
@@ -536,19 +537,23 @@ static int sieve_message_header_stringlist_next_item
 
 		/* Fetch all matching headers from the e-mail */
 		if ( strlist->mime_decode ) {
-			if ( mail_get_headers_utf8(mail, str_c(hdr_item), &strlist->headers) < 0 ||
-				( strlist->headers != NULL && strlist->headers[0] == NULL ) ) {
-				/* Try next item when this fails somehow */
-				strlist->headers = NULL;
-				continue;
-			}
+			ret = mail_get_headers_utf8(mail, str_c(hdr_item), &strlist->headers);			
 		} else {
-			if ( mail_get_headers(mail, str_c(hdr_item), &strlist->headers) < 0 ||
-				( strlist->headers != NULL && strlist->headers[0] == NULL ) ) {
-				/* Try next item when this fails somehow */
-				strlist->headers = NULL;
-				continue;
-			}
+			ret = mail_get_headers(mail, str_c(hdr_item), &strlist->headers);
+		}
+
+		if (ret < 0) {
+			sieve_runtime_critical(renv, NULL,
+				"failed to read header field",
+				"failed to read header field `%s': %s",
+				str_c(hdr_item), mailbox_get_last_error(mail->box, NULL));
+			_strlist->exec_status = SIEVE_EXEC_FAILURE;
+			return -1;
+		}
+
+		if ( strlist->headers == NULL || strlist->headers[0] == NULL ) {
+			/* Try next item when no headers found */
+			strlist->headers = NULL;
 		}
 	}
 
-- 
GitLab