diff --git a/Makefile.am b/Makefile.am
index 8ca0267645b30bb443e63e7a00c5dbca7b10e5ba..53a4d10288e8f11984c0ab597add429d0473f930 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,9 @@ EXTRA_DIST = \
 	examples \
 	COPYING.LGPL \
 	ChangeLog \
-	update-version.sh
+	update-version.sh \
+	tests/test-address.svtest.in \
+	tests/failures/mailbox-bad-utf8.svtest.in
 
 dist-hook:
 	rm -rf `find $(distdir)/tests -type f -name '*.svbin'`
@@ -56,6 +58,10 @@ else
 test_unfinished =
 endif
 
+test_utf8_cases = \
+		  tests/test-address.svtest \
+		  tests/failures/mailbox-bad-utf8.svtest
+
 test_cases = \
 	tests/testsuite.svtest \
 	tests/control-if.svtest \
@@ -184,7 +190,17 @@ test_cases = \
 	tests/extensions/vnd.dovecot/report/execute.svtest \
 	$(test_unfinished)
 
-$(test_cases):
+
+prepare_test_cases:
+	$(AM_V_at)for case in $(test_utf8_cases); do \
+		if test @HAVE_MAIL_UTF8@ = 1; then \
+		  $(SED) -s -e 's/#UTF8#.*//' $${case}.in > $$case ; \
+		else \
+		  $(SED) -s -e 's/#UTF8#//' $${case}.in > $$case ; \
+		fi; \
+	done
+
+$(test_cases): prepare_test_cases
 	@$(TEST_BIN) $(top_srcdir)/$@
 
 failure_test_cases = \
@@ -214,7 +230,7 @@ extprograms_test_cases = \
 $(extprograms_test_cases):
 	@$(TEST_EXTPROGRAMS_BIN) 	$(top_srcdir)/$@
 
-.PHONY: test test-plugins $(test_cases) $(failure_test_cases) $(extprograms_test_cases)
+.PHONY: test test-plugins $(test_cases) $(failure_test_cases) $(extprograms_test_cases) prepare_test_case
 test: all-am $(test_cases) $(failure_test_cases)
 test-plugins: all-am $(extprograms_test_cases)
 
diff --git a/configure.ac b/configure.ac
index ba24a322ee341c3763d8c0ec08ef405c78dbe3ce..d406e635cbeb37785b9e73e3f34bf4c6f2412888 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,8 @@ AC_SUBST(BINARY_CFLAGS)
 AC_SUBST(BINARY_LDFLAGS)
 AC_SUBST(LIBDOVECOT_INCLUDE)
 
+DC_HAVE_MAIL_UTF8
+
 AC_SUBST(PIGEONHOLE_ASSET_VERSION, regexp(AC_PACKAGE_VERSION, [^\([0-9]+\)\.\([0-9]+\).\([0-9]+\)], [\1.\2.\3]))
 AS_IF([test $PIGEONHOLE_ASSET_VERSION = "0.0.0"], [
    AC_SUBST([PIGEONHOLE_ASSET_VERSION], "main")
diff --git a/tests/failures/mailbox-bad-utf8.svtest b/tests/failures/mailbox-bad-utf8.svtest
deleted file mode 100644
index ad104e5ab8ddcc0f25a7773fce1b90d03120b2bf..0000000000000000000000000000000000000000
--- a/tests/failures/mailbox-bad-utf8.svtest
+++ /dev/null
@@ -1,6 +0,0 @@
-require "vnd.dovecot.testsuite";
-require "encoded-character";
-
-test "Mailbox parameter with bad UTF-8" {
-	test_message :folder "I${hex:9b}BOX" 0;
-}
diff --git a/tests/failures/mailbox-bad-utf8.svtest.in b/tests/failures/mailbox-bad-utf8.svtest.in
new file mode 100644
index 0000000000000000000000000000000000000000..2b441ed5cd8b09be0da439e25fcfe37f6fd249a2
--- /dev/null
+++ b/tests/failures/mailbox-bad-utf8.svtest.in
@@ -0,0 +1,6 @@
+require "vnd.dovecot.testsuite";
+require "encoded-character";
+
+#UTF8# test "Mailbox parameter with bad UTF-8" {
+#UTF8#	test_message :folder "I${hex:9b}BOX" 0;
+#UTF8# }
diff --git a/tests/test-address.svtest b/tests/test-address.svtest.in
similarity index 97%
rename from tests/test-address.svtest
rename to tests/test-address.svtest.in
index 3f7012fe4050a97aa941a677a719e4fdec87d189..1598826c11cce7b81689ecf96d7a58898de2f662 100644
--- a/tests/test-address.svtest
+++ b/tests/test-address.svtest.in
@@ -454,17 +454,17 @@ test "Invalid addresses" {
 		test_fail ":localpart matched invalid address";
 	}
 
-	if address :localpart "resent-cc" "jürgen" {
-		test_fail ":localpart matched invalid UTF-8 address";
-	}
+#UTF8#	if address :localpart "resent-cc" "jürgen" {
+#UTF8#		test_fail ":localpart matched invalid UTF-8 address";
+#UTF8#	}
 
 	if address :domain "to" "example.org" {
 		test_fail ":domain matched invalid address";
 	}
 
-	if address :domain "resent-cc" "example.com" {
-		test_fail ":domain matched invalid UTF-8 address";
-	}
+#UTF8#	if address :domain "resent-cc" "example.com" {
+#UTF8#		test_fail ":domain matched invalid UTF-8 address";
+#UTF8#	}
 
 	if not address :is :all "resent-to" "" {
 		test_fail ":all failed to match empty address";
@@ -474,9 +474,9 @@ test "Invalid addresses" {
 		test_fail ":all failed to match invalid address";
 	}
 
-	if not address :is :all "resent-cc" "<jürgen@example.com>" {
-		test_fail ":all failed to match invalid UTF-8 address";
-	}
+#UTF8#	if not address :is :all "resent-cc" "<jürgen@example.com>" {
+#UTF8#		test_fail ":all failed to match invalid UTF-8 address";
+#UTF8#	}
 
 	if address :is :localpart "bcc" "" {
 		test_fail ":localpart matched invalid address";