Skip to content

Commit

Permalink
increase logging, backout increased sizelimit due to bugginess
Browse files Browse the repository at this point in the history
  • Loading branch information
adonm committed Oct 10, 2020
1 parent cc85f8a commit a83d523
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion mailfixer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions mailfixer/mailfixer.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()]
Expand All @@ -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

0 comments on commit a83d523

Please sign in to comment.