From 7c77a9bdb3e877ac1cd7b8c10428244846a14355 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 4 Oct 2009 23:18:16 +0200
Subject: [PATCH] Made compiler more lenient towars missing CRLF at the end of
 the script in a hash comment.

---
 Makefile.am                      | 1 +
 src/lib-sieve/sieve-lexer.c      | 6 +++---
 tests/compile/warnings.svtest    | 8 ++++++++
 tests/compile/warnings/eof.sieve | 2 ++
 4 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 tests/compile/warnings.svtest
 create mode 100644 tests/compile/warnings/eof.sieve

diff --git a/Makefile.am b/Makefile.am
index b20be0ecf..43a7b56dc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,6 +43,7 @@ test_cases = \
 	tests/control-structures.svtest \
 	tests/compile/compile.svtest \
 	tests/compile/errors.svtest \
+	tests/compile/warnings.svtest \
 	tests/execute/errors.svtest \
 	tests/execute/actions.svtest \
 	tests/execute/smtp.svtest \
diff --git a/src/lib-sieve/sieve-lexer.c b/src/lib-sieve/sieve-lexer.c
index 1c51cba81..260ec9f08 100644
--- a/src/lib-sieve/sieve-lexer.c
+++ b/src/lib-sieve/sieve-lexer.c
@@ -318,9 +318,9 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexer *lexer)
 		while ( sieve_lexer_curchar(lexer) != '\n' ) {
 			switch( sieve_lexer_curchar(lexer) ) {
 			case -1:
-				sieve_lexer_error(lexer, "end of file before end of hash comment");
-				lexer->token_type = STT_ERROR;
-				return FALSE;
+				sieve_lexer_warning(lexer, "no newline (CRLF) at end of hash comment at end of file");
+				lexer->token_type = STT_WHITESPACE;
+				return TRUE;
 			case '\0':
 				sieve_lexer_error(lexer, "encountered NUL character in hash comment");
 				lexer->token_type = STT_ERROR;
diff --git a/tests/compile/warnings.svtest b/tests/compile/warnings.svtest
new file mode 100644
index 000000000..66f26f686
--- /dev/null
+++ b/tests/compile/warnings.svtest
@@ -0,0 +1,8 @@
+require "vnd.dovecot.testsuite";
+
+test "EOF Warnings" {
+    if not test_script_compile "warnings/eof.sieve" {
+        test_fail "compile should have succeeded.";
+    }
+}
+
diff --git a/tests/compile/warnings/eof.sieve b/tests/compile/warnings/eof.sieve
new file mode 100644
index 000000000..e7121495d
--- /dev/null
+++ b/tests/compile/warnings/eof.sieve
@@ -0,0 +1,2 @@
+keep;
+# Kept
\ No newline at end of file
-- 
GitLab