diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c
index f4c01786a0c8b9b0655c7c579331ab05f7d497aa..be225b736fee7af10a3aff2fd7f6f3c7307a9360 100644
--- a/src/lib-sieve/sieve-script.c
+++ b/src/lib-sieve/sieve-script.c
@@ -441,9 +441,16 @@ int sieve_script_cmp(const struct sieve_script *script1,
 
 unsigned int sieve_script_hash(const struct sieve_script *script)
 {
-	i_assert(script->name != NULL);
+	if (script == NULL)
+		return 0;
+
+	unsigned int hash = 0;
+
+	hash ^= POINTER_CAST_TO(script->script_class, unsigned int);
+	hash ^= sieve_storage_hash(script->storage);
+	hash ^= str_hash(script->name);
 
-	return str_hash(script->name);
+	return hash;
 }
 
 /*