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
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<!-- Copyright 1998 - 2014 Double Precision, Inc. See COPYING for -->
<!-- distribution information. -->
<refentry id="maildropfilter">
<info><author><firstname>Sam</firstname><surname>Varshavchik</surname><contrib>Author</contrib></author><productname>Courier Mail Server</productname></info>
<refmeta>
<refentrytitle>maildropfilter</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo class='manual'>Double Precision, Inc.</refmiscinfo>
</refmeta>
<refnamediv>
<refname>maildropfilter</refname>
<refpurpose>maildrop's filtering language</refpurpose>
</refnamediv>
<refsynopsisdiv>
<informalexample>
<simpara>
<filename>@withetcdir@/maildroprc</filename>,
<filename>$HOME/.mailfilter</filename>,
<filename>$HOME/.mailfilters/*</filename>, and friends...
</simpara>
</informalexample>
</refsynopsisdiv>
<refsect1 id="maildropfilter_description">
<title>DESCRIPTION</title>
<para>
This manual page describes the language used by <command>maildrop</command>
to filter E-mail messages.
The mail filtering instructions are read from a file.
The language is loosely structured, it is based on pattern
matching. The language has a distinct lexical and syntactical structure,
very similar to Perl's, but it is important to note that it is not Perl,
and is very different from Perl, in certain cases.</para>
<para>
If the filtering instructions do not exist,
<command>maildrop</command> delivers the
message to the default mailbox without doing any additional processing,
making it indistinguishable from the usual mail delivery agent.</para>
<para>
It is important to note that <command>maildrop</command> reads and parses the
<systemitem class="resource">filter file</systemitem> before doing anything. If there are any errors
<command>maildrop</command> prints an error message, and terminates with the exit code
set to <errorcode>EX_TEMPFAIL</errorcode>. A compliant mail transport agent
should
re-queue the message for a later delivery attempt. Hopefully, most simple
syntax errors will not cause mail to be bounced back if the error is caught
and fixed quickly.</para>
<refsect2 id="maildropfilter_environment">
<title>Environment</title>
<para>
<anchor id="environment"/>
<command>maildrop</command> uses variables to access and manipulate messages.
Variables
are arbitrary text accessed by referring to the name of the variable, such as
<varname>HOME</varname>, or <varname>DEFAULT</varname>.
Text is placed into a variable by
using an assignment statement, such as:
</para>
<blockquote>
<informalexample>
<programlisting>
FILE="IN.junk"
</programlisting>
</informalexample>
</blockquote>
<para>
This statement puts the text "IN.junk" (without the quotes) into a variable
whose name is <varname>FILE</varname>.
Later, the contents of a variable are accessed by using
the $ symbol and the name for the variable. For example:</para>
<blockquote>
<informalexample>
<programlisting>
to $FILE
</programlisting>
</informalexample>
</blockquote>
<para>
This will deliver the current message to the mailbox file (or a maildir
directory) named "IN.junk".</para>
<para>
<command>maildrop</command> initially creates variables from the environment
variables
of the operating system, UNLESS <command>maildrop</command> runs in delivery mode.
Each
operating system environment variable becomes a <command>maildrop</command>
variable.
When running in delivery mode, <command>maildrop</command> does not import the
environment for security reasons,
except for the environment variables that define the process locale
(<varname>LANG</varname>,
<varname>LANGUAGE</varname>, and
<varname>LC_<replaceable>*</replaceable></varname>), which are still imported.
</para>
<para>
In all cases <command>maildrop</command> resets the
following variables to their default values: <varname>HOME</varname>,
<varname>DEFAULT</varname>, <varname>SHELL</varname>,
<varname>PATH</varname>, <varname>LOCKEXT</varname>,
<varname>LOCKREFRESH</varname>, <varname>LOCKSLEEP</varname>,
<varname>LOCKTIMEOUT</varname>, <varname>MAILDIRQUOTA</varname>,
<varname>SENDMAIL</varname> and <varname>LOGNAME</varname>.</para>
<para>
There's one exception to this rule which applies to the version of
<command>maildrop</command> that comes with the
<ulink url="http://www.courier-mta.org/"><application>Courier</application> mail server</ulink>. The following
does not apply to the standalone version of <command>maildrop</command>:
when running in
delivery mode, if the <option>-d</option> flag was not used, or if it specifies
the same userid as the one that's running <command>maildrop</command>:
the following
variables are automatically imported from the environment: <varname>HOME</varname>, <varname>SHELL</varname>,
<varname>LOGNAME</varname> and <varname>MAILDIRQUOTA</varname>.
These environment variables are
initialized by the <application>Courier</application>
mail server prior to running <command>maildrop</command>.
Additionally, the
initial value for the <varname>DEFAULT</varname> maildrop variable is imported from
the <varname>MAILDROPDEFAULT</varname> environment variable. This is because
the <application>Courier</application> mail server overloads the
DEFAULT environment variable to store the defaulted
portion of the local mailbox address. See the <ulink url="dot-courier.html"><citerefentry><refentrytitle>dot-courier</refentrytitle><manvolnum>5</manvolnum></citerefentry></ulink> man page in the
<application>Courier</application> mail server
distribution. You can get the <application>Courier</application>
mail server's <varname>DEFAULT</varname> value by
using the
<command>import</command> command.
Note, however, that this will clobber the old
contents of <varname>DEFAULT</varname>, which is probably not what you want.
The right way to do this would be something like this:</para>
<blockquote>
<informalexample>
<programlisting>
SAVEDEFAULT=$DEFAULT
import DEFAULT
LOCALDEFAULT=$DEFAULT
DEFAULT=$SAVEDEFAULT
</programlisting>
</informalexample>
</blockquote>
<para>All internal variables are exported back as environment variables when
<command>maildrop</command> runs an external command. Changes to internal variables, made
by the <systemitem class="resource">filter file</systemitem>, are reflected in the exported environment.</para>
</refsect2>
<refsect2 id="maildropfilter_lexical_structure">
<title>Lexical structure</title>
<para>
Most whitespace is generally ignored. The <token>#</token>
character introduces a comment
running to the end of the line, which is also ignored. Unlike other mail
filters, <command>maildrop</command> parses the
<systemitem class="resource">filter file</systemitem> before taking any action
with the message.
If there are syntax errors in the file, <command>maildrop</command> displays
an error message, and returns <errorcode>EX_TEMPFAIL</errorcode>. That should
cause the
mail message to remain in the queue, and, hopefully allow the problem to be
corrected, without bouncing any mail.</para>
<note>
<para>
In <command>maildrop</command>, the end of line is a lexical token. In order to
continue a long statement on the next line, terminate the line with a
backslash character.</para></note>
</refsect2>
<refsect2 id="maildropfilter_literal_text">
<title>Literal text</title>
<para>
Literal text in the <command>maildrop</command> filtering language is
surrounded by
either single or double quotes. In order to enter a single quote into a text
literal surrounded by single quotes, or a double quote into a literal
surrounded by double quotes, prefix it with a backslash character. Use two
backslash characters characters to enter one backslash character in the text
literal.</para>
<note>
<para>A backslash followed by either a backslash, or a matching quote, is
the only situation where the backslash character is actually removed, leaving
only the following character in the actual text literal. If a backslash
character is followed by any other character, the backslash is NOT
removed.</para>
</note>
<para>Multiple text literals in a row are automatically concatenated, even if
they use different quotes. For example:</para>
<blockquote>
<informalexample>
<programlisting>
FOOBAR="Foo"'bar'
</programlisting>
</informalexample>
</blockquote>
<para>
This sets the variable <varname>FOOBAR</varname> to the text "Foobar".
</para>
</refsect2>
<refsect2 id="maildropfilter_variable_substitution">
<title>Variable substitution</title>
<para>
<anchor id="varsubst"/>
Variable substitution is performed on text literals that's surrounded by
double quotation marks. The "<token>$</token>" character, followed by a variable name,
is replaced by that variable's contents.
</para>
<blockquote>
<informalexample>
<programlisting>
MAILBOX="$HOME/Mailbox"
</programlisting>
</informalexample>
</blockquote>
<para>
This sets the variable <varname>MAILBOX</varname> to the contents of the
variable
<varname>HOME</varname> followed by <literal>"/Mailbox"</literal>.
Variable names must begin with an
uppercase letter, a lowercase letter, or an underscore.
Following that, all
letters, digits, and underscores are taken as a variable name, and its
contents replace the <token>$</token> sign, and the variable name. It is possible to access
variables whose name includes other characters, by using braces as
follows:</para>
<blockquote>
<informalexample>
<programlisting>
MAILBOX="${HOME-WORD}/Mailbox"
</programlisting>
</informalexample>
</blockquote>
<para>
Inserts the contents of the <varname>HOME-WORD</varname> variable. If the
variable
does not exist, the empty text literal is used to replace the variable name.
It is not possible to access variables whose names include the <token>}</token>
character.</para>
<para>If the <token>$</token> character is not followed by a left brace, letter, or an
underscore, the <token>$</token> character remains unmolested in the text literal. A
backslash followed by the <token>$</token> character results in a <token>$</token> character in the text
literal, without doing any variable substitution.</para>
<para>
Variable substitution is not done in text literals which are surrounded by
single quotes (apostrophes).</para>
</refsect2>
<refsect2 id="maildropfilter_command_line_arguments">
<title>Command line arguments</title>
<para>
<command>maildrop</command> initializes special variables:
<varname>$1</varname>, <varname>$2</varname>, and so on, with
additional parameters specified on the <command>maildrop</command>
command line. A <systemitem class="resource">filter file</systemitem>
may use those variables just like any other variables.</para>
</refsect2>
<refsect2 id="maildropfilter_predefined_variables">
<title>Predefined variables</title>
<anchor id="predefined"/>
<para>
The following variables are automatically defined by
<command>maildrop</command>. The
default values for the following variables may be changed by the system
administrator. For security reasons, the values of the following variables
are always reset to their default values, and are never imported from the
environment:</para>
<variablelist>
<varlistentry><term><varname>DEFAULT</varname></term><listitem><para>The default mailbox to deliver the message to.
If the <systemitem class="resource">filter file</systemitem> does not indicate a mailbox to deliver this message
to, the message is delivered to this mailbox. The default mailbox is
defined by the system administrator.
</para></listitem></varlistentry>
<varlistentry><term><varname>FROM</varname></term><listitem><para>Message envelope sender. This is usually the same
address as what appears in the <literal>From:</literal> header, but may
not be.
This information may or may not be available to <command>maildrop</command> on your
system. The message envelope sender is usually specified with the <option>-f</option>
option to <command>maildrop</command>. If the <option>-f</option> option is not given, <command>maildrop</command>
looks for the <literal>Return-Path:</literal> header in the message. As the last resort,
<literal>FROM</literal> defaults to <quote>MAILER-DAEMON</quote>.
Note that <varname>FROM</varname> may be empty - the message envelope sender is
empty for bounce messages.
</para></listitem></varlistentry>
<varlistentry><term><varname>HOME</varname></term><listitem><para>Home directory of the user running
<command>maildrop</command>.
</para></listitem></varlistentry>
<varlistentry><term><varname>HOSTNAME</varname></term><listitem><para>Network name of the machine running maildrop.
Obtained from <citerefentry><refentrytitle>gethostname</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para></listitem></varlistentry>
<varlistentry><term><varname>LOCKEXT</varname></term><listitem><para>Extension for dot-lock files (default: <literal>.lock</literal>).
</para></listitem></varlistentry>
<varlistentry><term><varname>LOCKREFRESH</varname></term><listitem><para>Refresh interval, in seconds, for dot-locks
(default: <literal>15</literal>). When <command>maildrop</command> dot-locks a mailbox, <command>maildrop</command>
tries to refresh the lock periodically in order to keep other programs
from removing a stale dot-lock. This is only required if a dot-lock
exists for a prolonged period of time, which should be discouraged
anyway.
</para></listitem></varlistentry>
<varlistentry><term><varname>LOCKSLEEP</varname></term><listitem><para>Number of seconds to wait to try again to
create a dot-lock file, if one already exists (default: 5).
</para></listitem></varlistentry>
<varlistentry><term><varname>LOCKTIMEOUT</varname></term><listitem><para>Number of seconds to wait before removing a
stale dot-lock file (default: <literal>60</literal>). If a dot-lock file still exists after
<varname>LOCKTIMEOUT</varname> seconds, <command>maildrop</command> assumes that the
process holding the lock no longer exists, and the dot-lock file can be
safely removed. After removing the dot-lock file, <command>maildrop</command> waits
<varname>LOCKSLEEP</varname> seconds before trying to create its own dot-lock
file, in order to avoid a race condition with another process which is
also trying to remove the same stale dot-lock, at the same time.
</para></listitem></varlistentry>
<varlistentry><term><varname>LOGNAME</varname></term><listitem><para>Name of the user to who the message is being
delivered.
</para></listitem></varlistentry>
<varlistentry>
<term><varname>MAILDROP_OLD_REGEXP</varname></term>
<listitem>
<para>
Revert to using the old legacy pattern matching engine.
Versions of <command>maildrop</command> prior to version 2.0
(included in the <application>Courier</application> mail server 0.51,
and earlier), used a built-in pattern matching engine, instead of using the
<acronym>PCRE</acronym>
library (see the
<quote><link linkend="patterns">Patterns</link></quote>
section).
<command>maildrop</command> 1.x used a different syntax for patterns, which
is no longer described in this manual page.
The old pattern matching engine is still available, by
setting <varname>MAILDROP_OLD_REGEXP</varname> to <quote>1</quote>.
Setting this variable will use the legacy pattern matching engine for the
rest of the <command>maildrop</command> recipe file.</para>
<para>
The pattern matching engine will be removed completely in a future version
of maildrop.
This setting provides for a transitional period of converting old recipes.
<varname>MAILDROP_OLD_REGEXP</varname> can be set to <quote>1</quote> in
the global <filename>maildroprc</filename> file, then reset to <quote>0</quote>
in each individual <command>maildrop</command> recipe file, after it gets
converted to the new syntax.</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>MAILFILTER</varname></term><listitem><para>This is the name of the original <systemitem class="resource">filter file</systemitem>
that was given to <command>maildrop</command> on the command line. This is mostly
useful to <literal>-default</literal> <systemitem class="resource">filter file</systemitem>s, it allows them to
obtain the <ulink url="maildrop.html#moption">value of the -M option</ulink>
specified on the command line.
</para></listitem></varlistentry>
<varlistentry><term><varname>PATH</varname></term><listitem><para>Command execution path. <command>maildrop</command> resets PATH
to the system default (usually
<literal>/bin:/usr/bin:/usr/local/bin</literal>).
</para></listitem></varlistentry>
<varlistentry><term><varname>SENDMAIL</varname></term><listitem><para>The mail delivery agent.
When <command>maildrop</command> is
instructed to deliver the message to a mailbox whose name begins with the
! character, this is interpreted as a request to forward the message. The
<varname>SENDMAIL</varname> command is executed to forward the message.
</para></listitem></varlistentry>
<varlistentry><term><varname>SHELL</varname></term><listitem><para>The login shell. The shell is used to execute all
commands invoked by <command>maildrop</command>.
</para></listitem></varlistentry>
<varlistentry><term><varname>VERBOSE</varname></term><listitem><para>Current Debug level (default: <literal>0</literal>). Setting <varname>VERBOSE</varname> to
progressive higher values, between 1 and 9, produces debugging output on
standard error. <command>maildrop</command> ignores
the <varname>VERBOSE</varname> variable in delivery
mode (in order not to confuse the mail transport agent).
</para></listitem></varlistentry>
<varlistentry><term><varname>UMASK</varname></term><listitem><para>The file creation mode mask, in octal. The
default setting of <literal>077</literal> creates mailboxes that are readable and writable
by the owner only. Use <literal>007</literal> to create mailboxes that are
readable/writable by both owner and the group. Use <literal>037</literal>
to create
mailboxes that are readable by both owner and group, but writable by
owner only. Permissions on existing mailboxes are not changed, this
setting affects only new mailboxes. When delivering to maildirs this
setting sets the permissions on new messages only. Access permissions on
messages in maildirs are also affected by the permissions on the maildir
directories.
</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2 id="maildropfilter_other_special_variables">
<title>Other special variables</title>
<para>
The following variables are automatically used by <command>maildrop</command> when the
<systemitem class="resource">filter file</systemitem> is being processed:
</para>
<variablelist>
<varlistentry><term><varname>EXITCODE</varname></term>
<listitem><para>Return code for <command>maildrop</command>. When
<command>maildrop</command> successfully delivers a message, it terminates with this
exit code, which defaults to 0. When the <command>to</command> or the
<command>cc</command> command is used to deliver the message to an external
process, via a pipe, <command>maildrop</command> will set this variable to the exit
code of the external process. Since <command>maildrop</command> immediately
terminates after completing the <command>to</command> command this means that
<command>maildrop</command>'s exit code will be the exit code of the external
process. If the <command>to</command> command does not deliver the message to a
process you must set <varname>EXITCODE</varname> before the <command>to</command>
command, since <command>maildrop</command> terminates immediately after finishing the
delivery.
</para></listitem></varlistentry>
<varlistentry><term><varname>FLAGS</varname></term>
<listitem>
<para>
The <varname>FLAGS</varname> variable is used only when delivering
a message to a maildir, and may contain only the following
letters: <quote>D</quote>, <quote>F</quote>,
<quote>R</quote>, and <quote>S</quote>. They may appear in
any order. When the message gets delivered to the maildir,
the message will be marked with a draft, flag, replied, or seen,
attribute, correspondingly.
</para>
<para>
<varname>FLAGS</varname> must be set before the message is
delivered to a maildir.
The contents of <varname>FLAGS</varname> are ignored, when
delivering on
an mbox folder.
</para>
</listitem>
</varlistentry>
<varlistentry><term><varname>KEYWORDS</varname></term>
<listitem>
<para>
The <varname>KEYWORDS</varname> variable is used only when delivering a
message to a maildir, and implements the optional IMAP keyword extension
as implemented in the
<ulink url="http://www.courier-mta.org/"><application>Courier</application> IMAP server</ulink>.
It may be optionally initialized to contain a comma-separate list of keywords.
The <link linkend="to"><command>to</command></link>, or the
<link linkend="cc"><command>cc</command></link> command, delivers the message
to the maildir normally, but also associated the list of keywords in
<varname>KEYWORDS</varname> with the newly delivered message.</para>
<para>
<varname>KEYWORDS</varname> must be set before the message is delivered to
a maildir.
The contents of <varname>KEYWORDS</varname> are ignored, when delivering on
an mbox folder.
</para></listitem></varlistentry>
<varlistentry><term><varname>LINES</varname></term><listitem><para>Number of lines in the current message. Note that
this may be an approximation. It may or may not take into account the -A
option. Use this as criteria for filtering,
nothing more.
</para></listitem></varlistentry>
<varlistentry><term><varname>MAILDIRQUOTA</varname></term><listitem><para>Set this variable in order to manually
enforce a maximum size on ANY maildir where the message is delivered.
This is an optional feature that must be enabled by the system
administrator, see <ulink url="maildirquota.html"><citerefentry><refentrytitle>maildirquota</refentrytitle><manvolnum>8</manvolnum></citerefentry></ulink> for
more information.
</para></listitem></varlistentry>
<varlistentry><term><varname>RETURNCODE</varname></term><listitem><para>This variable is set when <command>maildrop</command>
runs the
<ulink url="#system">system</ulink> command,
<ulink url="#xfilter">xfilter</ulink> command, or a command that's
specified within a pair of backtick characters ( command substitution ).
The <varname>RETURNCODE</varname> variable will be set to the exit code of the
command, after it completes.
</para></listitem></varlistentry>
<varlistentry><term><varname>SIZE</varname></term><listitem><para>Number of bytes in the message. This may or may not
include the -A option. Use this as a criteria
for filtering, nothing more.</para></listitem></varlistentry>
</variablelist>
</refsect2>
<refsect2 id="maildropfilter_unquoted_text">
<title>Unquoted text</title>
<para>
All text strings in <systemitem class="resource">filter file</systemitem>s should be in single, or double quotes.
However, for convenience sake, quotes can be omitted under certain
circumstances.</para>
<para>
Text that includes ONLY letters, digits, and the following characters:
<literal>_-.:/${}@</literal> may appear without quotes. Note that this does not
allow spaces, or backslashes to be entered, however the text is still
variable-substituted, and the substituted text may contain other
characters.</para>
<para>
Also, note that patterns (see below) begin with the slash character.
Normally, anything that begins with the slash is interpreted as a pattern.
However, text immediately after <quote>VARIABLE=</quote> is interpreted as a
string even if it begins with a slash. This is why something like:</para>
<blockquote>
<informalexample>
<programlisting>
MAILDIR=/var/mail
</programlisting>
</informalexample>
</blockquote>
<para>
works as expected. Using quotes, though, is highly recommended. You must use
quotes to set a variable to a lone slash, because an unquoted slash is
interpreted as a division sign.</para>
<para>
Long double or singly-quoted text can be broken across multiple lines by
ending the line with a lone backslash character, like this:</para>
<blockquote>
<informalexample>
<programlisting>
TEXT="This is a long \
text string"
</programlisting>
</informalexample>
</blockquote>
<para>
The backslash, the newline, and all leading whitespace on the next line is
removed, resulting in "This is a long text string".</para>
</refsect2>
<refsect2 id="maildropfilter_command_substitution">
<title>Command substitution</title>
<para>
Text enclosed in back-tick characters is interpreted as a shell command. The
shell command is executed as a child process by <command>maildrop</command>.
Its output is used in place of the command. For example:</para>
<blockquote>
<informalexample>
<programlisting>
DIR=`ls`
</programlisting>
</informalexample>
</blockquote>
<para>
places the names of the files in the current directory into the DIR
variable.</para>
<para>
The output of the command will have all newline characters replaced by
spaces, and leading and trailing spaces will be stripped (multiple spaces are
not removed, though). Also, the contents of the message being delivered is
made available to the command on standard input.</para>
</refsect2>
<refsect2 id="maildropfilter_patterns">
<title>Patterns</title>
<anchor id="patterns"/>
<para>
The pattern syntax in <command>maildrop</command> is similar to the
<command>grep</command> command's syntax, with some minor differences.
A pattern takes the following
form in the <systemitem class="resource">filter file</systemitem>:</para>
<blockquote>
<informalexample>
<programlisting>
/<replaceable>pattern</replaceable>/:<replaceable>options</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
<replaceable>pattern</replaceable> specifies the text to look for in the
message, in the <literal>UTF-8</literal> codeset.
<replaceable>pattern</replaceable> must not begin with a space,
otherwise the leading slash will then be
interpreted as a division sign. If you must search for text that starts
with a space, use something like <literal>"/[ ] ... /"</literal>.
</para>
<para>
The general syntax of <command>maildrop</command>'s patterns is
described in the <citerefentry>
<refentrytitle>pcrepattern</refentrytitle>
<manvolnum>3</manvolnum></citerefentry>
manual page, with certain exceptions
noted below.
<command>maildrop</command> uses the
<ulink url="http://www.pcre.org">PCRE</ulink>
library to implement pattern matching.
Not all features in <acronym>PCRE</acronym> are available in
<command>maildrop</command>, and
the <quote>options</quote> part, which follows the pattern
specification, changes the pattern matching further.
Consult the
<citerefentry>
<refentrytitle>pcrepattern</refentrytitle>
<manvolnum>3</manvolnum></citerefentry>
manual page for more information, but note the following
exceptions:
</para>
<itemizedlist>
<listitem>
<para>
Internal options settings are not supported (but see the
<quote>D</quote> maildrop option, below).
Do not include option settings in the
<replaceable>pattern</replaceable>,
doing so will lead to undefined results.</para>
</listitem>
<listitem>
<para>
Named subpatterns are not implemented.
Numbered subpatterns are implemented, see
<quote><link linkend="patmatch">Pattern Match Results</link></quote>,
below.
</para>
</listitem>
<listitem>
<para>
The search pattern gets executed not against the raw message text,
but the message transcoded into a canonical UTF-8-based format.
This process involves transcoding any non-UTF-8 message content
into UTF-8. Additionally, message headers get converted into a
canonical format before the search pattern gets executed.
</para>
<para>
For structured headers with email addresses, the process involves
removing extraneous punctuation, or adding missing ones (in
situations where a missing punctuation character can be deduced).
Additionally certain pre-RFC822 obsolete header formats get
converted to canonical form.
</para>
<para>
This means that header search patterns that include punctuation
character may appear not to work against obviously-matching
message text. Use <quote>reformime -u <message.txt</quote>,
with <filename>message.txt</filename> containing the sample message,
to see exactly the actual text that gets searched by patterns.
</para>
</listitem>
</itemizedlist>
</refsect2>
<refsect2 id="maildropfilter_pattern_options">
<title>Pattern options</title>
<anchor id="options"/>
<para>
Following <literal>/<replaceable>pattern</replaceable>/,</literal>
there may be an optional colon, followed by one. or
more options. The following options may be specified in any order:</para>
<variablelist>
<varlistentry>
<term><literal>h</literal></term>
<listitem>
<para>
Match this pattern in the message's header, and the
header of any attachments in the message.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>H</literal></term>
<listitem>
<para>
Match this pattern in the message's main header. Do not match
this pattern in the headers of the message's attachments.
</para>
</listitem>
</varlistentry>
<varlistentry><term><literal>b</literal></term>
<listitem>
<para>Match this pattern against the message body.</para>
</listitem></varlistentry>
<varlistentry><term><literal>D</literal></term>
<listitem>
<para>This is a case sensitive match. Normally the patterns match either
uppercase or lowercase text. <literal>/john/</literal> will match "John",
"john", or "JOHN". Specify the D option for a case-sensitive search:
lowercase letters in the pattern must match lowercase letters in the
message; ditto for uppercase.</para>
</listitem></varlistentry>
</variablelist>
<para>
If neither 'h', 'H', or 'b' is specified, 'h' is the default,
matching the pattern in the message's header, and all attachments'
headers. Specifying the 'b' option causes the pattern to be matched
against the message body.
Specifying 'b' and 'h' causes the pattern to be matched
against the entire message.
</para>
<para>
Normally, each line in the message gets matched against the pattern
individually. When applying patterns to a header, multi-line headers (headers
split on several lines by beginning each continuation line with whitespace)
are silently combined into a single line, before the pattern is applied.</para>
</refsect2>
<refsect2 id="maildropfilter_mime_encoding">
<title>MIME encoding</title>
<para>
The pattern must be a valid text string in the <literal>UTF-8</literal>
codeset, and <command>maildrop</command> should handle messages
that use MIME encodings in other known character sets.
<link linkend="options">Options</link> that specify a
message header search
result in <command>maildrop</command> searching the initial message
headers, and any headers of additional MIME sections, in a multipart
MIME message. Options that specify a message body search will search
through all "text" MIME content.
</para>
<para>
For a MIME search to succeed, the message must be a well-formed MIME
message (with a Mime-Version: 1.0 header).
</para>
</refsect2>
<refsect2 id="maildropfilter_weighted_scoring">
<title>Weighted scoring</title>
<para>
Patterns are evaluated by <command>maildrop</command> as any other numerical
expression. If a pattern is found, <command>maildrop</command>'s filter
interprets the
results of the pattern match as number 1, or true, for filtering purposes. If
a pattern is not found the results of the pattern search is zero. Once a
pattern is found, the search stops. Second, and subsequent occurrences of the
same pattern are NOT searched for.</para>
<para>
<command>maildrop</command> can also do weighted scoring. In weighted scoring,
multiple occurrences of the same pattern are used to calculate a numerical
score.</para>
<para>
To use a weighted search, specify the pattern as follows:</para>
<blockquote>
<informalexample>
<programlisting>
/<replaceable>pattern</replaceable>/:<replaceable>options</replaceable>,<replaceable>xxx</replaceable>,<replaceable>yyy</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
where <replaceable>xxx</replaceable> and <replaceable>yyy</replaceable> are
two numbers. <replaceable>yyy</replaceable> is optional -- it will
default to 1, if missing.</para>
<para>The first occurrence of the pattern is evaluated as xxx. The second
occurrence of the pattern is evaluated as xxx*yyy, the third as xxx*yyy*yyy,
etc... All occurrences of the pattern are added up to calculate the final
score.</para>
<note>
<para>
<command>maildrop</command> does not
recognize multiple occurrences of the same pattern in the same line.
Multiple occurences of the same pattern in one line count as one
occurence.</para>
</note>
</refsect2>
<refsect2 id="maildropfilter_pattern_match_results">
<title>Pattern Match Results</title>
<anchor id="patmatch"/>
<para>
After a pattern is successfully matched, the actual text that is matched
is placed in the <varname>MATCH</varname> variable. For example:</para>
<blockquote>
<informalexample>
<programlisting>
/^From:.*/
</programlisting>
</informalexample>
</blockquote>
<para>
matches a line of the form:
</para>
<blockquote>
<informalexample>
<programlisting>
From: postmaster@localhost
</programlisting>
</informalexample>
</blockquote>
<para>
Here the variable <varname>MATCH</varname> will be set to "From:
postmaster@localhost", which can be used in subsequent statements.</para>
<para>
If the pattern contains subpatterns, the portions of the text that match
the first subpattern is placed in the <varname>MATCH1</varname> variable.
The second subpattern, if any, is placed in <varname>MATCH2</varname>, and
so on:</para>
<blockquote>
<informalexample>
<programlisting>
/^From:\s+(.*)@(.*)/
</programlisting>
</informalexample>
</blockquote>
<para>
matched against the same line will set <varname>MATCH</varname> to
<quote>From: postmaster@localhost</quote>,
<varname>MATCH1</varname> to <quote>postmaster</quote>, and
<varname>MATCH2</varname> to <quote>localhost</quote>.
Of course, in real world the <quote>From:</quote> header is usually much
more complicated, and can't be handled that easily.
This is just an illustrative example.</para>
<note>
<para>
Subpatterns are not processed in the <literal>foreach</literal>
statement.</para>
</note>
</refsect2>
<refsect2 id="conversion">
<title>Conversion of <command>maildrop</command> 1.x patterns to 2.0</title>
<para>
Although the new <acronym>PCRE</acronym>-based pattern matching code in
<command>maildrop</command> is completely different from the built-in
pattern matching code in <command>maildrop</command> 1.x, very few changes
will be required to convert recipes to the new syntax.
The only major differences are:</para>
<itemizedlist>
<listitem>
<para>
The subexpression format has changed.
Any pattern that uses subexpression needs to be converted.
Additionally, references to <varname>MATCH2</varname> must be replaced
with <varname>MATCH1</varname>, <varname>MATCH3</varname> to
<varname>MATCH2</varname>, and so on.
References to plain old <varname>MATCH</varname> will remain the
same.</para>
</listitem>
<listitem>
<para>
The <quote>w</quote> pattern option is no longer possible, with
<acronym>PCRE</acronym>.
The very few recipes that use this option, if any actually exist,
will have to be rewritten in some other fashion.</para>
</listitem>
</itemizedlist>
</refsect2>
<refsect2 id="maildropfilter_expressions">
<title>Expressions</title>
<para>
Although <command>maildrop</command> evaluates expressions numerically,
results of
expressions are stored as text literals. When necessary, text literals are
converted to numbers, then the results of a mathematical operation is
converted back into a text literal.</para>
<refsect3 id="maildropfilter_operators">
<title>Operators</title>
<para>
The following operators carry their usual meaning, and are listed in order
from lowest precedence, to the highest:</para>
<blockquote>
<informalexample>
<programlisting>
||
&&
< <= > >= == != lt le gt ge eq ne
|
&
+ -
* /
=~ /<replaceable>pattern</replaceable>/
/<replaceable>pattern</replaceable>/ ! ~ <replaceable>function()</replaceable>
</programlisting>
</informalexample>
</blockquote>
</refsect3>
<refsect3 id="maildropfilter_variable_assignment">
<title>Variable assignment</title>
<anchor id="assign"/>
<blockquote>
<informalexample>
<programlisting>
VARIABLE=<replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
Assigns the result of the expression to <replaceable>VARIABLE</replaceable>
(note no leading $ in front of variable).
</para>
<note>
<para>
If <replaceable>VARIABLE</replaceable> is NOT surrounded by quotes, then it
may contain only letters, numbers, underscores, dashes, and a selected few
other characters. In order to initialize a variable whose name contains
non-standard punctuation marks, surround the name of the variable with
quotes.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_cc___deliver_a_copy_of_the_message">
<title>cc - deliver a copy of the message</title>
<anchor id="cc"/>
<blockquote>
<informalexample>
<programlisting>
cc <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The <command>cc</command> statement is very similar to the
<command>to</command> statement, except
that after delivering the message <command>maildrop</command> continues
to process the
<systemitem class="resource">filter file</systemitem>,
unlike the <command>to</command> statement which immediately
terminates <command>maildrop</command> after the delivery is complete.
Essentially, the
message is carbon copied to the given mailbox, and may be delivered again to
another mailbox by another <command>cc</command> or
<command>to</command> statement.</para>
<para>
<ulink url="#to">See the <command>to</command> statement</ulink> for more
details.
When
<command>cc</command> is used to deliver a message to a process
<command>maildrop</command>
will set the <varname>EXITCODE</varname> variable to the process's exit
code.</para>
</refsect3>
<refsect3 id="maildropfilter_dotlock___create_a_manual_dot_lock">
<title>dotlock - create a manual dot-lock</title>
<anchor id="dotlock"/>
<blockquote>
<informalexample>
<programlisting>
dotlock <replaceable>expression</replaceable> {
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
<command>maildrop</command> automatically creates a lock when a message is
delivered to a
mailbox. Depending upon your system configuration,
<command>maildrop</command> will use
either dot-locks, or the flock() system call.</para>
<para>The <command>dotlock</command> statement creates an explicit dot-lock
file. Use the <ulink url="#flock"><command>flock</command> statement</ulink> to create an
explicit flock()
lock.</para>
<para>The <replaceable>expression</replaceable> is a filename that should be
used as a lock file.
<command>maildrop</command> creates the indicated dot-lock, executes the
filtering
instructions contained within the { ... } block, and removes the lock. The
expression <emphasis>must</emphasis> be the name of the dot-lock file itself,
<emphasis>NOT</emphasis>
the name of the mailbox file you want to lock.</para>
<note>
<para>
With manual locking, it is possible to deadlock multiple
<command>maildrop</command> processes (or any other processes that try to
claim the same
locks).</para>
<para>No deadlock detection is possible with dot-locks, and since
<command>maildrop</command> automatically refreshes all of its dot-locks
regularly, they
will never go stale. You'll have <command>maildrop</command> processes
hanging in limbo,
until their watchdog timers go off, aborting the mail delivery.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_echo___output_diagnostic_information">
<title>echo - output diagnostic information</title>
<anchor id="echo"/>
<blockquote>
<informalexample>
<programlisting>
echo <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
<command>maildrop</command> will print the given text. This is usually used
when
<command>maildrop</command> runs in embedded mode, but can be used for
debugging
purposes. Normally, a newline is printed after the text. If text is
terminated with a \c, no newline will be printed.</para>
</refsect3>
<refsect3 id="maildropfilter_exception___trap_fatal_errors">
<title>exception - trap fatal errors</title>
<anchor id="exception"/>
<blockquote>
<informalexample>
<programlisting>
exception {
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
The <command>exception</command> statement traps errors that would normally
cause
<command>maildrop</command> to terminate. If a fatal error is encountered
anywhere within the
block of statements enclosed by the <command>exception</command> clause,
execution will
resume immediately following the <command>exception</command> clause.</para>
</refsect3>
<refsect3 id="maildropfilter_exit___terminate_filtering_unconditionally">
<title>exit - terminate filtering unconditionally</title>
<anchor id="exit"/>
<blockquote>
<informalexample>
<programlisting>
exit
</programlisting>
</informalexample>
</blockquote>
<para>
The <command>exit</command> statement immediately terminates filtering.
<command>maildrop</command>'s
return code is set to the value of the <varname>EXITCODE</varname> variable.
Normally, <command>maildrop</command> terminates immediately after <ulink url="#to">successfully delivering the message</ulink> to a mailbox. The
<command>exit</command> statement causes <command>maildrop</command> to
terminate without delivering the message anywhere.</para>
<para>The <command>exit</command> statement is usually used when
<command>maildrop</command> runs in <ulink url="maildrop.html#embedded">embedded mode</ulink>, when message
delivery instructions are not allowed.</para>
</refsect3>
<refsect3 id="maildropfilter_flock___create_an_manual_flock___lock">
<title>flock - create an manual flock() lock</title>
<anchor id="flock"/>
<blockquote>
<informalexample>
<programlisting>
flock <replaceable>expression</replaceable> {
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
<command>maildrop</command> automatically creates a lock when a message is delivered to a
mailbox. Depending upon your system configuration, <command>maildrop</command> will use
either dot-locks, or the flock() system call.</para>
<para>The <command>flock</command> statement creates a manual flock() lock.
Use the <ulink url="#dotlock"><command>dotlock</command> statement</ulink>
to create a manual dot-lock
file.</para>
<para>The <replaceable>expression</replaceable> is the name of the
file that should be locked.
<command>maildrop</command> creates the lock on the indicated file, executes
the
filtering instructions contained within the { ... } block, and removes the
lock.</para>
<note>
<para>
With manual locking, it is possible to deadlock multiple
<command>maildrop</command> processes (or any other
processes that try to claim the same
locks). The operating system will automatically break flock() deadlocks. When
that happens, one of the <command>maildrop</command> processes will terminate
immediately. Use the <command>exception</command> statement in order to trap
this
exception condition, and execute an alternative set of filtering
instructions.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_foreach___iterate_over_text_sections_matched_by_a_pattern">
<title>foreach - iterate over text sections matched by a pattern</title>
<blockquote>
<informalexample>
<programlisting>
foreach /pattern/:options
{
...
}
foreach (expression) =~ /pattern/:options
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
The <command>foreach</command> statement executes a block of statements for
each
occurrence of the given pattern in the given message, or expression. On every
iteration <varname>MATCH</varname> variable will be set to the matched string.
All the usual options may be applied to the pattern match,
EXCEPT the following:
<variablelist>
<varlistentry>
<term>,xxx,yyy</term>
<listitem>
<para>
Weighted scoring is meaningless, in this context.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>( ... )</term>
<listitem>
<para>
Subpatterns are not processed.
Only the <varname>MATCH</varname> variable will be set for each found
pattern.</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect3>
<refsect3 id="maildropfilter_if___conditional_execution">
<title>if - conditional execution</title>
<anchor id="if"/>
<blockquote>
<informalexample>
<programlisting>
if (<replaceable>expression</replaceable>)
{
...
}
else
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
Conditional execution. If <replaceable>expression</replaceable>
evaluates to a logical true (note -
parenthesis are required) then the first set of statements is executed.
The <command>else</command> keyword, and the subsequent statements, are
optional. If present,
and the expression evaluates to a logical false, the
<command>else</command> part is executed.</para>
<para>
<command>maildrop</command> evaluates all expression as text strings.
In the context
of a logical expression, an empty string, or the number 0 constitutes a
logical false value, anything else is a logical true value.</para>
<para>If the <command>if</command> part, or the
<command>else</command>
part consists of only one
statement, the braces may be omitted.</para>
<note>
<para>
The grammar of this <command>if</command> statement is stricter than
usual.
If
you get baffling syntax errors from <command>maildrop</command>, make sure that the
braces, and the if statement, appear on separate lines. Specifically: the
closing parenthesis, the closing braces, and the else statement, must be at
the end of the line (comments are allowed), and there may not be any blank
lines in between (not even ones containing comments only).</para>
</note>
<para>
If the <command>else</command> part contains a single <command>if</command>,
and nothing else,
this may be combined into an <command>elsif</command>:
</para>
<blockquote>
<informalexample>
<programlisting>
if (<replaceable>expression</replaceable>)
{
...
}
elsif (<replaceable>expression</replaceable>)
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
The above example is logically identical to:</para>
<blockquote>
<informalexample>
<programlisting>
if (<replaceable>expression</replaceable>)
{
...
}
else
{
if (<replaceable>expression</replaceable>)
{
...
}
}
</programlisting>
</informalexample>
</blockquote>
<para>
Consecutive <command>elsif</command> sequences are allowed:
</para>
<blockquote>
<informalexample>
<programlisting>
if (<replaceable>expression</replaceable>)
{
...
}
elsif (<replaceable>expression</replaceable>)
{
...
}
elsif (<replaceable>expression</replaceable>)
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
Consecutive occurences of <command>elsif</command> commands eliminate a
significant amount of indentation, and the resulting code is more readable.
</para>
</refsect3>
<refsect3 id="maildropfilter_import___access_original_environment_variable">
<title>import - access original environment variable</title>
<anchor id="import"/>
<blockquote>
<informalexample>
<programlisting>
import <replaceable>variable</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>When <command>maildrop</command> starts,
it normally imports the contents of the
environment variables, and assigns them to internal <command>maildrop</command>
variables. For example, if there was an environment variable
<varname>FOO</varname>, the internal <command>maildrop</command> variable
<varname>FOO</varname> will
have the contents of the environment variable.
From then on, <varname>FOO</varname>
will be no different than any other variable,
and when <command>maildrop</command> runs
an external command, the contents of <command>maildrop</command>'s
variables will be
exported as the environment for the command.</para>
<para>Certain variables, like <varname>HOME</varname> and
<varname>PATH</varname>, are always reset to fixed defaults,
for security reasons.
Also, in delivery and embedded modes, the environment is not imported at all
(with the exception of system locale environment variables),
and <command>maildrop</command> starts with only the fixed default
variables.</para>
<para>
The <command>import</command> statement initializes the specified
variable with the contents of the original environment variable
when <command>maildrop</command> started. For example:</para>
<blockquote>
<informalexample>
<programlisting>
echo "PATH is $PATH"
PATH="/bin"
echo "PATH is $PATH"
import PATH
echo "PATH is $PATH"
exit
</programlisting>
</informalexample>
</blockquote>
<para>This results in the following output:</para>
<blockquote>
<informalexample>
<programlisting>
PATH is /bin:/usr/bin:/usr/local/bin
PATH is /bin
PATH is /home/root/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
</programlisting>
</informalexample>
</blockquote>
<para>
This shows that when <command>maildrop</command> starts
<varname>PATH</varname> is set to the fixed default of
<literal>/bin:/usr/bin:/usr/local/bin</literal>.
However, the original contents of
the <varname>PATH</varname> environment variable we different, and the
<command>import</command> statement shows what it was.</para>
</refsect3>
<refsect3 id="maildropfilter_include___execute_filtering_instructions_from_another_file">
<title>include - execute filtering instructions from another file</title>
<anchor id="include"/>
<blockquote>
<informalexample>
<programlisting>
include <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The include statement reads a file, and executes filtering instructions
contained in that file. Note that the include statement is processed when the
current <systemitem class="resource">filter file</systemitem> is being executed. When <command>maildrop</command> reads the initial
<systemitem class="resource">filter file</systemitem>, any syntax errors in the filtering instructions are immediately
reported, and <command>maildrop</command> will terminate with a return code of
<errorcode>EX_TEMPFAIL</errorcode>. Any errors in files specified by
<command>include</command>
statements are NOT reported, because those files will not be read until the
<command>include</command> statement is itself executed.</para>
<para>
If the specified file does not exist, or if there are any syntax errors in
the file, <command>maildrop</command> reports the error, and terminates with
a return
code of <errorcode>EX_TEMPFAIL</errorcode>.</para>
</refsect3>
<refsect3 id="maildropfilter_log__logfile___log_message_deliveries">
<title>log, logfile - log message deliveries</title>
<anchor id="log"/>
<blockquote>
<informalexample>
<programlisting>
logfile <replaceable>expression</replaceable>
log <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
Logging in <command>maildrop</command> is normally turned off.
The <command>logfile</command>
statement specifies the file where
<command>maildrop</command> will log how the message has been
disposed of. The parameter is then name of the file. If the
file exists <command>maildrop</command> appends to the file.</para>
<para>
For each delivery (the <ulink url="#to"><command>to</command></ulink>
and <ulink url="#cc"><command>cc</command></ulink>
statements, and default deliveries)
<command>maildrop</command> records the
<literal>From:</literal> and the
<literal>Subject:</literal> fields, together with
the current time, in the log file.</para>
<para>
The <command>log</command> statement adds additional logging text to the
log file. The <command>log</command> statement works exactly like
the <command>echo</command>
statement, except that the text is written to the logfile, instead of
standard output.</para>
</refsect3>
<refsect3 id="maildropfilter_system___execute_a_system_command">
<title>system - execute a system command</title>
<anchor id="system"/>
<blockquote>
<informalexample>
<programlisting>
system <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
<replaceable>expression</replaceable> specifies an external program
that
<command>maildrop</command> runs as a subprocess.
The subprocess's standard input gets connected to
<filename>/dev/null</filename>, and the subprocess inherits
the standard output and error from
<command>maildrop</command>.</para>
</refsect3>
<refsect3 id="maildropfilter_to___deliver_message_to_a_mailbox">
<title>to - deliver message to a mailbox</title>
<anchor id="to"/>
<blockquote>
<informalexample>
<programlisting>
to <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The <command>to</command> statement delivers the message to a mailbox.
<replaceable>expression</replaceable>
must evaluate to a valid mailbox. A valid mailbox is either a mailbox file, a
maildir, or an external program (which includes forwarding to another
address).</para>
<para>
The <command>to</command> statement is the final delivery statement.
<command>maildrop</command>
delivers message, then immediately terminates,
with its return code set to
the <varname>EXITCODE</varname> variable.
If there was an error while
delivering the message, <command>maildrop</command> terminates with the
<errorcode>EX_TEMPFAIL</errorcode> exit code. A properly-written mail
transport agent
should re-queue the message, and re-attempt delivery at some later time.</para>
<para>
An <replaceable>expression</replaceable> that begins with the
"<token>|</token>" character
specifies an external program to run to handle the actual
delivery. The <varname>SHELL</varname> variable specifies the shell to
execute the
given command. The message is provided to the command on standard input.
<command>maildrop</command>'s exit code will be the process's exit
code.</para>
<para>
An <replaceable>expression</replaceable> that begins
with an exclamation mark, "<token>!</token>"
specifies a whitespace-delimited
list of E-mail addresses to forward the message
to.
The program
specified by the <varname>SENDMAIL</varname> variable is run as an
external program, with the list of E-mail addresses provided as parameters to
the program.</para>
<para>
Otherwise, <replaceable>expression</replaceable> names the mailbox
where <command>maildrop</command> delivers the message.
If <replaceable>expression</replaceable> is a directory,
<command>maildrop</command> assumes
that the directory is a maildir directory.
Otherwise, <command>maildrop</command> will deliver
the message to a file, formatted in traditional mailbox format.
<command>maildrop</command> will use either dot-locking, or flock()-locking
when
delivering the message to the file.</para>
</refsect3>
<refsect3 id="maildropfilter_while___repeatedly_execute_a_block_of_statements">
<title>while - repeatedly execute a block of statements</title>
<anchor id="while"/>
<blockquote>
<informalexample>
<programlisting>
while (<replaceable>expression</replaceable>)
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
The <replaceable>expression</replaceable> is repeatedly evaluated.
Each time it <ulink url="#if">evaluates to a logical true</ulink>,
the statements inside the braces
are executed.
When <replaceable>expression</replaceable> evaluates to a logical false,
the while loop is over. Take care to avoid infinite loops.</para>
</refsect3>
<refsect3 id="maildropfilter_xfilter___filter_message_through_another_program">
<title>xfilter - filter message through another program</title>
<anchor id="xfilter"/>
<blockquote>
<informalexample>
<programlisting>
xfilter <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
<replaceable>expression</replaceable> specifies an external program that
<command>maildrop</command> runs to filter the current message.
The current
message will be piped to the filter program as standard input. The output of
the filter program replaces the current message being delivered. The external
program must terminate with an exit code of 0. If the external program does
not terminate with an exit code of 0, or if it does not read the message from
the standard input, <command>maildrop</command> terminates with an exit code of
<errorcode>EX_TEMPFAIL</errorcode>.</para>
</refsect3>
<refsect3 id="maildropfilter______logical_or">
<title>|| - logical or</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>||</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
If <replaceable>expression1</replaceable> evaluates to a logical true,
the result of the <token>||</token> is
<replaceable>expression1</replaceable>, otherwise it's
<replaceable>expression2</replaceable>, which is evaluated.</para>
<para>
<command>maildrop</command> uses the following concept of true/false:
an empty text
literal, or a text literal that consists of the single character "0" is a
logical false value. Anything else is a logical true value.</para>
</refsect3>
<refsect3 id="maildropfilter__amp__amp____logical_and">
<title>&& - logical and</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>&&</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
If <replaceable>expression1</replaceable> evaluates to a logical false,
the result of the <token>&&</token> is
<replaceable>expression1</replaceable>, otherwise it's
<replaceable>expression2</replaceable>, which is evaluated.</para>
<para>
<command>maildrop</command> uses the following concept of true/false:
an empty text
literal, or a text literal that consists of the single character "0" is a
logical false value. Anything else is a logical true value.</para>
</refsect3>
<refsect3 id="maildropfilter__lt____lt_____gt____gt_______________numerical_comparison">
<title><, <=, >, >=, ==, != - numerical comparison</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token><</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token><=</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>></token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>>=</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>==</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>!=</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
These operators compare their left hand side expression against their right
hand side. These operators compare the numerical values of each side, as
floating point numbers. If the numbers compare as indicated, the result of
the comparison is the text string "1", otherwise it is the text
string 0.</para>
<note>
<para>Ccomparisons are not associative:
"<literal>a < b < c</literal>" is an error.
If it is absolutely necessary, use
"<literal>(a < b) < c</literal>".</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_lt__le__gt__ge__eq__ne___text_comparison">
<title>lt, le, gt, ge, eq, ne - text comparison</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>lt</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>le</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>gt</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>ge</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>eq</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>ne</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
These operators compare their left hand side expression against their right
hand side. These operators compare each side as text strings (alphabetically,
although the text may include anything). If the text strings compare as
indicated, the result of the comparison is the text string "1", otherwise it
is the text string 0.</para>
<note>
<para>
Comparisons are not associative: "<literal>a lt b lt c</literal>"
is an error. If it is
absolutely necessary, use "<literal>(a lt b) lt c</literal>".
(But why would you?).</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_____bitwise_or">
<title>| - bitwise or</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>|</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
This is the bitwise or operator. Its result is a 32 bit
integer, which is a bitwise-or combination of the left hand side and the
right hand side.</para>
</refsect3>
<refsect3 id="maildropfilter__amp____bitwise_and">
<title>& - bitwise and</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>&</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
This is the bitwise and operator. Its result is a 32 bit
integer, which is a bitwise-and combination of the left hand side and the
right hand side.</para>
</refsect3>
<refsect3 id="maildropfilter______________numerical_operations">
<title>+, -, *, / - numerical operations</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression1</replaceable> <token>+</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>-</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>*</token> <replaceable>expression2</replaceable>
<replaceable>expression1</replaceable> <token>/</token> <replaceable>expression2</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
These are numerical, floating point, operators.</para>
</refsect3>
<refsect3 id="maildropfilter_____pattern__options___pattern_match_against_string">
<title>=~ /pattern/:options - pattern match against string</title>
<blockquote>
<informalexample>
<programlisting>
<replaceable>expression</replaceable> <token>=~</token> /<replaceable>pattern</replaceable>/:<replaceable>option</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The left hand side of the <token>=~</token> operator can be any expression.
The right hand
side is always a pattern specification. The result of the operator is the
weighted match of the pattern against
<replaceable>expression</replaceable> (if the options do not
specify weighted scoring, the result is simply 1 if the pattern was found,
0 if not).</para>
<para>
See "<ulink url="#patterns">Patterns</ulink>" for more information.</para>
</refsect3>
<refsect3 id="maildropfilter__pattern__options___pattern_match_against_message">
<title>/pattern/:options - pattern match against message</title>
<blockquote>
<informalexample>
<programlisting>
/<replaceable>pattern</replaceable>/:<replaceable>option</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The result of this operator is the weighted match of the pattern against the
current message (if the options do not specify weighted scoring, the result
is simply 1 if the pattern was found, 0 if not).</para>
<para>
See "<ulink url="#patterns">Patterns</ulink>" for more information.</para>
</refsect3>
<refsect3 id="maildropfilter________logical_bitwise_not_operator_">
<title>!, ~ - logical/bitwise not operator.</title>
<blockquote>
<informalexample>
<programlisting>
<token>!</token> <replaceable>expression</replaceable>
<token>~</token> <replaceable>expression</replaceable>
</programlisting>
</informalexample>
</blockquote>
<para>
The result of the <token>!</token>
operator is a logical opposite of its right hand side
expression. If the right hand side expression evaluated to a logical true,
the result is a logical false. If it evaluated to a logical false, the result
is a logical true.</para>
<para>
<command>maildrop</command> uses the following concept of true/false:
an empty text
literal, or a text literal that consists of the single character "0" is a
logical false value. Anything else is a logical true value.</para>
<para>
The result of the <token>~</token>
operator is a bitwise complement of its right hand
side expression. The right hand side expression is evaluated as a 32 bit
integer, and the result of this operator is a bitwise complement of the
result.</para>
</refsect3>
<refsect3 id="maildropfilter_escape_string____escape_special_characters_in_a_string_">
<title>escape(string) - escape special characters in a string.</title>
<blockquote>
<informalexample>
<programlisting>
<function>escape</function>(<replaceable>expression</replaceable>)
</programlisting>
</informalexample>
</blockquote>
<para>
The <function>escape</function> function returns
its sole argument with every occurrence of a
special character prefixed by a backslash. A special character is any of the
following characters:</para>
<blockquote>
<informalexample>
<programlisting>
|!$()[]\+*?.&;`'-~<>^{}"
</programlisting>
</informalexample>
</blockquote>
<para>
This can used when <ulink url="#patmatch">matching pattern sections</ulink>,
and then taking one section and matching it again. For example:</para>
<blockquote>
<informalexample>
<programlisting>
if ( /^From:\s*(.*)/ )
{
MATCH1=escape($MATCH1)
if ( /^Subject:.*$MATCH1/ )
{
...
}
}
</programlisting>
</informalexample>
</blockquote>
<para>
This example checks if the contents of the <literal>From:</literal>
header can also be found in the <literal>Subject:</literal> header.
If the <function>escape</function> function were not used, then any
special characters in the <literal>From:</literal> header that are also used
in regular
expressions, such as <token>*</token>
or <token>+</token>, would introduce unpredictable behavior, most
likely a syntax error.</para>
<para>
The reason why this list of special characters also includes characters
not used in <command>maildrop</command>'s regular expressions is to allow
<command>maildrop</command>'s variables to be used on the command line of a
shell command
executed by the <command>xfilter</command> command, backtick characters, or
<command>to</command> or <command>cc</command> commands.</para>
<para>
Although using data from an external data source is dangerous, and it may
result in inadvertent exploits, using the escape function should hopefully
result in fewer surprises.</para>
</refsect3>
<refsect3 id="maildropfilter_gdbmopen__gdbmclose__gdbmfetch__gdbmstore___gdbm_support_in_maildrop">
<title>gdbmopen, gdbmclose, gdbmfetch, gdbmstore - GDBM support in <command>maildrop</command></title>
<para>
These functions provide support for GDBM database files. See <ulink url="maildropgdbm.html"><citerefentry><refentrytitle>maildropgdbm</refentrytitle><manvolnum>5</manvolnum></citerefentry></ulink>
for more information.</para>
<note>
<para>
The system administrator can disable GDBM support in
<command>maildrop</command>, so these commands may not be available to
you.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_getaddr_string____extract_rfc_2822_addresses_from_a_header_">
<title>getaddr(string) - extract RFC 2822 addresses from a header.</title>
<anchor id="getaddr"/>
<blockquote>
<informalexample>
<programlisting>
if ( /^From:\s*(.*)/ )
{
ADDR=getaddr($MATCH1)
}
</programlisting>
</informalexample>
</blockquote>
<para>
This function is usually applied to a header that contains
<ulink url="http://www.rfc-editor.org/rfc/rfc2822.txt">RFC 2822</ulink>
addresses. It extracts the actual addresses from the
header, without any comments or extraneous punctuation. Each address is
followed by a newline character. For example,
if <replaceable>string</replaceable> contains:</para>
<blockquote>
<informalexample>
<programlisting>
joe@domain.com (Joe Brown), "Alex Smith" <alex@domain.com>, tom@domain.com
</programlisting>
</informalexample>
</blockquote>
<para>
The result of the <function>getaddr</function> function is the
following string:</para>
<blockquote>
<informalexample>
<programlisting>
joe@domain.com<token><NL></token>alex@domain.com<token><NL></token>tom@domain.com<token><NL></token>
</programlisting>
</informalexample>
</blockquote>
<note>
<para>
Because <function>getaddr</function>() interprets
<ulink url="http://www.rfc-editor.org/rfc/rfc822.txt">RFC 2822</ulink>
loosely, it is not
necessary to
strip off the "<literal>To:</literal>" or the "<literal>Cc:</literal>"
header from the string, before feeding it to
<function>getaddr()</function>. For example, the following snippet of code
takes all
addresses in the message, and concatenates them into a single string,
separated by spaces:</para>
<blockquote>
<informalexample>
<programlisting>
ADDRLIST=""
foreach /^(To|Cc): .*/
{
foreach (getaddr $MATCH) =~ /.+/
{
ADDRLIST="$ADDRLIST $MATCH"
}
}
</programlisting>
</informalexample>
</blockquote>
</note>
<note>
<para>
In certain rare situations,
<ulink url="http://www.rfc-editor.org/rfc/rfc822.txt">RFC 2822</ulink> allows
spaces to be included in E-mail addresses, so this example is just
educational.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_hasaddr_string____search_for_an_address_">
<title>hasaddr(string) - Search for an address.</title>
<blockquote>
<informalexample>
<programlisting>
if ( hasaddr(<replaceable>string</replaceable>) )
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
"<replaceable>string</replaceable>" is of the form
<literal>user@domain</literal>. The hasaddr
function returns 1 if this address is included in any <literal>To:</literal>,
<literal>Cc:</literal>,<literal> Resent-To:</literal>, or <literal>Resent-Cc:</literal>, header
in the message, otherwise this function returns 0.</para>
<para>
This is more than just a simple text search. Each header is parsed
according to <literal>RFC822</literal>. Addresses found in the header are
extracted, ignoring all comments and names. The remaining addresses are
checked, and if "<replaceable>string</replaceable>" is one of them,
<function>hasaddr</function> returns 1,
otherwise it returns 0.</para>
<para>The comparison is case-insensitive. This actually violates
<literal>RFC822</literal> (and several others) a little bit, because the user part
of the address may be (but is not required to be) case sensitive.</para>
</refsect3>
<refsect3 id="maildropfilter_length__string____length_of_a_string">
<title>length (string) - length of a string</title>
<blockquote>
<informalexample>
<programlisting>
if (length(<replaceable>string</replaceable>) > 80)
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
The <function>length</function> function returns the number of characters in
<replaceable>string</replaceable>.</para>
</refsect3>
<refsect3 id="maildropfilter_lookup__expr___filename____options_____read_file_for_patterns">
<title>lookup (expr, 'filename', 'options') - read file for patterns</title>
<blockquote>
<informalexample>
<programlisting>
if (lookup(<replaceable>expr</replaceable>, <filename>file</filename>, "<replaceable>option</replaceable>"))
{
...
}
</programlisting>
</informalexample>
</blockquote>
<para>
<replaceable>expr</replaceable> is any expression.
<filename>filename</filename> is a name of a file containing
a list of patterns. Note that <filename>filename</filename> is relative to the
current directory, which is the home directory of the user when
<command>maildrop</command> runs in delivery mode, or embedded mode. <command>maildrop</command> then
reads the file.
Blank lines will be ignored, as well as any lines that begin
with the # character (comments).</para>
<para>Leading whitespace (but not trailing whitespace, take care) is removed,
and the remaining contents of each line are interpreted as a pattern which is
matched against <replaceable>expr</replaceable>.
As soon as the match is found, <function>lookup</function>
returns "1". If no match is found after reading the entire file,
<function>lookup</function> returns "0". For example:</para>
<blockquote>
<informalexample>
<programlisting>
if ( /^To:\s*(.*)/ && lookup( $MATCH1, "badto.dat" ))
{
exit
}
</programlisting>
</informalexample>
</blockquote>
<para>
The file badto.dat contains the following two lines:</para>
<blockquote>
<informalexample>
<programlisting>
friend@public
^[^@]*$
</programlisting>
</informalexample>
</blockquote>
<para>
If a message has a <literal>To:</literal>
header that contains the text "<literal>friend@public</literal>", or does
not contain at least one <token>@</token> character, then the message will
be silently
dropped on the floor ( <command>maildrop</command> will terminate without
delivering the
message anywhere).</para>
<para>
<replaceable>options</replaceable> are the pattern matching options
to use. The only supported
option is "D" (the rest are meaningless, in this case).</para>
<note>
<para>
Be careful with discarding messages like that. Pattern matching can
be tricky, and a slight miscalculation can cause mail to be unintentionally
discarded. It is much desirable to first deliver message to a separate folder
or mailbox, and once the filter is verified to work correctly, change it so
the messages are discarded completely.</para>
</note>
</refsect3>
<refsect3 id="maildropfilter_substr_string_start___count_____return_substring">
<title>substr(string,start [,count]) - return substring</title>
<blockquote>
<informalexample>
<programlisting>
foo=substr($foo, 1, 10)
</programlisting>
</informalexample>
</blockquote>
<para>
The <function>substr</function> function
extracts characters from <replaceable>string</replaceable>
beginning with character #<replaceable>start</replaceable>.
If <replaceable>count</replaceable> is
specified, at most <replaceable>count</replaceable> characters
starting at position <replaceable>start</replaceable> are kept, any excess is
trimmed.</para>
</refsect3>
<refsect3 id="maildropfilter_time___return_current_time">
<title>time - return current time</title>
<blockquote>
<informalexample>
<programlisting>
foo=time
</programlisting>
</informalexample>
</blockquote>
<para>
The <function>time</function> function returns the current time, in
seconds, since
January 1, 1970. This function is useful when using GDBM files. See <ulink url="maildropex.html"><citerefentry><refentrytitle>maildropex</refentrytitle><manvolnum>7</manvolnum></citerefentry></ulink>
for an example of using the <function>time</function> function.</para>
</refsect3>
<refsect3 id="maildropfilter_tolower_string____convert_string_to_lowercase_">
<title>tolower(string) - Convert string to lowercase.</title>
<blockquote>
<informalexample>
<programlisting>
foo=tolower(<replaceable>string</replaceable>)
</programlisting>
</informalexample>
</blockquote>
<para>
This function returns the <replaceable>string</replaceable>
with all uppercase characters
replaced by lowercase characters.</para>
</refsect3>
<refsect3 id="maildropfilter_toupper_string____convert_string_to_uppercase_">
<title>toupper(string) - Convert string to uppercase.</title>
<blockquote>
<informalexample>
<programlisting>
foo=toupper(<replaceable>string</replaceable>)
</programlisting>
</informalexample>
</blockquote>
<para>
This function returns the <replaceable>string</replaceable>
with all lowercase characters
replaced by uppercase characters.</para>
</refsect3>
</refsect2>
<refsect2 id="maildropfilter_statements">
<title>Statements</title>
<para>
The <systemitem class="resource">filter file</systemitem> is read by
<command>maildrop</command>
(<filename>$HOME/.mailfilter</filename> or another file), and it
contains filtering
statements, one per line. The filtering language used by
<command>maildrop</command> has
a loosely - defined grammatical structure.</para>
<para>Statements are listed one per line. Multiple statements may be listed on
the same line by separating them with semicolons. To continue a long
statement on the next line, terminate the line with a backslash
character.</para>
</refsect2>
</refsect1>
<refsect1 id="maildropfilter_bugs">
<title>BUGS</title>
<para>
If <function>getaddr</function>() or <function>hasaddr</function>()
functions are used on broken headers, the results
are unpredictable.</para>
<para><function>hasaddr</function>() is completely case insensitive. This
actually violates a few
RFCs, because the userid portion of the address could be case-sensitive, but
it's not in too many cases, so there.</para>
</refsect1>
<refsect1 id="maildropfilter_see_also">
<title>SEE ALSO</title>
<para>
<ulink url="lockmail.html"><citerefentry><refentrytitle>lockmail</refentrytitle><manvolnum>1</manvolnum></citerefentry></ulink>,
<ulink url="maildrop.html"><citerefentry><refentrytitle>maildrop</refentrytitle><manvolnum>1</manvolnum></citerefentry></ulink>,
<ulink url="maildropgdbm.html"><citerefentry><refentrytitle>maildropgdbm</refentrytitle><manvolnum>5</manvolnum></citerefentry></ulink>,
<ulink url="maildirquota.html"><citerefentry><refentrytitle>maildirquota</refentrytitle><manvolnum>8</manvolnum></citerefentry></ulink>,
<ulink url="reformail.html"><citerefentry><refentrytitle>reformail</refentrytitle><manvolnum>1</manvolnum></citerefentry></ulink>,
<citerefentry><refentrytitle>egrep</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sendmail</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
</para>
</refsect1>
</refentry>
|