I used sievec to validate your script and got an error
Error: Unknown or incompatible type >>string/<< at >>:replace "." "" "to" "${1}"; set "envelope.to" "$<<
so set :replace "." "" "to" "${1}";
seam to be wrong
ChatGPT think this about your script
Errors in the Script
Incorrect set Command Usage:
The set command in Sieve requires a variable name to be set directly. The current script attempts to set "envelope.to," which is not directly supported as a variable in the Sieve scripting language. Instead, variables should be user-defined or predefined by the Sieve environment.
Misuse of :replace Modifier:
The :replace modifier is not a valid syntax in the context of the set command in Sieve. Instead, use the regex extension to perform replacements.
Improper Handling of Regular Expressions and Captured Variables:
Captured groups in the regex match should be accessed correctly. When using regular expressions in Sieve, you need to store the matched components explicitly into variables.