From aa135190b997798bf9f01b264ef2fb59bbcb5dbb Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Wed, 22 Apr 2020 21:40:28 +0200 Subject: [PATCH] add some comments and change setup.py --- pymodmilter/__init__.py | 11 +++++++++-- setup.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pymodmilter/__init__.py b/pymodmilter/__init__.py index 781f79c..f7e7d2a 100644 --- a/pymodmilter/__init__.py +++ b/pymodmilter/__init__.py @@ -62,8 +62,9 @@ def replace_illegal_chars(string): 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 = { "add_header": ["header", "value"], "del_header": ["header"], @@ -117,7 +118,7 @@ class Modification: def execute(self, qid, headers): """ - Execute rule on given headers and return list + Execute modification and return list with modified headers. """ if self.mod_type == "add_header": @@ -179,6 +180,9 @@ class Modification: class Rule: + """ + Rule to implement multiple modifications on emails based on conditions. + """ def __init__(self, name, modifications, local_addrs, log, conditions={}): self.logger = logging.getLogger(__name__) self.name = name @@ -261,6 +265,7 @@ class Rule: f"{self.name}: added modification: {mod['name']}") def ignore_host(self, host): + """Check if host is ignored by this rule.""" ip = IPAddress(host) if "local" in self.conditions: @@ -282,12 +287,14 @@ class Rule: return False def ignore_envfrom(self, envfrom): + """Check if envelope-from address is ignored by this rule.""" if "envfrom" in self.conditions: if not self.conditions["envfrom"].search(envfrom): return True return False def execute(self, qid, headers): + """Execute all modifications of this rule.""" changes = [] if self.log: self.logger.info(f"{qid}: executing rule '{self.name}'") diff --git a/setup.py b/setup.py index ba29fe6..45fff62 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup(name = "pymodmilter", url = "https://github.com/spacefreak86/pymodmilter", packages = ["pymodmilter"], long_description = read_file("README.md"), - long_description_content_type="text/markdown", + long_description_content_type = "text/markdown", classifiers = [ # 3 - Alpha # 4 - Beta @@ -29,11 +29,20 @@ setup(name = "pymodmilter", "Programming Language :: Python :: 3", "Topic :: Communications :: Email :: Filters" ], + include_package_data = True, entry_points = { "console_scripts": [ "pymodmilter=pymodmilter.run:main" ] }, + data_files = [ + ( + 'usr/share/docs/', + [ + 'docs/pymodmilter.conf.example' + ] + ) + ], install_requires = ["pymilter", "netaddr"], python_requires = ">=3.6" )