switch config to JSON format and new rules/modifications logic

This commit is contained in:
2020-04-22 19:50:25 +02:00
parent 594d3a466b
commit 1bcfbb2414
7 changed files with 619 additions and 450 deletions

View File

@@ -1,53 +1,82 @@
# pymodmilter
A pymilter based sendmail/postfix pre-queue filter with the ability to add, remove and modify e-mail headers.
The project is currently in beta status, but it is already used in a productive enterprise environment which processes about a million e-mails per month.
This project is currently in beta status, but it is already used in a productive enterprise environment which processes about a million e-mails per month.
The basic idea is to define rules with conditions and do modifications make changes when all conditions are met.
## Requirements
* pymilter <https://pythonhosted.org/pymilter/>
* netaddr <https://github.com/drkjam/netaddr/>
## Configuration
The pymodmilter uses an INI-style configuration file. The sections are described below.
Pymodmilter uses a configuration file in JSON format. The options are described below. Make a copy of the example configuration file in the docs folder to start with.
### Section "global"
Any available configuration option can be set in the global section as default instead of in a rule section.
### global (Object)
The following optional global configuration options are available:
* **local_addrs (Array of Strings)**
A list of hosts and network addresses which are considered local. It is used to for the condition option 'local'. This option may be overriden within a rule object.
* **log (Bool)**
Enable or disable logging. This option may be overriden by a rule or modification object.
The following configuration options are mandatory in the global section:
* **rules**
Comma-separated, ordered list of active rules. For each, there must be a section of the same name in the configuration.
### rules (Array)
A mandatory list of rule objects which are processed in the given order.
### Rule sections
### rule (Object)
The following configuration options are mandatory for each rule:
* **action**
Set the action of this rule. Possible values are:
* **add**
* **del**
* **mod**
* **header**
Name of the header in case of adding a header, regular expression to match whole header lines in case of deleting or modifying a header.
The following configuration options are mandatory for an add-rule:
* **value**
Value of the header.
The following configuration options are mandatory for a mod-rule:
* **search**
Regular expression to match the value of header lines. You may use subgroups or named subgroups (python syntax) to include parts of the original value in the new value.
* **value**
New value of the header.
* **modifications (Array of Objects)**
A list of modification objects which are processed in the given order.
The following configuration options are optional for each rule:
* **ignore_envfrom**
Regular expression to match envelop-from addresses. The rule will be skipped if the expression matches.
* **ignore_hosts**
Comma-separated list of host and network addresses. The rule will be skipped if the sending host is included here.
* **only_hosts**
Comma-separated list of host and network addresses. The rule will be skipped if the sending host is not included here. If a is included in both **ignore_hosts** and **only_hosts**, the rule will be skipped.
* **log**
Enable or disable logging of this rule. Possible values are:
* **true**
* **false**
* **name (String)**
Name of the rule.
* **conditions (Object)**
A list of conditions which all have to be true to process the rule.
* **local_addrs (Array of Strings)**
As described above in the global object section.
* **log (Bool)**
As described above in the global object section.
### modification (Object)
The following configuration options are mandatory for each modification:
* **type (String)**
Set the modification type. Possible values are:
* **add_header**
* **del_header**
* **mod_header**
Additional parameters are mandatory based on the modification type.
* **add_header**
* **header (String)**
Name of the header.
* **value (String)**
Value of the header.
* **del_header**
* **header (String)**
Regular expression to match against header lines.
* **mod_header**
* **header (String)**
Regular expression to match against header lines.
* **search (String)**
Regular expression to match against the value of header lines. You may use subgroups or named subgroups (python syntax) to include parts of the original value in the new value.
* **value (String)**
New value of the header.
The following configuration options are optional for each modification:
* **name (String)**
Name of the modification.
* **log (Bool)**
As described above in the global object section.
### conditions (Object)
The following configuration options are optional:
* **local (Bool)**
If set to true, the rule is only executed for emails originating from addresses defined in local_addrs and vice versa.
* **hosts (Array of Strings)**
A list of hosts and network addresses for which the rule should be executed.
* **envfrom (String)**
A regular expression to match against the evenlope-from addresses for which the rule should be executed.
## Developer information
Everyone who wants to improve or extend this project is very welcome.