diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c
index 3c896f2d2c289cea8fd1052ad0e2faa23660b8f2..fc75063d9f8b91b853d311d9a1dde9c1c5938f16 100644
--- a/src/lib-sieve/sieve-result.c
+++ b/src/lib-sieve/sieve-result.c
@@ -969,7 +969,14 @@ static int _sieve_result_implicit_keep
 
 			rac = rac->next;
 		}
+	} else if ( !rollback ) {
+		act_keep.location = kac->action.location;
+		act_keep.mail = kac->action.mail;
+		if ( kac->seffects != NULL )
+			rsef_first = kac->seffects->first_effect;
+	}
 
+	if (rsef_first == NULL) {
 		/* Apply any implicit side effects if applicable */
 		if ( !rollback && hash_table_is_created(result->action_contexts) ) {
 			struct sieve_result_action_context *actctx;
@@ -980,11 +987,6 @@ static int _sieve_result_implicit_keep
 			if ( actctx != NULL && actctx->seffects != NULL )
 				rsef_first = actctx->seffects->first_effect;
 		}
-	} else if ( !rollback ) {
-		act_keep.location = kac->action.location;
-		act_keep.mail = kac->action.mail;
-		if ( kac->seffects != NULL )
-			rsef_first = kac->seffects->first_effect;
 	}
 
 	/* Start keep action */