From 3868e61f0be760ae62e318d33f3a9fb140c1c3d6 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Wed, 18 Dec 2019 14:25:09 +0100 Subject: [PATCH] Initial import of basic skeleton --- .gitignore | 1 + README.md | 0 main.py | 39 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 41 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..3b1bcf4 --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +import time +import sys +import logging + +import Milter +from Milter.utils import parse_addr + +# Basic logger that also logs to stdout +# TODO: Improve this a lot. +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +handler = logging.StreamHandler(sys.stdout) +handler.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +handler.setFormatter(formatter) + +logger.addHandler(handler) + +class SuspiciousFrom(Milter.Base): + def __init__(self): + self.id = Milter.uniqueID() + logger.info(f"{self.id} got fired up.") + + def header(self, field, value): + logger.info(f"{self.id} Got header: {field} --> {value}") + +def main(): + milter_socket = "inet:7777@127.0.0.1" + milter_timeout = 60 + Milter.factory = SuspiciousFrom + logger.info(f"Starting Milter.") + # This call blocks the main thread. + Milter.runmilter("SuspiciousFromMilter", milter_socket, milter_timeout, rmsock=False) + logger.info(f"Milter finished running.") + +if __name__ == "__main__": + logger.debug(f"Hello world!") + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6cef3a1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pymilter==1.0.4