diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c
index 81deda81b8fd60292deb75e4b921bdf7a5856ccb..6cc6c4e0a8cca5381dac55d7542b2f6bafbb41b9 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-common.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-common.c
@@ -240,6 +240,26 @@ static inline bool sieve_variable_valid
 	return ( index < array_count(&storage->scope->variable_index) );
 }
 
+bool sieve_variable_get_identifier
+(struct sieve_variable_storage *storage, unsigned int index, const char **identifier)
+{
+	struct sieve_variable * const *var;
+	*identifier = NULL;
+
+	if ( storage->scope == NULL ) return TRUE;
+
+	/* FIXME: direct invasion of the scope object is a bit ugly */
+	if ( index >= array_count(&storage->scope->variable_index) )
+		return FALSE;
+
+	var = array_idx(&storage->scope->variable_index, index);
+
+	if ( *var != NULL )
+		*identifier = (*var)->identifier;
+
+	return TRUE;
+}
+
 bool sieve_variable_get
 (struct sieve_variable_storage *storage, unsigned int index, string_t **value)
 {
diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
index 3703a9b80d3508ee796df7cda5d6aa6ccc571cfa..8824c044be225246abe78cfed3bf5ac0805ad40c 100644
--- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h
+++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
@@ -82,6 +82,9 @@ bool sieve_variable_get_modifiable
 bool sieve_variable_assign
 	(struct sieve_variable_storage *storage, unsigned int index, 
 		const string_t *value);
+bool sieve_variable_get_identifier
+	(struct sieve_variable_storage *storage, unsigned int index, 
+		const char **identifier);
 
 /*
  * Variables access