add some comments and change setup.py

This commit is contained in:
2020-04-22 21:40:28 +02:00
parent b20a37cf7c
commit aa135190b9
2 changed files with 19 additions and 3 deletions

View File

@@ -62,8 +62,9 @@ def replace_illegal_chars(string):
class Modification: class Modification:
"""Modification to implement a modification to apply on e-mail headers.""" """Modification to implement a modification to apply on e-mails."""
# mandatory parameters for each modification type
types = { types = {
"add_header": ["header", "value"], "add_header": ["header", "value"],
"del_header": ["header"], "del_header": ["header"],
@@ -117,7 +118,7 @@ class Modification:
def execute(self, qid, headers): def execute(self, qid, headers):
""" """
Execute rule on given headers and return list Execute modification and return list
with modified headers. with modified headers.
""" """
if self.mod_type == "add_header": if self.mod_type == "add_header":
@@ -179,6 +180,9 @@ class Modification:
class Rule: class Rule:
"""
Rule to implement multiple modifications on emails based on conditions.
"""
def __init__(self, name, modifications, local_addrs, log, conditions={}): def __init__(self, name, modifications, local_addrs, log, conditions={}):
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.name = name self.name = name
@@ -261,6 +265,7 @@ class Rule:
f"{self.name}: added modification: {mod['name']}") f"{self.name}: added modification: {mod['name']}")
def ignore_host(self, host): def ignore_host(self, host):
"""Check if host is ignored by this rule."""
ip = IPAddress(host) ip = IPAddress(host)
if "local" in self.conditions: if "local" in self.conditions:
@@ -282,12 +287,14 @@ class Rule:
return False return False
def ignore_envfrom(self, envfrom): def ignore_envfrom(self, envfrom):
"""Check if envelope-from address is ignored by this rule."""
if "envfrom" in self.conditions: if "envfrom" in self.conditions:
if not self.conditions["envfrom"].search(envfrom): if not self.conditions["envfrom"].search(envfrom):
return True return True
return False return False
def execute(self, qid, headers): def execute(self, qid, headers):
"""Execute all modifications of this rule."""
changes = [] changes = []
if self.log: if self.log:
self.logger.info(f"{qid}: executing rule '{self.name}'") self.logger.info(f"{qid}: executing rule '{self.name}'")

View File

@@ -17,7 +17,7 @@ setup(name = "pymodmilter",
url = "https://github.com/spacefreak86/pymodmilter", url = "https://github.com/spacefreak86/pymodmilter",
packages = ["pymodmilter"], packages = ["pymodmilter"],
long_description = read_file("README.md"), long_description = read_file("README.md"),
long_description_content_type="text/markdown", long_description_content_type = "text/markdown",
classifiers = [ classifiers = [
# 3 - Alpha # 3 - Alpha
# 4 - Beta # 4 - Beta
@@ -29,11 +29,20 @@ setup(name = "pymodmilter",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Topic :: Communications :: Email :: Filters" "Topic :: Communications :: Email :: Filters"
], ],
include_package_data = True,
entry_points = { entry_points = {
"console_scripts": [ "console_scripts": [
"pymodmilter=pymodmilter.run:main" "pymodmilter=pymodmilter.run:main"
] ]
}, },
data_files = [
(
'usr/share/docs/',
[
'docs/pymodmilter.conf.example'
]
)
],
install_requires = ["pymilter", "netaddr"], install_requires = ["pymilter", "netaddr"],
python_requires = ">=3.6" python_requires = ">=3.6"
) )