2 Module: Mailscanner_rules
3 Parses MailScanner rules files.
5 Author: Andrew Colin Kissa <andrew@topdog.za.net>
6 Baruwa Enterprise Edition http://www.baruwa.com
9 This file is licensed under the LGPL v2+.
11 About: Configuration files
12 This lens applies to MailScanner rules files
13 The format is described below:
15 # NOTE: Fields are separated by TAB characters --- Important!
17 # Syntax is allow/deny/deny+delete/rename/rename to replacement-text/email-addresses,
18 # then regular expression,
20 # then user report text.
21 # The "email-addresses" can be a space or comma-separated list of email
22 # addresses. If the rule hits, the message will be sent to these address(es)
23 # instead of the original recipients.
25 # If a rule is a "rename" rule, then the attachment filename will be renamed
26 # according to the "Default Rename Pattern" setting in MailScanner.conf.
27 # If a rule is a "rename" rule and the "to replacement-text" is supplied, then
28 # the text matched by the regular expression in the 2nd field of the line
29 # will be replaced with the "replacement-text" string.
30 # For example, the rule
31 # rename to .ppt \.pps$ Renamed .pps to .ppt Renamed .pps to .ppt
32 # will find all filenames ending in ".pps" and rename them so they end in
36 module Mailscanner_Rules =
39 (************************************************************************
41 *************************************************************************)
43 let eol = del /\n/ "\n"
44 let ws = del /[\t]+/ "\t"
45 let comment = Util.comment
46 let empty = Util.empty
47 let action = /allow|deny|deny\+delete|rename|rename[ ]+to[ ]+[^# \t\n]+|([A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+[, ]?)+/
48 let non_space = /[^# \t\n]+/
49 let non_tab = /[^\t\n]+/
51 let field (l:string) (r:regexp)
52 = [ label l . store r ]
54 (************************************************************************
56 *************************************************************************)
58 let entry = [ seq "rule" . field "action" action
59 . ws . field "regex" non_tab
60 . ws . field "log-text" non_tab
61 . ws . field "user-report" non_tab
64 (************************************************************************
66 *************************************************************************)
68 let lns = (comment|empty|entry)*
70 let filter = (incl "/etc/MailScanner/filename.rules.conf")
71 . (incl "/etc/MailScanner/filetype.rules.conf")
72 . (incl "/etc/MailScanner/archives.filename.rules.conf")
73 . (incl "/etc/MailScanner/archives.filetype.rules.conf")
75 let xfm = transform lns filter