From a83d523cd50a69ff586d64d18cf7ccdb56a40d0a Mon Sep 17 00:00:00 2001 From: Adon Metcalfe Date: Sun, 11 Oct 2020 02:05:00 +0800 Subject: [PATCH] increase logging, backout increased sizelimit due to bugginess --- mailfixer/Dockerfile | 3 ++- mailfixer/mailfixer.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/mailfixer/Dockerfile b/mailfixer/Dockerfile index b678787..c203fd2 100644 --- a/mailfixer/Dockerfile +++ b/mailfixer/Dockerfile @@ -2,8 +2,9 @@ FROM python:3 LABEL org.opencontainers.image.source https://github.com/dbca-wa/docker-postfix-mailrelay WORKDIR /usr/src/app -COPY . . +ADD requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +COPY . . EXPOSE 8025 diff --git a/mailfixer/mailfixer.py b/mailfixer/mailfixer.py index 1fca4c3..4fa345d 100755 --- a/mailfixer/mailfixer.py +++ b/mailfixer/mailfixer.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import os, time, email -from datetime import datetime +import os, email, logging, asyncio from email.mime.text import MIMEText from aiosmtpd.handlers import Proxy from aiosmtpd.controller import Controller @@ -10,7 +9,7 @@ class FixerHandler: async def handle_DATA(self, server, session, envelope): - print("Message from {} to {} received at {}".format(envelope.mail_from, envelope.rcpt_tos, datetime.now().isoformat())) + print("Message from {} to {}".format(envelope.mail_from, envelope.rcpt_tos)) msg = email.message_from_string(envelope.content.decode("utf-8")) if msg.get_content_maintype() != "text": content_types = [part.get_content_type() for part in msg.get_payload()] @@ -22,17 +21,18 @@ async def handle_DATA(self, server, session, envelope): return await proxy.handle_DATA(server, session, envelope) -class FatController(Controller): - def factory(self): - # bump up max message size to 150MB - return SMTP(self.handler, data_size_limit=150 * 1024 * 1024) +async def amain(loop): + handler = FixerHandler() + controller = Controller(handler, hostname="0.0.0.0", port=8025) + controller.start() if __name__ == "__main__": - handler = FixerHandler() - controller = FatController(handler, hostname="0.0.0.0") - controller.start() - print("SMTP server running.") - while time.sleep(900) is None: - print("Still running: {}".format(datetime.now().isoformat())) - controller.stop() + logging.basicConfig(level=logging.INFO) + loop = asyncio.get_event_loop() + loop.create_task(amain(loop=loop)) + try: + print("SMTP server running.") + loop.run_forever() + except KeyboardInterrupt: + pass