prepare to merge with pyquarantine project

This commit is contained in:
2021-09-30 18:04:36 +02:00
parent cd7e0688dc
commit 0bd88f7cf4
26 changed files with 133 additions and 108 deletions

View File

@@ -1,3 +1,3 @@
include LICENSE README.md
recursive-include pymodmilter/docs *
recursive-include pymodmilter/misc *
recursive-include pyquarantine/docs *
recursive-include pyquarantine/misc *

View File

@@ -1,25 +1,27 @@
# pymodmilter
# pyquarantine
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 that processes about a million e-mails per month.
The basic idea is to define rules with conditions and actions which are processed when all conditions are true.
## Dependencies
Pymodmilter is depending on these python packages, but they are installed automatically if you are working with pip.
* [pymilter](https://pythonhosted.org/pymilter/)
* [netaddr](https://github.com/drkjam/netaddr/)
pyquarantine is depending on these python packages, but they are installed automatically if you are working with pip.
* [jsonschema](https://github.com/Julian/jsonschema)
* [pymilter](https://github.com/sdgathman/pymilter)
* [netaddr](https://github.com/drkjam/netaddr)
* [peewee](https://github.com/coleifer/peewee)
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)
## Installation
* Install pymodmilter with pip and copy the example config file.
* Install pyquarantine with pip and copy the example config file.
```sh
pip install pymodmilter
cp /etc/pymodmilter/pymodmilter.conf.example /etc/pymodmilter/pymodmilter.conf
pip install pyquarantine
cp /etc/pyquarantine/pyquarantine.conf.example /etc/pyquarantine/pyquarantine.conf
```
* Modify /etc/pymodmilter/pymodmilter.conf according to your needs.
* Modify /etc/pyquarantine/pyquarantine.conf according to your needs.
## Configuration options
Pymodmilter uses a config file in JSON format. The config file has to be JSON valid with the exception of allowed comment lines starting with **#**. The options are described below.
pyquarantine uses a config file in JSON format. The config file has to be JSON valid with the exception of allowed comment lines starting with **#**. The options are described below.
Rules and actions are processed in the given order.
### Global

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [
@@ -27,9 +27,9 @@ __all__ = [
"whitelist",
"ModifyMilter"]
__version__ = "1.2.0"
__version__ = "2.0.0"
from pymodmilter import _runtime_patches
from pyquarantine import _runtime_patches
import Milter
import logging
@@ -44,9 +44,9 @@ from email.policy import SMTPUTF8
from io import BytesIO
from netaddr import IPNetwork, AddrFormatError
from pymodmilter.base import CustomLogger, MilterMessage
from pymodmilter.base import replace_illegal_chars
from pymodmilter.rule import Rule
from pyquarantine.base import CustomLogger, MilterMessage
from pyquarantine.base import replace_illegal_chars
from pyquarantine.rule import Rule
class ModifyMilter(Milter.Base):

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
import encodings

View File

@@ -1,21 +1,21 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = ["Action"]
from pymodmilter import modify, notify, storage
from pymodmilter.conditions import Conditions
from pyquarantine import modify, notify, storage
from pyquarantine.conditions import Conditions
class Action:

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [

View File

@@ -20,8 +20,8 @@ import logging.handlers
import sys
import time
from pymodmilter.config import get_milter_config
from pymodmilter import __version__ as version
from pyquarantine.config import get_milter_config
from pyquarantine import __version__ as version
def _get_quarantine(quarantines, name):
@@ -316,7 +316,7 @@ def main():
formatter_class=formatter_class)
parser.add_argument(
"-c", "--config", help="Config file to read.",
default="/etc/pymodmilter/pymodmilter.conf")
default="/etc/pyquarantine/pyquarantine.conf")
parser.add_argument(
"-d", "--debug",
help="Log debugging messages.",

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = ["Conditions"]
@@ -18,8 +18,8 @@ import logging
import re
from netaddr import IPAddress, IPNetwork, AddrFormatError
from pymodmilter import CustomLogger
from pymodmilter.whitelist import DatabaseWhitelist
from pyquarantine import CustomLogger
from pyquarantine.whitelist import DatabaseWhitelist
class Conditions:

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [

View File

@@ -1,4 +1,4 @@
# This is an example /etc/pymodmilter.conf file.
# This is an example /etc/pyquarantine/pyquarantine.conf file.
# Copy it into place before use.
#
# The file is in JSON format.
@@ -176,14 +176,14 @@
# Notes: Path to a file which contains the html representation of the disclaimer.
# Value: [ FILE_PATH ]
#
"html_template": "/etc/pymodmilter/templates/disclaimer_html.template",
"html_template": "/etc/pyquarantine/templates/disclaimer_html.template",
# Option: text_template
# Type: String
# Notes: Path to a file which contains the text representation of the disclaimer.
# Value: [ FILE_PATH ]
#
"text_template": "/etc/pymodmilter/templates/disclaimer_text.template",
"text_template": "/etc/pyquarantine/templates/disclaimer_text.template",
# Option: error_policy
# Type: String

View File

@@ -0,0 +1,29 @@
<html>
<body>
<h1>Quarantine notification</h1>
<table>
<tr>
<td><b>Envelope-From:</b></td>
<td>{ENVELOPE_FROM}</td>
</tr>
<tr>
<td><b>From:</b></td>
<td>{FROM}</td>
</tr>
<tr>
<td><b>Envelope-To:</b></td>
<td>{ENVELOPE_TO}</td>
</tr>
<tr>
<td><b>To:</b></td>
<td>{TO}</td>
</tr>
<tr>
<td><b>Subject:</b></td>
<td>{SUBJECT}</td>
</tr>
</table><br/>
<h2>Preview of the original e-mail</h2>
{HTML_TEXT}
</body>
</html>

BIN
pyquarantine/docs/templates/removed.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
import logging

View File

@@ -1,8 +1,8 @@
# /etc/conf.d/pymodmilter: config file for /etc/init.d/pymodmilter
# /etc/conf.d/pyquarantine: config file for /etc/init.d/pyquarantine
# Start the daemon as the user. You can optionally append a group name here also.
# USER="daemon"
# USER="daemon:nobody"
# Optional parameters for pymodmilter
# Optional parameters for pyquarantine
# MILTER_OPTS=""

View File

@@ -4,7 +4,7 @@ user=${USER:-daemon}
milter_opts="${MILTER_OPTS:-}"
pidfile="/run/${RC_SVCNAME}.pid"
command="/usr/bin/pymodmilter"
command="/usr/bin/pyquarantine-milter"
command_args="${milter_opts}"
command_background=true
command_user="${user}"

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [
@@ -30,8 +30,8 @@ from copy import copy
from email.message import MIMEPart
from email.policy import SMTPUTF8
from pymodmilter import replace_illegal_chars
from pymodmilter.base import CustomLogger
from pyquarantine import replace_illegal_chars
from pyquarantine.base import CustomLogger
class AddHeader:

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [
@@ -30,8 +30,8 @@ from html import escape
from os.path import basename
from urllib.parse import quote
from pymodmilter.base import CustomLogger
from pymodmilter import mailer
from pyquarantine.base import CustomLogger
from pyquarantine import mailer
class BaseNotification:

View File

@@ -1,21 +1,21 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = ["Rule"]
from pymodmilter.action import Action
from pymodmilter.conditions import Conditions
from pyquarantine.action import Action
from pyquarantine.conditions import Conditions
class Rule:

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = ["main"]
@@ -20,25 +20,25 @@ import logging
import logging.handlers
import sys
from pymodmilter import mailer
from pymodmilter import ModifyMilter
from pymodmilter import __version__ as version
from pymodmilter.config import get_milter_config
from pyquarantine import mailer
from pyquarantine import ModifyMilter
from pyquarantine import __version__ as version
from pyquarantine.config import get_milter_config
def main():
python_version = ".".join([str(v) for v in sys.version_info[0:3]])
python_version = f"{python_version}-{sys.version_info[3]}"
"Run PyMod-Milter."
"Run pyquarantine."
parser = argparse.ArgumentParser(
description="PyMod milter daemon",
description="pyquarantine-milter daemon",
formatter_class=lambda prog: argparse.HelpFormatter(
prog, max_help_position=45, width=140))
parser.add_argument(
"-c", "--config", help="Config file to read.",
default="/etc/pymodmilter/pymodmilter.conf")
default="/etc/pyquarantine/pyquarantine.conf")
parser.add_argument(
"-s",
@@ -125,10 +125,10 @@ def main():
sysloghandler = logging.handlers.SysLogHandler(
address="/dev/log", facility=logging.handlers.SysLogHandler.LOG_MAIL)
sysloghandler.setFormatter(
logging.Formatter("pymodmilter: %(message)s"))
logging.Formatter("pyquarantine: %(message)s"))
root_logger.addHandler(sysloghandler)
logger.info("pymodmilter starting")
logger.info("pyquarantine-milter starting")
# register milter factory class
Milter.factory = ModifyMilter
@@ -139,13 +139,13 @@ def main():
rc = 0
try:
Milter.runmilter("pymodmilter", socketname=socket, timeout=600)
Milter.runmilter("pyquarantine", socketname=socket, timeout=600)
except Milter.milter.error as e:
logger.error(e)
rc = 255
mailer.queue.put(None)
logger.info("pymodmilter stopped")
logger.info("pyquarantine-milter stopped")
sys.exit(rc)

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [
@@ -27,10 +27,10 @@ from datetime import datetime
from glob import glob
from time import gmtime
from pymodmilter.base import CustomLogger
from pymodmilter.conditions import Conditions
from pymodmilter.config import ActionConfig
from pymodmilter.notify import Notify
from pyquarantine.base import CustomLogger
from pyquarantine.conditions import Conditions
from pyquarantine.config import ActionConfig
from pyquarantine.notify import Notify
class BaseMailStorage:

View File

@@ -1,15 +1,15 @@
# PyMod-Milter is free software: you can redistribute it and/or modify
# pyquarantine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyMod-Milter is distributed in the hope that it will be useful,
# pyquarantine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyMod-Milter. If not, see <http://www.gnu.org/licenses/>.
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
#
__all__ = [

View File

@@ -1,2 +1,2 @@
[metadata]
version = attr: pymodmilter.__version__
version = attr: pyquarantine.__version__

View File

@@ -4,14 +4,14 @@ def read_file(fname):
with open(fname, 'r') as f:
return f.read()
setup(name = "pymodmilter",
setup(name = "pyquarantine",
author = "Thomas Oettli",
author_email = "spacefreak@noop.ch",
description = "A pymilter based sendmail/postfix pre-queue filter.",
license = "GPL 3",
keywords = "header quarantine milter",
url = "https://github.com/spacefreak86/pymodmilter",
packages = ["pymodmilter"],
url = "https://github.com/spacefreak86/pyquarantine",
packages = ["pyquarantine"],
long_description = read_file("README.md"),
long_description_content_type = "text/markdown",
classifiers = [
@@ -28,20 +28,23 @@ setup(name = "pymodmilter",
include_package_data = True,
entry_points = {
"console_scripts": [
"pymodmilter=pymodmilter.run:main"
"pyquarantine-milter=pyquarantine.run:main",
"pyquarantine=pyquarantine.run:main",
]
},
data_files = [
(
"/etc/pymodmilter",
"/etc/pyquarantine",
[
"pymodmilter/docs/pymodmilter.conf.example"
"pyquarantine/docs/pyquarantine.conf.example"
]
), (
"/etc/pymodmilter/templates",
"/etc/pyquarantine/templates",
[
"pymodmilter/docs/templates/disclaimer_html.template",
"pymodmilter/docs/templates/disclaimer_text.template"
"pyquarantine/docs/templates/disclaimer_html.template",
"pyquarantine/docs/templates/disclaimer_text.template",
"pyquarantine/docs/templates/notification.template",
"pyquarantine/docs/templates/removed.png"
]
)
],

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env python
import sys
import pymodmilter.run
if __name__ == '__main__':
sys.exit(
pymodmilter.run.main()
)