Understanding the SMTP conversation
An important part in understanding the rules.MailRules file is understanding the SMTP conversation. This conversation delivers a message and initiates at what point and in what order various rules events occur. What follows is a timeline of events in the transmission of a simple RFC-2822 message into Internet Services via SMTP. Here is what happens during an SMTP conversation:
Let's run a sample message through a sample rules file. Say you have the following rules.MailRules file:
# if the message is from a trusted IP address, we're done
^: IF (@istrustedip($senderip)) DONE
# admin settable variables are defined here
^: IF (1) SET $spamMax=50
# checked for spammers in Received headers
Received: regexp:"\\[0-9][0-9]*\\.[0-9][0-9]*\\.[0-9][0-9]*\\.[0-9][0-9]*\\)" SET $IP = "\\1"
Received: IF (isspamip($IP)) NDN
# check subject
Subject: IF (@inblocklist($subject)) SET $spamlevel += 50
Subject: " " SET $spamlevel += 25
Subject: IF (@allcaps ($subject)) SET $spamlevel += 25
# errors-to makes something less likely to be spam
Errors-To: "*@*" SET $spamlevel -= 20 AND $spamtests += "-ERRORS_TO;"
# If any header says Viagra, this is junk
*: "Viagra" SET $spamlevel += 25
# rules to deal with spam level, processed at the end of the headers
: IF ($spamlevel >= $spamMax) NDN 550 "Sorry, your message has triggered a spam block, please contact the postmaster."
Let's see how the above rules.MailRules file handles a mail message:
When another mail server connects to Internet Services, SMTP pleasantries are exchanged up to DATA command. This is how the rest of the message is handled:
• ^ rules are run
SpamMax is now 50 and if the mail server is a trusted IP, all rules' processing stops.
• To: user@is.com
Arrives on SMTP channel, * rule runs, "user@is.com" is compared to "Viagra" and, if no match, nothing happens.
• From:user@is.com
Arrives on SMTP channel, * rule runs, "user@is.com" is compared to "Viagra" and, if no match, nothing happens.
• Subject: HELLO OUT THERE!
Arrives on SMTP channel, rule "Subject:IF (@inblocklist($subject)) SET $spamlevel + = 50" runs, nothing happens.
The "Subject: " " SET $spamlevel + = 25" rule runs and $spamlevel is now 25.
The "Subject: IF (@allcaps($subject)) SET $spamlevel += 25" rule runs and $spamlevel is now 50.
The * rule runs, which compares "HELLO OUT THERE!" to "Viagra" and, if no match, nothing happens.
• "<CRLF>"
A blank line arrives triggering "" rule, ": IF ($spamlevel >= &$SpamMax) NDN 550 "Sorry your message has triggered a spam block, please contact the postmaster"" runs.
Since $spamlevel is 50, the message is NDNed. The other mail server sees the NDN message and stops trying to connect.
When another message comes in the process begins again.
|