Mailfromd Mail Filter Version 8.12, 23 July 2021
Total Page:16
File Type:pdf, Size:1020Kb
Mailfromd mail filter version 8.12, 23 July 2021 Sergey Poznyakoff. Published by the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Copyright c 2005–2021 Sergey Poznyakoff Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. Dedico aquest treball a Lluis Llach, per obrir els nous horitzons. i Short Contents Preface ................................................. 1 1 Introduction to mailfromd.............................. 5 2 Building the Package .................................. 9 3 Tutorial ............................................ 13 4 Mail Filtering Language ............................... 51 5 The MFL Library Functions .......................... 111 6 Using the GNU Emacs MFL Mode ..................... 195 7 Configuring mailfromd ............................... 199 8 Mailfromd Command Line Syntax ..................... 209 9 Using mailfromd with Various MTAs ................... 217 10 calloutd .......................................... 223 11 mfdbtool .......................................... 231 12 mtasim — a testing tool .............................. 233 13 Pmilter multiplexer program. .......................... 243 14 How to Report a Bug ................................ 251 A Gacopyz ........................................... 253 B Time and Date Formats .............................. 255 C Upgrading ......................................... 259 D GNU Free Documentation License ...................... 271 Concept Index ......................................... 279 iii Table of Contents Preface .............................................. 1 Short history of mailfromd. ......................................... 1 Acknowledgments ................................................... 3 1 Introduction to mailfromd ...................... 5 1.1 Typographical conventions ..................................... 5 1.2 Overview of Mailfromd ......................................... 6 1.3 Sender Address Verification. .................................... 6 1.3.1 Limitations of Sender Address Verification ................. 7 1.4 Controlling Mail Sending Rate. ................................. 8 1.5 SPF, DKIM, and others ........................................ 8 2 Building the Package ........................... 9 3 Tutorial ........................................ 13 3.1 Start Up ...................................................... 13 3.2 Simplest Configurations ....................................... 15 3.3 Conditional Execution ........................................ 16 3.4 Functions and Modules........................................ 17 3.5 Domain Name System......................................... 18 3.6 Checking Sender Address...................................... 18 3.7 SMTP Timeouts............................................... 19 3.8 Avoiding Verification Loops ................................... 20 3.9 HELO Domain................................................ 22 3.10 SMTP RSET and Milter Abort Handling..................... 23 3.11 Controlling Number of Recipients ............................ 23 3.12 Sending Rate ................................................ 25 3.13 Greylisting................................................... 27 3.14 Local Account Verification ................................... 29 3.15 Databases ................................................... 30 3.15.1 Database Formats....................................... 31 3.15.2 Basic Database Operations .............................. 32 3.15.3 Database Maintenance .................................. 33 3.16 Testing Filter Scripts ........................................ 33 3.17 Run Mode ................................................... 35 3.17.1 The Top of a Script File................................. 36 3.17.2 Parsing Command Line Arguments ...................... 37 3.18 Logging and Debugging ...................................... 40 3.19 Runtime Errors .............................................. 45 3.20 Notes and Cautions .......................................... 48 iv Mailfromd Manual 4 Mail Filtering Language ...................... 51 4.1 Comments .................................................... 51 4.2 Pragmatic comments .......................................... 52 4.2.1 Pragma prereq ........................................... 52 4.2.2 Pragma stacksize ......................................... 52 4.2.3 Pragma regex ............................................ 54 4.2.4 Pragma dbprop .......................................... 55 4.2.5 Pragma greylist .......................................... 55 4.2.6 Pragma miltermacros..................................... 55 4.2.7 Pragma provide-callout................................... 55 4.3 Data Types ................................................... 56 4.4 Numbers ...................................................... 56 4.5 Literals ....................................................... 56 4.6 Here Documents .............................................. 58 4.7 Sendmail Macros .............................................. 59 4.8 Constants..................................................... 59 4.8.1 Built-in constants ........................................ 60 4.9 Variables...................................................... 62 4.9.1 Predefined Variables...................................... 63 4.10 Back references .............................................. 65 4.11 Handlers ..................................................... 66 4.12 The ‘begin’ and ‘end’ special handlers ....................... 71 4.13 Functions .................................................... 72 4.13.1 Some Useful Functions .................................. 76 4.14 Expressions .................................................. 78 4.14.1 Constant Expressions ................................... 78 4.14.2 Function Calls .......................................... 78 4.14.3 Concatenation .......................................... 78 4.14.4 Arithmetic Operations .................................. 79 4.14.5 Bitwise shifts ........................................... 79 4.14.6 Relational Expressions .................................. 79 4.14.7 Special Comparisons .................................... 79 4.14.8 Boolean Expressions .................................... 80 4.14.9 Operator Precedence .................................... 81 4.14.10 Type Casting .......................................... 82 4.15 Variable and Constant Shadowing ............................ 82 4.16 Statements .................................................. 85 4.16.1 Action Statements ...................................... 85 4.16.2 Variable Assignments ................................... 87 4.16.3 The pass statement ..................................... 87 4.16.4 The echo statement ..................................... 87 4.17 Conditional Statements ...................................... 88 4.18 Loop Statements ............................................. 89 4.19 Exceptional Conditions ...................................... 92 4.19.1 Built-in Exceptions...................................... 92 4.19.2 User-defined Exceptions ................................. 94 4.19.3 Exception Handling ..................................... 94 4.20 Sender Verification Tests ..................................... 97 v 4.21 Modules .................................................... 101 4.21.1 Declaring Modules ..................................... 101 4.21.2 Scope of Visibility...................................... 102 4.21.3 Require and Import .................................... 102 4.22 MFL Preprocessor........................................... 103 4.23 Example of a Filter Script File .............................. 106 4.24 Reserved Words ............................................ 108 5 The MFL Library Functions ................ 111 5.1 Sendmail Macro Access Functions ............................ 111 5.2 The sed function ............................................ 112 5.3 String Manipulation Functions ............................... 113 5.4 String formatting ............................................ 117 5.5 Character Type .............................................. 119 5.6 I/O functions ................................................ 120 5.7 Filtering functions ........................................... 125 5.7.1 Filters and Filter Pipes.................................. 125 5.8 Email processing functions. .................................. 129 5.9 Envelope Modification Functions ............................. 130 5.10 Header Modification Functions .............................. 130 5.11 Body Modification Functions................................ 132 5.12 Message Modification Queue ................................ 133 5.13 Mail Header Functions ...................................... 134 5.14 Mail Body Functions........................................ 135 5.15 EOM Functions............................................. 136 5.16 Current Message Functions ................................. 136 5.17 Mailbox Functions .......................................... 137 5.18 Message Functions .......................................... 138 5.18.1 Header functions ....................................... 139