diff --git a/src/plugins/sieve-extprograms/cmd-execute.c b/src/plugins/sieve-extprograms/cmd-execute.c
index 6c1fb6dafc9624e723ce5fd755af43201396e9c0..f868595bd5bd8adfe20db756ceb2b69675393b10 100644
--- a/src/plugins/sieve-extprograms/cmd-execute.c
+++ b/src/plugins/sieve-extprograms/cmd-execute.c
@@ -441,9 +441,10 @@ static int cmd_execute_operation_execute
 	if ( outbuf != NULL ) 
 		buffer_free(&outbuf);
 
-	if ( is_test )
+	if ( is_test ) {
 		sieve_interpreter_set_test_result(renv->interp, ( ret > 0 ));
-
-	return SIEVE_EXEC_OK;
+		return SIEVE_EXEC_OK;
+	}
+	return ( ret >= 0 ? SIEVE_EXEC_OK : SIEVE_EXEC_FAILURE );
 }
 
diff --git a/src/plugins/sieve-extprograms/cmd-filter.c b/src/plugins/sieve-extprograms/cmd-filter.c
index 77bd35899e4babc6cd766bc4068809ecadeaae59..6b0bc09760e83ddd2acd0764d4464f700eef2b60 100644
--- a/src/plugins/sieve-extprograms/cmd-filter.c
+++ b/src/plugins/sieve-extprograms/cmd-filter.c
@@ -231,9 +231,12 @@ static int cmd_filter_operation_execute
 			"filter action: program indicated false result");
 	}
 
-	if ( is_test )
+	if ( is_test ) {
 		sieve_interpreter_set_test_result(renv->interp, ( ret > 0 ));
 
-	return SIEVE_EXEC_OK;
+		return SIEVE_EXEC_OK;
+	}
+
+	return ( ret >= 0 ? SIEVE_EXEC_OK : SIEVE_EXEC_FAILURE );
 }