Fixed all the issues

master
Raoul Snyman 2021-10-31 04:12:18 +00:00
parent 825c9f575a
commit fc173dbac2
2 changed files with 5 additions and 17 deletions

View File

@ -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"]

View File

@ -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: