Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / mailscanner_rules.aug
1 (*
2 Module: Mailscanner_rules
3   Parses MailScanner rules files.
4
5 Author: Andrew Colin Kissa <andrew@topdog.za.net>
6   Baruwa Enterprise Edition http://www.baruwa.com
7
8 About: License
9   This file is licensed under the LGPL v2+.
10
11 About: Configuration files
12   This lens applies to MailScanner rules files
13   The format is described below:
14
15   # NOTE: Fields are separated by TAB characters --- Important!
16   #
17   # Syntax is allow/deny/deny+delete/rename/rename to replacement-text/email-addresses,
18   #           then regular expression,
19   #           then log text,
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.
24
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
33   # ".ppt" instead.
34 *)
35
36 module Mailscanner_Rules =
37 autoload xfm
38
39 (************************************************************************
40  *                           USEFUL PRIMITIVES
41  *************************************************************************)
42
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]+/
50
51 let field (l:string) (r:regexp)
52                = [ label l . store r ]
53
54 (************************************************************************
55  *                               ENTRIES
56  *************************************************************************)
57
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
62                 . eol ]
63
64 (************************************************************************
65  *                                LENS
66  *************************************************************************)
67
68 let lns        = (comment|empty|entry)*
69
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")
74
75 let xfm        = transform lns filter