Go to the first, previous, next, last section, table of contents.


Expansion operators

The following operations can be performed on portions of an expanded string:


${domain:<string>}

The string is interpreted as an RFC 822 address and the domain is extracted from it. If the string does not parse successfully, the result is empty.


${expand:<string>}

The `expand' operator causes a string to be expanded for a second time. For example,


${expand:${lookup{$domain}dbm{/some/file}{$value}}}

first looks up a string in a file while expanding the operand for `expand', and then re-expands what it has found.


${hash_<n>_<m>:<string>}

The two items <n> and <m> are numbers. If <n> is greater than or equal to the length of the string, the operator returns the string. Otherwise it computes a new string of length <n> by applying a hashing function to the string. The new string consists of characters taken from the first <m> characters of the string


abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQWRSTUVWXYZ0123456789

and if <m> is not present the value 26 is used, so that only lower case letters appear. These examples:


${hash_3:monty}
${hash_5:monty}
${hash_4_62:monty python}

yield


jmg
monty
fbWx

respectively. The abbreviation `h' can be used instead of `hash'.


${lc:<string>}

This forces the letters in the string into lower-case, for example:


${lc:$local_part}

${length_<number>:<string>}

The `length' operator can be used to extract the initial portion of a string. It is followed by an underscore and the number of characters required. For example


${length_50:$message_body}

The result of this operator is either the first <number> characters or the whole string, whichever is the shorter. The abbreviation `l' can be used instead of `length'.


${local_part:<string>}

The string is interpreted as an RFC 822 address and the local part is extracted from it. If the string does not parse successfully, the result is empty.


${quote:<string>}

The `quote' operator puts its argument into double quotes if it contains anything other than letters, digits, underscores, full stops (periods), and hyphens. Any occurrences of double quotes and backslashes are escaped with a backslash. For example,


${quote:ab*cd}

becomes


"ab*cd"

The place where this is useful is when the argument is a substitution from a variable or a message header.


${rxquote:<string>}

The `rxquote' operator inserts a backslash before any non-alphanumeric characters in its argument. This is useful when substituting the values of variables or headers inside regular expressions.


${substr_<start>_<length>:<string>}

The `substr' operator can be used to extract more general substrings than `length'. It is followed by an underscore and the starting offset, then a second underscore and the length required. For example


${substr_3_2:$local_part}

If the starting offset is greater than the string length the result is the null string; if the length plus starting offset is greater than the string length, the result is the right-hand part of the string, starting from the given offset. The first character in the string has offset zero. The abbreviation `s' can be used instead of `substr'.

The `substr' expansion operator can take negative offset values to count from the righthand end of its operand. The last character is offset -1, the second-last is offset -2, and so on. Thus, for example,


${substr_-5_2:1234567}

yields `34'. If the absolute value of a negative offset is greater than the length of the string, the substring starts at the beginning of the string, and the length is reduced by the amount of overshoot. Thus, for example,


${substr_-5_2:12}

yields an empty string, but


${substr_-3_2:12}

yields `1'.

If the second number is omitted from `substr', the remainder of the string is taken if the offset was positive. If it was negative, all characters in the string preceding the offset point are taken. For example, an offset of -1 and no length yields all but the last character of the string.


Go to the first, previous, next, last section, table of contents.