Sieve translate extension

From Messaging Server Technical Reference Wiki
Revision as of 09:02, 10 May 2016 by BulkPageCreator (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


New in MS 8.0.1, the MTA supports a private "translate" function, to translate a string (or a list) from one character set to another. No "require" clause is needed to use this private extension.

Note that RFC 5228 requires that Sieve filters represent strings in UTF-8. Even strings that (in original messages) were in some other charset are converted to UTF-8 for purposes of Sieve processing. So usually the entire issue of character sets can be ignored for Sieve processing: everything is represented in UTF-8. However, on occasion malformed messages may be encountered that contain incorrectly labelled, or incorrectly structured MIME encoded-words, where proper conversion to UTF-8 cannot be performed. Or special purpose generation of explicitly encoded-in-a-specific-charset strings may be desired. These are cases where the "translate" function may be of use.

"translate" takes three (positional) arguments: the original string, the character set of the original string, and the character set to which to translate the string. Note that the original string remains unchanged; the translated string is returned as a function result.

Either of the following two Sieve sequences of commands will request "fileinto" (folder delivery) to the folder named "nopNOP". The first example does this making use of a variable, plus the MTA Sieve implementation feature of allowing an assignment statement:


require ["variables","fileinto"];
set "string" "abcABC";
rotstring := translate "${string}" "US-ASCII" "ROT13";
fileinto "${rotstring}"; 

The second example does this by making use of the MTA Sieve implementation feature allowing expressions where arguments are normally expected, to perform the "translate" in-line, without use of any named variable:


require "fileinto";
fileinto (translate "abcABC" "US-ASCII" "ROT13");

See also: