1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
|
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
from spec on 25 November 2000 -->
<TITLE>Exim Specification - 9. String expansions</TITLE>
</HEAD>
<body bgcolor="#FFFFFF" text="#00005A" link="#FF6600" alink="#FF9933" vlink="#990000">
Go to the <A HREF="spec_1.html">first</A>, <A HREF="spec_8.html">previous</A>, <A HREF="spec_10.html">next</A>, <A HREF="spec_59.html">last</A> section, <A HREF="spec_toc.html">table of contents</A>.
<P><HR><P>
<H1><A NAME="SEC176" HREF="spec_toc.html#TOC176">9. String expansions</A></H1>
<P>
<A NAME="IDX525"></A>
<A NAME="IDX526"></A>
A number of configuration strings are expanded before use. Some of them are
expanded every time they are used; others are expanded only once.
</P>
<P>
Expanded strings are copied verbatim from left to right except when a dollar or
backslash character is encountered. A dollar specifies the start of a portion
of the string which is interpreted and replaced as described below.
</P>
<P>
An uninterpreted dollar can be included in the string by putting a backslash in
front of it -- if the string appears in quotes in the configuration file, two
backslashes are required because the quotes themselves cause interpretation of
backslashes when the string is read in. A backslash can be used to prevent any
special character being treated specially in an expansion, including itself.
</P>
<P>
A backslash followed by one of the letters `n', `r', or `t' is recognized as an
escape sequence for the character newline, carriage return, or tab,
respectively. A backslash followed by up to three octal digits is recognized as
an octal encoding for a single character, while a backslash followed by `x' and
up to two hexadecimal digits is a hexadecimal encoding. A backslash followed by
any other character causes that character to be added to the output string
uninterpreted. These escape sequences are also recognized in quoted strings as
they are read in; their interpretation in expansions as well is useful for
unquoted strings and other cases such as looked-up strings that are then
expanded.
</P>
<P>
<H2><A NAME="SEC177" HREF="spec_toc.html#TOC177">9.1 Testing string expansions</A></H2>
<P>
<A NAME="IDX527"></A>
<A NAME="IDX528"></A>
Many expansions can be tested by calling Exim with the -<EM>be</EM> option. This takes
the command arguments, or lines from the standard input if there are no
arguments, runs them through the string expansion code, and writes the results
to the standard output. Variables based on configuration values are set up, but
since no message is being processed, variables such as $<EM>local_part</EM> have no
value. Nevertheless the -<EM>be</EM> option can be useful for checking out file and
database lookups, and the use of expansion operators such as <EM>substr</EM> and
<EM>hash</EM>.
</P>
<P>
<font color=green>
Exim gives up its root privilege when it is called with the -<EM>be</EM> option, and
instead runs under the uid and gid it was called with, to prevent users from
using -<EM>be</EM> for reading files to which they normally do not have access.
</font>
</P>
<H2><A NAME="SEC178" HREF="spec_toc.html#TOC178">9.2 Expansion items</A></H2>
<P>
The following items are recognized in expanded strings. White space may be used
between sub-items that are keywords or substrings enclosed in braces inside an
outer set of braces, to improve readability.
<font color=green>
Within braces, however, white space is significant.
</font>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>$<<EM>variable name</EM>> or ${<<EM>variable name</EM>>}</b>
</PRE>
<P>
<A NAME="IDX529"></A>
Substitute the contents of the named variable, for example
<PRE>
$local_part
${domain}
</PRE>
<P>
The second form can be used to separate the name from subsequent alphanumeric
characters. This form (using curly brackets) is available only for variables;
it does <EM>not</EM> apply to message headers. The names of the variables are given
in section 9.5 below. If the name of a non-existent
variable is given, the expansion fails.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>$header_<<EM>header name</EM>>: or $h_<<EM>header name</EM>>:</b>
</PRE>
<P>
<A NAME="IDX530"></A>
Substitute the contents of the named message header line, for example
<PRE>
$header_reply-to:
</PRE>
<P>
The header names follow the syntax of RFC 822, which states that they may
contain any printing characters except space and colon. Consequently, curly
brackets <EM>do not</EM> terminate header names,
and should not be used to enclose them as if they were variables. Attempting to
do so causes a syntax error.
</P>
<P>
Upper-case and lower-case letters are synonymous in header names. If the
following character is white space, the terminating colon may be omitted, but
this is not recommended, because you may then forget it when it is needed. When
white space terminates the header name, it is included in the expanded string.
If the message does not contain the given header, the expansion item is
replaced by an empty string. (See the <EM>def</EM> condition in section
9.4 for a means of testing for the existence of a header.)
If there is more than one header with the same name, they are all concatenated
to form the substitution string, with a newline character between each of them.
However, if the length of this string exceeds 64K, any further headers of the
same name are ignored.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${<<EM>op</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX531"></A>
The string is first itself expanded, and then the operation specified by <<EM>op</EM>>
is applied to it. For example,
<PRE>
${lc:$local_part}
</PRE>
<P>
A list of operators is given in section 9.3 below. The
string starts with the first character after the colon, which may be leading
white space.
</P>
<P>
<font color=green>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${extract{<<EM>key</EM>>}{<<EM>string1</EM>>}{<<EM>string2</EM>>}{<<EM>string3</EM>>}}</b>
</PRE>
<P>
The key and <<EM>string1</EM>> are first expanded separately. The key must not
consist entirely of digits. For the string, the result must be of the form:
<PRE>
<<EM>key1</EM>> = <<EM>value1</EM>> <<EM>key2</EM>> = <<EM>value2</EM>> ...
</PRE>
<P>
where the equals signs and spaces are optional. If any of the values contain
white space, they must be enclosed in double quotes, and any values that are
enclosed in double quotes are subject to escape processing as described in
section
7.8. The expanded <<EM>string1</EM>> is searched for the value that
corresponds to the key. If it is found, <<EM>string2</EM>> is expanded, and replaces
the whole item; otherwise <<EM>string3</EM>> is used. During the expansion of
<<EM>string2</EM>> the variable $<EM>value</EM> contains the value that has been extracted.
Afterwards, it is restored to any previous value it might have had.
</P>
<P>
If {<<EM>string3</EM>>} is omitted, the item is replaced by nothing if the key is
not found. If {<<EM>string2</EM>>} is also omitted, the value that was looked up is
used. Thus, for example, these two expansions are identical, and yield `2001':
<PRE>
${extract{gid}{uid=1984 gid=2001}}
${extract{gid}{uid=1984 gid=2001}{$value}}
</PRE>
<P>
Instead of {<<EM>string3</EM>>} the word `fail' (not in curly brackets) can appear,
for example:
<PRE>
${extract{Z}{A=... B=...}{$value} fail }
</PRE>
<P>
{<<EM>string2</EM>>} must be present for `fail' to be recognized. When this syntax
is used, if the extraction fails,
the entire string expansion fails in a way that can be detected by the code in
Exim which requested the expansion. This is called `forced expansion failure',
and its consequences depend on the circumstances. In some cases it is no
different from any other expansion failure, but in others a different action
may be taken. See for example the <EM>new_address</EM> option of the <EM>smartuser</EM>
director.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${extract{<<EM>number</EM>>}{<<EM>separators</EM>>}{<<EM>string1</EM>>}{<<EM>string2</EM>>}{<<EM>string3</EM>>}}</b>
</PRE>
<P>
The <<EM>number</EM>> argument must consist entirely of decimal digits. This is what
distinguishes this form of <EM>extract</EM> from the previous kind. It behaves in the
same way, except that, instead of extracting a named field, it extracts from
<<EM>string1</EM>> the field whose number is given as the first argument. The first
field is numbered one. If the number is greater than the number of fields in
the string, the result is empty; if it is zero, the entire string is returned.
The fields in the string are separated by any one of the characters in the
separator string. For example:
<PRE>
${extract{2}{:}{x:42:99:& Mailer::/bin/bash}}
</PRE>
<P>
yields `42'. Two successive separators mean that the field between them is
empty (for example, the sixth field above).
</font>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${if <<EM>condition</EM>> {<<EM>string1</EM>>}{<<EM>string2</EM>>}}</b>
</PRE>
<P>
<A NAME="IDX532"></A>
If <<EM>condition</EM>> is true, <<EM>string1</EM>> is expanded and replaces the whole item;
otherwise <<EM>string2</EM>> is used. For example,
<PRE>
${if eq {$local_part}{postmaster} {yes}{no} }
</PRE>
<P>
The second string need not be present; if it is not and the condition is not
true, the item is replaced with nothing. Alternatively, the word `fail' may be
present instead of the second string (without any curly brackets). In this
case, the expansion is forced to fail if the condition is not true. The
available conditions are described in section 9.4 below.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${lookup{<<EM>key</EM>>} <<EM>search type</EM>> {<<EM>file</EM>>} {<<EM>string1</EM>>} {<<EM>string2</EM>>}}</b>
</PRE>
<PRE>
<b>${lookup <<EM>search type</EM>> {<<EM>query</EM>>} {<<EM>string1</EM>>} {<<EM>string2</EM>>}}</b>
</PRE>
<P>
<A NAME="IDX533"></A>
<A NAME="IDX534"></A>
<A NAME="IDX535"></A>
<A NAME="IDX536"></A>
These items specify data lookups in files and databases, as discussed in
chapter 6. The first form is used for single-key lookups, and the
second is used for query-style lookups. The <<EM>key</EM>>, <<EM>file</EM>>, and <<EM>query</EM>>
strings are expanded before use.
</P>
<P>
If there is any white space in a lookup item which is part of a filter command,
a rewrite rule, a routing rule for the <EM>domainlist</EM> router, or any other place
where white space is significant,
the lookup item must be enclosed in double quotes.
The use of data lookups in users' filter files may be locked out by the system
administrator.
</P>
<P>
<A NAME="IDX537"></A>
If the lookup succeeds, <<EM>string1</EM>> is expanded and replaces the entire item.
During its expansion, the variable $<EM>value</EM> contains the data returned by the
lookup.
<font color=green>
Afterwards it reverts to the value it had previously (at the outer level it is
empty).
</font>
If the lookup fails, <<EM>string2</EM>> is expanded and replaces the entire item. If
{<<EM>string2</EM>>} is omitted, the replacement is null on failure. Alternatively,
<<EM>string2</EM>> can itself be a nested lookup, thus providing a mechanism for
looking up a default value when the original lookup fails.
</P>
<P>
<font color=green>
If a nested lookup is used as part of <<EM>string1</EM>>, $<EM>value</EM> contains the data
for the outer lookup while the parameters of the second lookup are expanded,
and also while <<EM>string2</EM>> of the second lookup is expanded, should the second
lookup fail.
</font>
</P>
<P>
Instead of {<<EM>string2</EM>>} the word `fail' can appear, and in this case, if the
lookup fails, the entire expansion is forced to fail. If both {<<EM>string1</EM>>}
and {<<EM>string2</EM>>} are omitted, the result is the looked up value in the case
of a successful lookup, and nothing in the case of failure.
</font>
</P>
<P>
For single-key lookups, the string `partial-' is permitted to precede the
search type in order to do partial matching, and * or *@ may follow a
search type to request default lookups if the key does not match (see sections
6.6 and 6.7).
</P>
<P>
If a partial search is used, the variables $<EM>1</EM> and $<EM>2</EM> contain the wild
and non-wild parts of the key during the expansion of the replacement text.
They return to their previous values at the end of the lookup item.
</P>
<P>
This example looks up the postmaster alias in the conventional alias file.
<PRE>
${lookup {postmaster} lsearch {/etc/aliases} {$value}}
</PRE>
<P>
This example uses NIS+ to look up the full name of the user corresponding to
the local part of an address, forcing the expansion to fail if it is not found.
<PRE>
"${lookup nisplus {[name=$local_part],passwd.org_dir:gcos} \
{$value}fail}"
</PRE>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${lookup{<<EM>key:subkey</EM>>} <<EM>search type</EM>> {<<EM>file</EM>>} {<<EM>string1</EM>>} {<<EM>string2</EM>>}}</b>
</PRE>
<P>
<font color=green>
This is just a syntactic variation for a single-key lookup, surrounded by an
<EM>extract</EM> item. It searches for <<EM>key</EM>> in the file as described above for
single-key lookups; if it succeeds, it extracts from the data a subfield which
is identified by the <<EM>subkey</EM>>. For example, if a line in a linearly searched
file contains
<PRE>
alice: uid=1984 gid=2001
</PRE>
<P>
then expanding the string
<PRE>
${lookup{alice:uid}lsearch{<<EM>file name</EM>>}{$value}}
</PRE>
<P>
yields the string `1984'. If the subkey is not found in the looked up data,
then <<EM>string2</EM>>, if present, is expanded and replaces the entire item.
Otherwise the replacement is null. The example above could equally well be
written like this:
<PRE>
${extract{uid}{${lookup{alice}lsearch{<<EM>file name</EM>>}}}}
</PRE>
<P>
and this is recommended, because this approach can also be used with
query-style lookups.
</font>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${perl{<<EM>subroutine</EM>>}{<<EM>arg</EM>>}{<<EM>arg</EM>>}...}</b>
</PRE>
<P>
<A NAME="IDX538"></A>
This item is available only if Exim has been built to include an embedded Perl
interpreter. The subroutine name and the arguments are first separately
expanded, and then the Perl subroutine is called with those arguments. No
arguments need be given; the maximum number permitted is eight.
</P>
<P>
The return value of the subroutine is inserted into the expanded
string, unless the return value is <EM>undef</EM>. In that case, the
expansion fails in the same way as an explicit `fail' on a
lookup item. If the subroutine exits by calling Perl's <EM>die</EM> function,
the expansion fails with the error message that was passed to <EM>die</EM>.
</P>
<P>
More details of the embedded Perl facility are given in chapter 10.
</P>
<P>
<font color=green>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${sg{<<EM>subject</EM>>}{<<EM>regex</EM>>}{<<EM>replacement</EM>>}}</b>
</PRE>
<P>
<A NAME="IDX539"></A>
This item works like Perl's substitution operator (s) with the global (/g)
option; hence its name. It takes three arguments: the subject string, a regular
expression, and a substitution string. For example
<PRE>
${sg{abcdefabcdef}{abc}{xyz}}
</PRE>
<P>
yields `xyzdefxyzdef'. Because all three arguments are expanded before use, if
any $ or \ characters are required in the regular expression or in the
substitution string, they have to be escaped. For example
<PRE>
${sg {abcdef}{^(...)(...)\$}{\$2\$1}}
</PRE>
<P>
yields `defabc', and
<PRE>
${sg{1=A 4=D 3=C}{(\\d+)=}{K\$1=}}
</PRE>
<P>
yields `K1=A K4=D K3=C'.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${tr{<<EM>subject</EM>>}{<<EM>characters</EM>>}{<<EM>replacements</EM>>}}</b>
</PRE>
<P>
<A NAME="IDX540"></A>
This item does single-character translation on its subject string. The second
argument is a list of characters to be translated in the subject string. Each
matching character is replaced by the corresponding character from the
replacement list. For example
<PRE>
${tr{abcdea}{ac}{13}}
</PRE>
<P>
yields `1b3de1'. If there are duplicates in the second character string, the
last occurrence is used. If the third string is shorter than the second, its
last character is replicated. However, if it is empty, no translation takes
place.
</font>
</P>
<H2><A NAME="SEC179" HREF="spec_toc.html#TOC179">9.3 Expansion operators</A></H2>
<P>
<A NAME="IDX541"></A>
The following operations can be performed on portions of an expanded string.
The substring is first expanded before the operation is applied to it.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${domain:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX542"></A>
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.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${escape:<<EM>string</EM>>}</b>
</PRE>
<P>
If the string contains any non-printing characters, they are converted to
escape sequences starting with a backslash.
Whether characters with the most significant bit set (so-called `8-bit
characters') count as printing or not is controlled by the <EM>print_topbitchars</EM>
option.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${expand:<<EM>string</EM>>}</b>
</PRE>
<P>
The <EM>expand</EM> operator causes a string to be expanded for a second time. For
example,
<PRE>
${expand:${lookup{$domain}dbm{/some/file}{$value}}}
</PRE>
<P>
first looks up a string in a file while expanding the operand for <EM>expand</EM>, and
then re-expands what it has found.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${hash_<<EM>n</EM>>_<<EM>m</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX543"></A>
The two items <<EM>n</EM>> and <<EM>m</EM>> are numbers. If <<EM>n</EM>> is greater than or equal to
the length of the string, the operator returns the string. Otherwise it
computes a new string of length <<EM>n</EM>> by applying a hashing function to the
string. The new string consists of characters taken from the first <<EM>m</EM>>
characters of the string
<PRE>
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQWRSTUVWXYZ0123456789
</PRE>
<P>
and if <<EM>m</EM>> is not present the value 26 is used, so that only lower case
letters appear. These examples:
<PRE>
${hash_3:monty}
${hash_5:monty}
${hash_4_62:monty python}
</PRE>
<P>
yield
<PRE>
jmg
monty
fbWx
</PRE>
<P>
respectively. The abbreviation <EM>h</EM> can be used instead of <EM>hash</EM>.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${nhash_<<EM>n</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX544"></A>
<A NAME="IDX545"></A>
The string is processed by a hash function which returns a numeric value in the
<font color=green>
range 0--<<EM>n</EM>>-1.
</font>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${nhash_<<EM>n</EM>>_<<EM>m</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
The string is processed by a div/mod hash function which returns two numbers,
separated by a slash, in the ranges
<font color=green>
0--<<EM>n</EM>>-1 and 0--<<EM>m</EM>>-1,
</font>
respectively. For example,
<PRE>
${nhash_8_64:supercalifragilisticexpialidocious}
</PRE>
<P>
returns the string `6/33'.
</P>
<P>
<A NAME="IDX546"></A>
<A NAME="IDX547"></A>
<A NAME="IDX548"></A>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${lc:<<EM>string</EM>>}</b>
</PRE>
<P>
This forces the letters in the string into lower-case, for example:
<PRE>
${lc:$local_part}
</PRE>
<P>
<A NAME="IDX549"></A>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${uc:<<EM>string</EM>>}</b>
</PRE>
<P>
This forces the letters in the string into upper-case.
</P>
<PRE>
<b>${length_<<EM>number</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
The <EM>length</EM> 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
<PRE>
${length_50:$message_body}
</PRE>
<P>
The result of this operator is either the first <<EM>number</EM>> characters or the
whole string, whichever is the shorter. The abbreviation <EM>l</EM> can be used
instead of <EM>length</EM>.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${local_part:<<EM>string</EM>>}</b>
</PRE>
<P>
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.
</P>
<PRE>
<b>${mask:<<EM>IP address</EM>>/<<EM>bit count</EM>>}</b>
</PRE>
<P>
<A NAME="IDX550"></A>
<A NAME="IDX551"></A>
If the form of the string to be operated on is not an IP address followed by a
slash and an integer, the expansion fails. Otherwise, this operator converts
the IP address to binary, masks off the least significant bits according to the
bit count, and converts the result back to text, with mask appended. For
example,
<PRE>
${mask:10.111.131.206/28}
</PRE>
<P>
returns the string `10.111.131.192/28'. Since this operation is expected to be
mostly used for looking up masked addresses in files, the result for an IPv6
address uses fullstops (periods) to separate components instead of colons,
because colon terminates a key string in lsearch files. So, for example,
<PRE>
${mask:5f03:1200:836f:0a00:000a:0800:200a:c031/99}
</PRE>
<P>
returns the string
<PRE>
5f03.1200.836f.0a00.000a.0800.2000.0000/99
</PRE>
<P>
Letters in IPv6 addresses are always output in lower case.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${quote:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX552"></A>
The <EM>quote</EM> 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,
<PRE>
${quote:ab"*"cd}
</PRE>
<P>
becomes
<PRE>
"ab\"*\"cd"
</PRE>
<P>
The place where this is useful is when the argument is a substitution from a
variable or a message header.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${quote_<<EM>lookup-type</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX553"></A>
This operator applies lookup-specific quoting rules to the string. Each
query-style lookup type has its own quoting rules which are described with
the lookups in chapter 6. For example,
<PRE>
${quote_ldap:two + two}
</PRE>
<P>
returns `two%20%5C+%20two'. For single-key lookup types, no quoting is
necessary and this operator yields an unchanged string.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${rxquote:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX554"></A>
<A NAME="IDX555"></A>
The <EM>rxquote</EM> 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.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>${substr_<<EM>start</EM>>_<<EM>length</EM>>:<<EM>string</EM>>}</b>
</PRE>
<P>
<A NAME="IDX556"></A>
<A NAME="IDX557"></A>
The <EM>substr</EM> operator can be used to extract more general substrings than
<EM>length</EM>. It is followed by an underscore and the starting offset, then a
second underscore and the length required. For example
<PRE>
${substr_3_2:$local_part}
</PRE>
<P>
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 <EM>s</EM>
can be used instead of <EM>substr</EM>.
</P>
<P>
The <EM>substr</EM> 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,
<PRE>
${substr_-5_2:1234567}
</PRE>
<P>
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,
<PRE>
${substr_-5_2:12}
</PRE>
<P>
yields an empty string, but
<PRE>
${substr_-3_2:12}
</PRE>
<P>
yields `1'.
</P>
<P>
If the second number is omitted from <EM>substr</EM>, 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.
</P>
<H2><A NAME="SEC180" HREF="spec_toc.html#TOC180">9.4 Expansion conditions</A></H2>
<P>
<A NAME="IDX558"></A>
The following conditions are available for testing by the <EM>${if</EM> construct
while expanding strings:
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>!<<EM>condition</EM>></b>
</PRE>
<P>
Preceding any condition with an exclamation mark negates the result of the
condition.
</P>
<PRE>
<b><<EM>symbolic operator</EM>> {<<EM>string1</EM>>}{<<EM>string2</EM>>}</b>
</PRE>
<P>
<A NAME="IDX559"></A>
<A NAME="IDX560"></A>
There are a number of symbolic operators for doing numeric comparisons. They
are:
<PRE>
= equal
== equal
> greater
>= greater or equal
< less
<= less or equal
</PRE>
<P>
For example,
<PRE>
${if >{$message_size}{10M} ...
</PRE>
<P>
Note that the general negation operator provides for inequality testing.
The two strings must take the form of optionally signed decimal integers,
optionally followed by one of the letters `K' or `M' (in either upper or lower
case), signifying multiplication by 1024 or 1024*1024, respectively.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>def:<<EM>variable name</EM>></b>
</PRE>
<P>
The <EM>def</EM> condition must be followed by the name of one of the expansion
variables defined in section 5.
The condition is true if the named expansion variable does not contain the
empty string, for example
<PRE>
${if def:sender_ident {from $sender_ident}}
</PRE>
<P>
Note that the variable name is given without a leading <EM>$</EM> character.
If the variable does not exist, the expansion fails.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>def:header_<<EM>header name</EM>>: or def:h_<<EM>header name</EM>>:</b>
</PRE>
<P>
This condition is true if a message is being processed and the named header
exists in the message. For example,
<PRE>
${if def:header_reply-to:{$h_reply-to:}{$h_from:}}
</PRE>
<P>
Note that no <EM>$</EM> appears before <EM>header_</EM> or <EM>h_</EM> in the condition,
and that header names must be terminated by colons if white space does not
follow.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>exists {<<EM>file name</EM>>}</b>
</PRE>
<P>
The substring is first expanded and then interpreted as an absolute path.
The condition is true if the named file (or directory) exists. The existence
test is done by calling the <EM>stat()</EM> function.
The use of the <EM>exists</EM> test in users' filter files may be locked out by the
system administrator.
</P>
<PRE>
<b>eq {<<EM>string1</EM>>}{<<EM>string2</EM>>}</b>
</PRE>
<P>
<A NAME="IDX561"></A>
<A NAME="IDX562"></A>
The two substrings are first expanded. The condition is true if the two
resulting strings are identical, including the case of letters.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>crytpeq {<<EM>string1</EM>>}{<<EM>string2</EM>>}</b>
</PRE>
<P>
<A NAME="IDX563"></A>
This condition is included in the Exim binary if it is built to support any
authentication mechanisms (see chapter 35). Otherwise, it is
necessary to define SUPPORT_CRYPTEQ in <TT>`Local/Makefile'</TT> to get <EM>crypteq</EM>
included in the binary.
</P>
<P>
The <EM>crypteq</EM> condition has two arguments. The first is encrypted and compared
against the second, which is already encrypted. The second string may be in the
LDAP form for storing encrypted strings, which starts with the encryption type
in curly brackets, followed by the data. For example:
<PRE>
{md5}CY9rzUYh03PK3k6DJie09g==
</PRE>
<P>
If such a string appears directly in an expansion, the curly brackets have to
be quoted, because they are part of the expansion syntax. For example:
<PRE>
${if crypteq {test}{\{md5\}CY9rzUYh03PK3k6DJie09g==}{yes}{no}}
</PRE>
<P>
Two encryption types are currently supported:
</P>
<UL>
<LI>
<EM>md5</EM> first computes the MD5 digest of the string, and then expresses this
as printable characters by means of base64 encoding.
<LI>
<EM>crypt</EM> calls the <EM>crypt()</EM> function as used for encrypting login passwords.
</UL>
<P>
If the second string does not begin with `{' it is assumed to be encrypted with
<EM>crypt()</EM>, since such strings cannot begin with `{'. Typically this will be a
field from a password file.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>match {<<EM>string1</EM>>}{<<EM>string2</EM>>}</b>
</PRE>
<P>
The two substrings are first expanded. The second is then treated as a regular
expression and applied to the first. Because of the pre-expansion, if the
regular expression contains dollar, or backslash characters, they must be
escaped with backslashes. Care must also be taken if the regular expression
contains braces (curly brackets). A closing brace must be escaped so that it is
not taken as a premature termination of <<EM>string2</EM>>. It does no harm to escape
opening braces, but this is not strictly necessary. For example,
<PRE>
${if match {$local_part}{^\\d\{3\}} ...
</PRE>
<P>
If the whole expansion string is in double quotes, further escaping of
backslashes is also required.
</P>
<P>
The condition is true if the regular expression match succeeds. At the start of
an <EM>if</EM> expansion the values of the numeric variable substitutions $<EM>1</EM> etc.
are remembered. Obeying a <EM>match</EM> condition that succeeds causes them to be
reset to the substrings of that condition and they will have these values
during the expansion of the success string. At the end of the <EM>if</EM> expansion,
the previous values are restored. After testing a combination of conditions
using <EM>or</EM>, the subsequent values of the numeric variables are those of the
condition that succeeded.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>pam {<<EM>string1</EM>>:<<EM>string2</EM>>:...}</b>
</PRE>
<P>
<EM>Pluggable Authentication Modules</EM>
(<A HREF="http://ftp.at.kernel.org/pub/linux/libs/pam/">http://ftp.at.kernel.org/pub/linux/libs/pam/</A>) are a facility which is
available in the latest releases of Solaris and in some GNU/Linux
distributions. The Exim support, which is intended for use in conjunction with
the SMTP AUTH command, is available only if Exim is compiled with
<PRE>
SUPPORT_PAM=yes
</PRE>
<P>
in <TT>`Local/Makefile'</TT>. You probably need to add -<EM>lpam</EM> to EXTRALIBS, and in
some releases of GNU/Linux -<EM>ldl</EM> is also needed.
</P>
<P>
<font color=green>
The argument string is first expanded, and the result must be a colon-separated
list of strings. The PAM module is initialized with the service name `exim' and
the user name taken from the first item in the colon-separated data string
(i.e. <<EM>string1</EM>>). The remaining items in the data string are passed over in
response to requests from the authentication function. In the simple case there
will only be one request, for a password, so the data will consist of two
strings only.
</P>
<P>
There can be problems if any of the strings are permitted to contain colon
characters. In the usual way, these have to be doubled to avoid being taken as
separators. If the data is being inserted from a variable, the <EM>sg</EM> expansion
item can be used to double any existing colons. For example, the configuration
of a LOGIN authenticator might contain this setting:
<PRE>
server_condition = ${if pam{$1:${sg{$2}{:}{::}}}{yes}{no}}
</PRE>
<P>
</font>
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>first_delivery</b>
</PRE>
<P>
<A NAME="IDX564"></A>
<A NAME="IDX565"></A>
This condition, which has no data, is true during a message's first delivery
attempt. It is false during any subsequent delivery attempts.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>queue_running</b>
</PRE>
<P>
<A NAME="IDX566"></A>
This condition, which has no data, is true during delivery attempts that are
initiated by queue-runner processes, and false otherwise.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>or {{<<EM>cond1</EM>>}{<<EM>cond2</EM>>}...}</b>
</PRE>
<P>
The sub-conditions are evaluated from left to right. The condition is true if
any one of the sub-conditions is true.
For example,
<PRE>
${if or {{eq{$local_part}{spqr}}{eq{$domain}{testing.com}}}...
</PRE>
<P>
When a true sub-condition is found, the following ones are parsed but not
evaluated. If there are several `match' sub-conditions the values of the
numeric variables afterwards are taken from the first one that succeeds.
</P>
<PRE>
<font color=blue>______________________________________________________________</font>
<b>and {{<<EM>cond1</EM>>}{<<EM>cond2</EM>>}...}</b>
</PRE>
<P>
The sub-conditions are evaluated from left to right. The condition is true if
all of the sub-conditions are true.
If there are several `match' sub-conditions, the values of the numeric
variables afterwards are taken from the last one.
When a false sub-condition is found, the following ones are parsed but not
evaluated.
</P>
<P>
Note that <EM>and</EM> and <EM>or</EM> are complete conditions on their own, and precede
their lists of sub-conditions. Each sub-condition must be enclosed in
braces within the overall braces that contain the list. No repetition of <EM>if</EM>
is used.
</P>
<H2><A NAME="SEC181" HREF="spec_toc.html#TOC181">9.5 Expansion variables</A></H2>
<P>
<A NAME="IDX567"></A>
</P>
<P>
The variable substitutions that are available for use in expansion strings are:
</P>
<P>
$<EM>0</EM>, $<EM>1</EM>, etc: When a <EM>matches</EM> expansion condition succeeds, these
variables contain the captured substrings identified by the regular expression
during subsequent processing of the success string of the containing <EM>if</EM>
expansion item. They may also be set externally by some other matching process
which precedes the expansion of the string. For example, the commands available
in Exim filter files include an <EM>if</EM> command with its own regular expression
matching condition.
</P>
<P>
$<EM>address_file</EM>: When, as a result of aliasing or forwarding, a message is
directed to a specific file, this variable holds the name of the file when the
transport is running. For example, using the default configuration, if user
<EM>r2d2</EM> has a <TT>`.forward'</TT> file containing
<PRE>
/home/r2d2/savemail
</PRE>
<P>
then when the <EM>address_file</EM> transport is running, $<EM>address_file</EM> contains
`/home/r2d2/savemail'. At other times, the variable is empty.
</P>
<P>
$<EM>address_pipe</EM>: When, as a result of aliasing or forwarding, a message is
directed to a pipe, this variable holds the pipe command when the
transport is running.
</P>
<P>
<A NAME="IDX568"></A>
$<EM>authenticated_id</EM>: When a server successfully authenticates a client it may
be configured to preserve some of the authentication information in the
variable $<EM>authenticated_id</EM> (see chapter 35). For example, a
user/password authenticator configuration might preserve the user name for use
in the directors or routers.
</P>
<P>
<A NAME="IDX569"></A>
<A NAME="IDX570"></A>
$<EM>authenticated_sender</EM>:
When a client host has authenticated itself, Exim pays attention to the
AUTH= parameter on the SMTP MAIL command. Otherwise, it accepts the
syntax, but ignores the data. Unless the data is the string `<>', it is set
as the authenticated sender of the message, and the value is available during
delivery in the $<EM>authenticated_sender</EM> variable.
</P>
<P>
<font color=green>
<A NAME="IDX571"></A>
<A NAME="IDX572"></A>
$<EM>body_linecount</EM>:
When a message is being received or delivered, this variable contains the
number of lines in the message's body.
</font>
</P>
<P>
<A NAME="IDX573"></A>
$<EM>caller_gid</EM>: The group id under which the process that called Exim was
running. This is not the same as the group id of the originator of a message
(see $<EM>originator_gid</EM>). If Exim re-execs itself, this variable in the new
incarnation normally contains the Exim gid.
</P>
<P>
<A NAME="IDX574"></A>
$<EM>caller_uid</EM>: The user id under which the process that called Exim was
running. This is not the same as the user id of the originator of a message
(see $<EM>originator_uid</EM>). If Exim re-execs itself, this variable in the new
incarnation normally contains the Exim uid.
</P>
<P>
$<EM>compile_date</EM>: The date on which the Exim binary was compiled.
</P>
<P>
$<EM>compile_number</EM>: The building process for Exim keeps a count of the number
of times it has been compiled. This serves to distinguish different
compilations of the same version of the program.
</P>
<P>
$<EM>domain</EM>: When an address is being directed, routed, or delivered on its own,
this variable contains the domain. In particular, it is set during
user filtering, but not during system filtering, since a message may have many
recipients and the system filter is called just once.
</P>
<P>
For remote addresses, the domain that is being routed can change as routing
proceeds, as a result of router actions (see, for example, the <EM>domainlist</EM>
router). However, the value of $<EM>domain</EM> remains as the original domain. The
current routing domain can often be accessed by other means.
</P>
<P>
When a remote or local delivery is taking place, if all the addresses that are
being handled simultaneously contain the same domain, it is placed in
$<EM>domain</EM>. Otherwise this variable is empty. Transports should be restricted
to handling only one domain at once if its value is required at transport time
-- this is the default for local transports. For further details of the
environment in which local transports are run, see chapter 13.
</P>
<P>
<A NAME="IDX575"></A>
At the end of a delivery, if all deferred addresses have the same domain, it is
set in $<EM>domain</EM> during the expansion of <EM>delay_warning_condition</EM>.
</P>
<P>
Because configured address rewriting happens at the time a message is received,
$<EM>domain</EM> normally contains the value after rewriting. However, when a rewrite
item is actually being processed (see chapter 34) $<EM>domain</EM>
contains the domain portion of the address that is being rewritten; it can be
used in the expansion of the replacement address, for example, to rewrite
domains by file lookup.
</P>
<P>
<A NAME="IDX576"></A>
<A NAME="IDX577"></A>
When the <EM>smtp_etrn_command</EM> option is being expanded, $<EM>domain</EM> contains
the complete argument of the ETRN command (see section 48.6).
</P>
<P>
<font color=green>
$<EM>domain_data</EM>: When a director or a router has a setting of the <EM>domains</EM>
generic option, and that involves a lookup which succeeds, the data read by the
lookup is available during the running of the director or router as
$<EM>domain_data</EM>. In addition, if the driver directs or routes the address to a
transport, the value is available in that transport. In all other situations,
this variable expands to nothing.
</font>
</P>
<P>
$<EM>errmsg_recipient</EM>:
This is set to the recipient address of an error message while Exim is creating
it. It is useful if a customized error message text file is in use (see
chapter 39).
</P>
<P>
$<EM>home</EM>:
A home directory may be set during a local delivery, either by the transport or
by the director that handled the address. When this is the case, $<EM>home</EM>
contains its value and may be used in any expanded options for the transport.
The <EM>forwardfile</EM> director also makes use of $<EM>home</EM>. Full details are
given in chapter 24. When interpreting a user's filter file,
Exim is normally configured so that $<EM>home</EM> contains the user's home
directory.
When running a filter test via the -<EM>bf</EM> option, $<EM>home</EM> is set to the value
of the environment variable HOME.
</P>
<P>
$<EM>host</EM>:
<font color=green>
When the <EM>smtp</EM> transport is expanding its options for encryption using TLS,
$<EM>host</EM> contains the name of the host to which it is connected.
Likewise, when used in the client part of an authenticator configuration (see
chapter 35), $<EM>host</EM> contains the name of the server to which the
client is connected.
</font>
</P>
<P>
<A NAME="IDX578"></A>
<A NAME="IDX579"></A>
When used in a transport filter (see chapter 14) $<EM>host</EM>
refers to the host involved in the current connection.
</P>
<P>
When a local transport is run as a result of routing a remote address, this
variable is available to access the host name that the router defined. A router
may set up many hosts; in this case $<EM>host</EM> refers to the first one. It is
expected that this usage will be mainly via the domainlist router, setting up a
single host for batched SMTP output, for example.
</P>
<P>
$<EM>host_address</EM>:
<font color=green>
This variable is set to the remote host's IP address whenever $<EM>host</EM> is set
for a remote connection.
</font>
</P>
<P>
$<EM>host_lookup_failed</EM>:
This variable contains `1' if the message came from a remote host and there was
an attempt to look up the host's name from its IP address, but the attempt
failed. Otherwise the value of the variable is `0'.
</P>
<P>
$<EM>interface_address</EM>:
For a message received over a TCP/IP connection, this variable contains the
address of the IP interface that was used. See also the -<EM>oMi</EM> command line
option.
</P>
<P>
<A NAME="IDX580"></A>
<font color=green>
$<EM>key</EM>: When a domain, host, or address list is being searched, this variable
contains the value of the key, so that it can be inserted into strings for
query-style lookups. See section 6.4 for further details and an
example. In other circumstances this variable is empty.
</font>
</P>
<P>
$<EM>local_part</EM>: When an address is being directed, routed, or delivered on its
own, this variable contains the local part. If a local part prefix or suffix
has been recognized, it is not included in the value.
When a number of addresses are being delivered in a batch by a local
or remote transport, $<EM>local_part</EM> is not set.
</P>
<P>
When a message is being delivered to a pipe, file, or autoreply transport as a
result of aliasing or forwarding, $<EM>local_part</EM> is set to the local part of
the parent address.
</P>
<P>
Because configured address rewriting happens at the time a message is received,
$<EM>local_part</EM> normally contains the value after rewriting. However, when a
rewrite item is actually being processed (see chapter 34)
$<EM>local_part</EM> contains the local part of the address that is being rewritten;
it can be used in the expansion of the replacement address, for example, to
rewrite local parts by file lookup.
</P>
<P>
<font color=green>
$<EM>local_part_data</EM>: When a director or a router has a setting of the
<EM>local_parts</EM> generic option, and that involves a lookup which succeeds, the
data read by the lookup is available during the running of the director or
router as $<EM>local_part_data</EM>. In addition, if the driver directs or routes
the address to a transport, the value is available in that transport. In all
other situations, this variable expands to nothing.
</font>
</P>
<P>
$<EM>local_part_prefix</EM>: When an address is being directed or delivered locally,
and a specific prefix for the local part was recognized, it is available in
this variable. Otherwise it is empty.
</P>
<P>
$<EM>local_part_suffix</EM>: When an address is being directed or delivered locally,
and a specific suffix for the local part was recognized, it is available in
this variable. Otherwise it is empty.
</P>
<P>
$<EM>localhost_number</EM>: This contains the expanded value of the
<EM>localhost_number</EM> option. The expansion happens after the main options have
been read.
</P>
<P>
<A NAME="IDX581"></A>
$<EM>message_age</EM>:
This variable is set at the start of a delivery attempt to contain the number
of seconds since the message was received. It does not change during a single
delivery attempt.
</P>
<P>
<A NAME="IDX582"></A>
<A NAME="IDX583"></A>
$<EM>message_body</EM>: This variable contains the initial portion of a message's
body while it is being delivered, and is intended mainly for use in filter
files. The maximum number of characters of the body that are used is set by the
<EM>message_body_visible</EM> configuration option; the default is 500. Newlines are
converted into spaces to make it easier to search for phrases that might be
split over a line break.
</P>
<P>
<A NAME="IDX584"></A>
<A NAME="IDX585"></A>
$<EM>message_body_end</EM>: This variable contains the final portion of a message's
body while it is being delivered. The format and maximum size are as for
$<EM>message_body</EM>.
</P>
<P>
<A NAME="IDX586"></A>
<A NAME="IDX587"></A>
$<EM>message_body_size</EM>: When a message is being received or delivered, this
variable contains the size of the body in bytes. The count starts from the
character after the blank line that separates the body from the header.
Newlines are included in the count. See also $<EM>message_size</EM> and
$<EM>body_linecount</EM>.
</P>
<P>
$<EM>message_headers</EM>:
This variable contains a concatenation of all the header lines when a message
is being processed. They are separated by newline characters.
</P>
<P>
$<EM>message_id</EM>: When a message is being received or delivered, this variable
contains the unique message id which is used by Exim to identify the message.
</P>
<P>
$<EM>message_precedence</EM>: When a message is being delivered, the value of any
<EM>Precedence:</EM> header is made available in this variable. If there is no such
header, the value is the null string.
</P>
<P>
<A NAME="IDX588"></A>
<A NAME="IDX589"></A>
<font color=green>
$<EM>message_size</EM>: When a message is being received or delivered, this variable
contains its size in bytes. In most cases, the size includes those headers that
were received with the message, but not those (such as <EM>Envelope-to:</EM>) that are
added to individual deliveries as they are written.
However, there is one special case: during the expansion of the <EM>maildir_tag</EM>
option in the <EM>appendfile</EM> transport while doing a delivery in maildir format,
the value of $<EM>message_size</EM> is the precise size of the file that has been
written.
</font>
See also $<EM>message_body_size</EM> and $<EM>body_linecount</EM>.
</P>
<P>
$<EM>n0</EM> -- $<EM>n9</EM>: These variables are counters that can be incremented by means
of the <EM>add</EM> command in filter files.
</P>
<P>
$<EM>original_domain</EM>: When a top-level address is being processed for delivery,
this contains the same value as $<EM>domain</EM>. However, if a `child' address (for
example, generated by an alias, forward, or filter file) is being processed,
this variable contains the domain of the original address.
This differs from $<EM>parent_domain</EM> when there is more than one level of
aliasing or forwarding.
When more than one address is being delivered in a batch by a local or remote
transport, $<EM>original_domain</EM> is not set.
</P>
<P>
Address rewriting happens as a message is received. Once it has happened, the
previous form of the address is no longer accessible. It is the rewritten
top-level address whose domain appears in this variable.
</P>
<P>
$<EM>original_local_part</EM>: When a top-level address is being processed for
delivery, this contains the same value as $<EM>local_part</EM>. However, if a
`child' address (for example, generated by an alias, forward, or filter file)
is being processed, this variable contains the local part of the original
address.
This differs from $<EM>parent_local_part</EM> when there is more than one level of
aliasing or forwarding.
When more than one address is being delivered in a batch by a local or remote
transport, $<EM>original_local_part</EM> is not set.
</P>
<P>
Address rewriting happens as a message is received. Once it has happened, the
previous form of the address is no longer accessible. It is the rewritten
top-level address whose local part appears in this variable.
</P>
<P>
<A NAME="IDX590"></A>
<A NAME="IDX591"></A>
$<EM>originator_gid</EM>: The value of $<EM>caller_gid</EM> that was set when the message
was received. For messages received via the command line, this is the gid of
the sending user. For messages received by SMTP over TCP/IP, this is normally
the gid of the Exim user.
</P>
<P>
<A NAME="IDX592"></A>
<A NAME="IDX593"></A>
$<EM>originator_uid</EM>: The value of $<EM>caller_uid</EM> that was set when the message
was received. For messages received via the command line, this is the uid of
the sending user. For messages received by SMTP over TCP/IP, this is normally
the uid of the Exim user.
</P>
<P>
$<EM>parent_domain</EM>: This variable is empty, except when a `child' address
(generated by aliasing or forwarding, for example) is being processed, in which
case it contains the domain of the immediately preceding parent address.
</P>
<P>
$<EM>parent_local_part</EM>: This variable is empty, except when a `child' address
(generated by aliasing or forwarding, for example) is being processed, in which
case it contains the local part of the immediately preceding parent address.
</P>
<P>
<A NAME="IDX594"></A>
<A NAME="IDX595"></A>
$<EM>pipe_addresses</EM>: This is not an expansion variable, but is mentioned here
because the string `$pipe_addresses' is handled specially in the command
specification for the <EM>pipe</EM> transport and in transport filters. It cannot be
used in general expansion strings, and provokes an `unknown variable' error if
encountered.
</P>
<P>
$<EM>primary_hostname</EM>: The value set in the configuration file, or read by the
<EM>uname()</EM> function.
</P>
<P>
$<EM>prohibition_reason</EM>: This variable is set only during the expansion of
prohibition messages. See section 46.5 for details.
</P>
<P>
$<EM>qualify_domain</EM>: The value set for this option in the configuration file.
</P>
<P>
$<EM>qualify_recipient</EM>: The value set for this option in the configuration file,
or if not set, the value of $<EM>qualify_domain</EM>.
</P>
<P>
<font color=green>
$<EM>rbl_domain</EM>: While expanding <EM>prohibition_message</EM> when rejecting a
recipient because of an RBL failure (see section 46.5),
$<EM>rbl_domain</EM> contains the name of the RBL domain that caused the rejection.
</font>
</P>
<P>
<font color=green>
$<EM>rbl_text</EM>: While expanding <EM>prohibition_message</EM> when rejecting a
recipient because of an RBL failure (see section 46.5),
$<EM>rbl_text</EM> contains the text of a DNS TXT record that is associated with the
block, if one exists.
</font>
</P>
<P>
$<EM>received_for</EM>: If there is only a single recipient address in an incoming
message, then when the <EM>Received:</EM> header line is being built, this variable
contains that address. Otherwise it is empty.
</P>
<P>
$<EM>received_protocol</EM>: When a message is being processed, this variable
contains the name of the protocol by which it was received.
</P>
<P>
$<EM>recipients</EM>: This variable contains a list of envelope recipients for a
message, but is recognized only in the system filter file, to prevent exposure
of Bcc recipients to ordinary users. A comma and a space separate the
addresses in the replacement text.
</P>
<P>
$<EM>recipients_count</EM>: When a message is being processed, this variable contains
the number of envelope recipients that came with the message. Duplicates are
not excluded from the count.
</P>
<P>
$<EM>reply_address</EM>: When a message is being processed, this variable contains
the contents of the <EM>Reply-To:</EM> header line if one exists, or otherwise the
contents of the <EM>From:</EM> header line.
<font color=green>
However, if the message contains a set of <TT>`Resent-'</TT> header lines, their
contents are used in preference.
</font>
</P>
<P>
$<EM>return_path</EM>: When a message is being delivered, this variable contains the
return path -- the sender field that will be sent as part of the envelope. It
is not enclosed in <> characters. In many cases, $<EM>return_path</EM> has the
same value as $<EM>sender_address</EM>, but if, for example, an incoming message to
a mailing list has been expanded by a director which specifies a specific
address for delivery error messages, $<EM>return_path</EM> contains the new error
address, while $<EM>sender_address</EM> contains the original sender address that
was received with the message.
</P>
<P>
$<EM>return_size_limit</EM>: This contains the value set in the
<EM>return_size_limit</EM> option, rounded up to a multiple of 1000. It is useful
when a customized error message text file is in use (see chapter
39).
</P>
<P>
$<EM>route_option</EM>: A router may set up an arbitrary string to be passed to a
transport via this variable. Currently, only the <EM>queryprogram</EM> router has the
ability to do so.
</P>
<P>
$<EM>self_hostname</EM>:
The generic router option <EM>self</EM> can be set to the values `local' or
`fail_soft' (amongst others). These cause the address to be passed over to the
directors, as if its domain were a local domain, or to be passed on to
the next router, respectively. While subsequently directing or routing (and
doing any deliveries) $<EM>self_hostname</EM> is set to the name of the local host
that the router encountered. In other circumstances its contents are null.
</P>
<P>
$<EM>sender_address</EM>: When a message is being processed, this variable contains
the sender's address that was received in the message's envelope.
For delivery failure reports, the value of this variable is the empty string.
</P>
<P>
$<EM>sender_address_domain</EM>: The domain portion of $<EM>sender_address</EM>.
</P>
<P>
$<EM>sender_address_local_part</EM>: The local part portion of $<EM>sender_address</EM>.
</P>
<P>
$<EM>sender_fullhost</EM>: When a message is received from a remote host, this
variable contains the host name and IP address in a single string, which always
ends with the IP address in square brackets.
<font color=green>
If <EM>log_incoming_port</EM> is set, the port number on the remote host is added to
the IP address, separated by a full stop.
</font>
The format of the rest of the string depends on whether the host issued a
HELO or EHLO SMTP command, and whether the host name was verified by
looking up its IP address.
(Looking up the IP address can be forced by the <EM>host_lookup</EM> option,
independent of verification.)
A plain host name at the start of the string is a verified host name; if this
is not present, verification either failed or was not requested. A host name in
parentheses is the argument of a HELO or EHLO command. This is omitted
if it is identical to the verified host name or to the host's IP address in
square brackets.
</P>
<P>
$<EM>sender_helo_name</EM>: When a message is received from a remote host that has
issued a HELO or EHLO command, the first item in the argument of that
command is placed in this variable. It is also set if HELO or EHLO is
used when a message is received using SMTP locally via the -<EM>bs</EM> or -<EM>bS</EM>
options.
</P>
<P>
$<EM>sender_host_address</EM>: When a message is received from a remote host, this
variable contains that host's IP address.
<font color=green>
The value is set as soon as the connection is established, so it is available,
for example, during the expansion of <EM>prohibition_message</EM>.
</font>
</P>
<P>
$<EM>sender_host_authenticated</EM>:
During message delivery, this variable contains the name (not the public name)
of the authenticator driver which successfully authenticated the client from
which the message was received. It is empty if there was no successful
authentication.
</P>
<P>
$<EM>sender_host_name</EM>: When a message is received from a remote host, this
variable contains the host's name as verified by looking up its IP address. If
verification failed, or was not requested, this variable contains the empty
string.
</P>
<P>
<font color=green>
$<EM>sender_host_port</EM>: When a message is received from a remote host, this
variable contains the port number that was used on the remote host.
</font>
</P>
<P>
$<EM>sender_ident</EM>: When a message is received from a remote host, this variable
contains the identification received in response to an RFC 1413 request. When a
message has been received locally, this variable contains the login name of the
user that called Exim.
</P>
<P>
$<EM>sender_rcvhost</EM>: This is provided specifically for use in <EM>Received:</EM>
headers. It starts with either the verified host name (as obtained from a
<A NAME="IDX596"></A>
<A NAME="IDX597"></A>
reverse DNS lookup) or, if there is no verified host name, the IP address in
square brackets. After that there may be text in parentheses. When the first
item is a verified host name, the first thing in the parentheses is the IP
address in square brackets. There may also be items of the form
`helo=<EM>xxxx</EM>' if HELO or EHLO was used and its argument was not
identical to the real host name or IP address, and `ident=<EM>xxxx</EM>' if an RFC
1413 ident string is available. If all three items are present in the
parentheses, a newline and tab are inserted into the string, to improve the
formatting of the <EM>Received:</EM> header.
</P>
<P>
$<EM>sn0</EM> -- $<EM>sn9</EM>: These variables are copies of the values of the $<EM>n0</EM>
-- $<EM>n9</EM> accumulators that were current at the end of the system filter file.
This allows a system filter file to set values that can be tested in users'
filter files. For example, a system filter could set a value indicating how
likely it is that a message is junk mail.
</P>
<P>
$<EM>spool_directory</EM>: The name of Exim's spool directory.
</P>
<P>
$<EM>thisaddress</EM>: This variable is set only during the processing of the
<EM>foranyaddress</EM> command in a filter file. Its use is explained in the
description of that command.
</P>
<P>
<font color=green>
$<EM>tls_cipher</EM>: When a message is received from a remote host over an
encrypted SMTP connection, this variable is set to the cipher that was
negotiated, for example DES-CBC3-SHA. See chapter 38.
</font>
</P>
<P>
<font color=green>
$<EM>tls_peerdn</EM>: When a message is received from a remote host over an
encrypted SMTP connection, and Exim is configured to request a certificate from
the client, the value of the Distinguished Name of the certificate is made
available in the $<EM>tls_peerdn</EM> during subsequent processing.
</font>
</P>
<P>
$<EM>tod_bsdinbox</EM>: The time of day and date, in the format required for
BSD-style mailbox files, for example: Thu Oct 17 17:14:09 1995.
</P>
<P>
$<EM>tod_full</EM>: A full version of the time and date, for example: Wed, 16 Oct
1995 09:51:40 +0100. The timezone is always given as a numerical offset from
GMT.
</P>
<P>
$<EM>tod_log</EM>: The time and date in the format used for writing Exim's log
files, for example: 1995-10-12 15:32:29.
</P>
<P>
<A NAME="IDX598"></A>
$<EM>value</EM>: This variable contains the result of an expansion lookup operation,
as described above.
Also, if a <EM>domainlist</EM> router has a lookup pattern in a route item, $<EM>value</EM>
contains the data that was looked up during the expansion of the host list.
If $<EM>value</EM> is used in other circumstances, its contents are null.
</P>
<P>
$<EM>version_number</EM>: The version number of Exim.
</P>
<P>
$<EM>warnmsg_delay</EM>: This variable is set only during the creation of a message
warning about a delivery delay. Details of its use are explained in section
39.2.
</P>
<P>
$<EM>warnmsg_recipients</EM>: This variable is set only during the creation of a
message warning about a delivery delay. Details of its use are explained in
section 39.2.
<P><HR><P>
Go to the <A HREF="spec_1.html">first</A>, <A HREF="spec_8.html">previous</A>, <A HREF="spec_10.html">next</A>, <A HREF="spec_59.html">last</A> section, <A HREF="spec_toc.html">table of contents</A>.
</BODY>
</HTML>
|