diff --git a/src/lib-sieve/sieve-storage-private.h b/src/lib-sieve/sieve-storage-private.h
index 46820227a48962500b8293fe727327637bac9b67..32ad37d9f2dee67a78c48f3655424344e3cbf49b 100644
--- a/src/lib-sieve/sieve-storage-private.h
+++ b/src/lib-sieve/sieve-storage-private.h
@@ -142,6 +142,17 @@ int sieve_storage_alloc_with_settings(struct sieve_instance *svinst,
 				      enum sieve_error *error_code_r,
 				      const char **error_r);
 
+/*
+ * Utility
+ */
+
+int sieve_storage_get_full_path(struct sieve_storage *storage,
+				const char *path, const char **path_r);
+
+/*
+ * Binary
+ */
+
 int sieve_storage_setup_bin_path(struct sieve_storage *storage, mode_t mode);
 
 /*
diff --git a/src/lib-sieve/sieve-storage.c b/src/lib-sieve/sieve-storage.c
index bf3f30c3e8bfe869e1c5781160b2fc9f7d77555d..5f8bca3d1b826dbb9618cb44cddc2b840a106719 100644
--- a/src/lib-sieve/sieve-storage.c
+++ b/src/lib-sieve/sieve-storage.c
@@ -808,6 +808,37 @@ void sieve_storage_unref(struct sieve_storage **_storage)
 	pool_unref(&storage->pool);
 }
 
+/*
+ * Utility
+ */
+
+int sieve_storage_get_full_path(struct sieve_storage *storage,
+				const char *path, const char **path_r)
+{
+	struct sieve_instance *svinst = storage->svinst;
+
+	*path_r = path;
+
+	if (path == NULL || *path == '\0')
+		return 0;
+	if ((path[0] != '~' || (path[1] != '/' && path[1] != '\0')) &&
+	    ((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) == 0 ||
+	     path[0] == '/'))
+		return 0;
+
+	/* Home-relative path. change to absolute. */
+	const char *home = sieve_environment_get_homedir(svinst);
+
+	if (home == NULL)
+		return -1;
+
+	if (path[0] == '~' && (path[1] == '/' || path[1] == '\0'))
+		*path_r = home_expand_tilde(path, home);
+	else
+		*path_r = t_strconcat(home, "/", path, NULL);
+	return 0;
+}
+
 /*
  * Binary
  */
diff --git a/src/lib-sieve/storage/file/sieve-file-storage.c b/src/lib-sieve/storage/file/sieve-file-storage.c
index 829ee2e1394f639f36cfbbadec8a7377e9f4f566..da6459cd83a98b67ecafb38ab6d804d0bfe38db9 100644
--- a/src/lib-sieve/storage/file/sieve-file-storage.c
+++ b/src/lib-sieve/storage/file/sieve-file-storage.c
@@ -225,33 +225,15 @@ sieve_file_storage_get_full_path(struct sieve_file_storage *fstorage,
 				 const char **storage_path)
 {
 	struct sieve_storage *storage = &fstorage->storage;
-	struct sieve_instance *svinst = storage->svinst;
 	const char *path = *storage_path;
 
-	/* Get full storage path */
-
-	if (path != NULL &&
-	    ((path[0] == '~' && (path[1] == '/' || path[1] == '\0')) ||
-	     (((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) != 0) &&
-	      path[0] != '/'))) {
-		/* home-relative path. change to absolute. */
-		const char *home = sieve_environment_get_homedir(svinst);
-
-		if (home != NULL) {
-			if (path[0] == '~' && (path[1] == '/' ||
-			    path[1] == '\0'))
-				path = home_expand_tilde(path, home);
-			else
-				path = t_strconcat(home, "/", path, NULL);
-		} else {
-			sieve_storage_set_critical(
-				storage,
-				"Sieve storage path '%s' is relative to home directory, "
-				"but home directory is not available.", path);
-			return -1;
-		}
+	if (sieve_storage_get_full_path(storage, path, storage_path) < 0) {
+		sieve_storage_set_critical(
+			storage,
+			"Sieve storage path '%s' is relative to home directory, "
+			"but home directory is not available.", path);
+		return -1;
 	}
-	*storage_path = path;
 	return 0;
 }
 
@@ -260,31 +242,15 @@ sieve_file_storage_get_full_active_path(struct sieve_file_storage *fstorage,
 					const char **active_path)
 {
 	struct sieve_storage *storage = &fstorage->storage;
-	struct sieve_instance *svinst = storage->svinst;
 	const char *path = *active_path;
 
-	if (path != NULL && *path != '\0' &&
-	    ((path[0] == '~' && (path[1] == '/' || path[1] == '\0')) ||
-	     (((svinst->flags & SIEVE_FLAG_HOME_RELATIVE) != 0) &&
-	      path[0] != '/')))	{
-		/* home-relative path. change to absolute. */
-		const char *home = sieve_environment_get_homedir(svinst);
-
-		if (home != NULL) {
-			if (path[0] == '~' && (path[1] == '/' ||
-			    path[1] == '\0'))
-				path = home_expand_tilde(path, home);
-			else
-				path = t_strconcat(home, "/", path, NULL);
-		} else {
-			sieve_storage_set_critical(
-				storage,
-				"Sieve storage active script path '%s' is relative to home directory, "
-				"but home directory is not available.", path);
-			return -1;
-		}
+	if (sieve_storage_get_full_path(storage, path, active_path) < 0) {
+		sieve_storage_set_critical(
+			storage,
+			"Sieve storage active script path '%s' is relative to home directory, "
+			"but home directory is not available.", path);
+		return -1;
 	}
-	*active_path = path;
 	return 0;
 }