From fc173dbac29b3bc4991e04446e5a737e50d719b6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 31 Oct 2021 04:12:18 +0000 Subject: [PATCH] Fixed all the issues --- Dockerfile | 1 + libertyforward.py | 21 ++++----------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index eb45672..cbf2145 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,5 +3,6 @@ FROM python:alpine WORKDIR /usr/src/app RUN pip install --no-cache requests configargparse xdg aiosmtpd COPY ./libertyforward.py . + EXPOSE 25 CMD ["python", "/usr/src/app/libertyforward.py"] diff --git a/libertyforward.py b/libertyforward.py index 2733bfb..7bd11ea 100644 --- a/libertyforward.py +++ b/libertyforward.py @@ -1,4 +1,6 @@ +from base64 import b64encode from time import sleep + import requests from aiosmtpd.controller import Controller from configargparse import ArgParser @@ -14,32 +16,17 @@ def parse_args(): return parser.parse_args() -class MailerHandlerMixin: - """Base class for the mail handlers""" - _api_token = None - - @property - def api_token(self): - return self._api_token - - @api_token.setter - def api_token(self, value): - self._api_token = value - - class KingMailerHandler(object): async def handle_DATA(self, server, session, envelope): - print('Incoming mesage from: {}'.format(envelope.mail_from), flush=True) payload = { 'mail_from': envelope.mail_from, 'rcpt_to': envelope.rcpt_tos, - 'data': envelope.content + 'data': b64encode(envelope.original_content).decode() } headers = {'X-Server-API-Key': self.api_token} response = requests.post('https://kingmailer.org/api/v1/send/raw', json=payload, headers=headers) resp_dict = response.json() - print(resp_dict, flush=True) if resp_dict['status'] == 'success': print('Message accepted', flush=True) return '250 Message accepted for delivery' @@ -53,7 +40,7 @@ if __name__ == '__main__': args = parse_args() handler = KingMailerHandler() handler.api_token = args.api_token - controller = Controller(handler, hostname='127.0.0.1', port=25) + controller = Controller(handler, hostname='0.0.0.0', port=25) print('Starting controller thread', flush=True) controller.start() while True: