diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 6cb1c7fbe..d614aaeb9 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -126,9 +126,6 @@ services: dev: aliases: - mail - ports: - - "5005:5005" - - "5006:5006" volumes: home: diff --git a/docker/mail.Dockerfile b/docker/mail.Dockerfile index e0d82af41..c30ca8ec3 100644 --- a/docker/mail.Dockerfile +++ b/docker/mail.Dockerfile @@ -1,13 +1,8 @@ -FROM golang:rc-alpine -RUN apk add --no-cache git -RUN apk add --no-cache gcc -RUN apk add --no-cache musl-dev -RUN git clone "https://github.com/jamillosantos/mailslurper.git" /opt/mailslurper -WORKDIR /opt/mailslurper/cmd/mailslurper -RUN go get github.com/mjibson/esc -RUN cd /opt/mailslurper/cmd/mailslurper -COPY ./mailslurper.conf config.json -RUN go get -RUN go generate -RUN go build -ENTRYPOINT ["/opt/mailslurper/cmd/mailslurper/mailslurper"] +FROM debian:unstable + +RUN apt-get update && apt-get install -y python3 python3-aiosmtpd python3-termcolor + +WORKDIR /opt/mail +COPY ./mail.py mail.py + +ENTRYPOINT ["python3", "mail.py"] diff --git a/docker/mail/mail.py b/docker/mail/mail.py new file mode 100644 index 000000000..1d4b28dec --- /dev/null +++ b/docker/mail/mail.py @@ -0,0 +1,49 @@ +import asyncio +import email +import email.policy +import sys + +from aiosmtpd.controller import Controller +from termcolor import cprint + + +class PycroftDebugging: + COLOR_HEADER = "blue" + COLOR_CONTENT_BORDER = "magenta" + + async def handle_DATA(self, server, session, envelope): + message = email.message_from_bytes(envelope.content, policy=email.policy.default) + + # Print headers + for key, value in message.items(): + cprint(f"{key}: {value}", self.COLOR_HEADER) + + # Print message parts, i.e. text/plain, text/html + for part in message.walk(): + try: + content = part.get_content() + except KeyError: + continue + + print() + content_type = part.get_content_type() + cprint(content_type, self.COLOR_CONTENT_BORDER) + cprint("⌄" * len(content_type), self.COLOR_CONTENT_BORDER) + print(content) + cprint("⌃" * len(content_type), self.COLOR_CONTENT_BORDER) + + print() + sys.stdout.flush() + + return "250 Message accepted for delivery" + + +controller = Controller(PycroftDebugging(), hostname="0.0.0.0", port=2500) +controller.start() + +loop = asyncio.get_event_loop() +try: + loop.run_forever() +finally: + loop.close() + controller.stop() diff --git a/docker/mailslurper.conf b/docker/mailslurper.conf deleted file mode 100644 index 09f03120f..000000000 --- a/docker/mailslurper.conf +++ /dev/null @@ -1,27 +0,0 @@ -{ - "wwwAddress": "0.0.0.0", - "wwwPort": 5005, - "wwwPublicURL": "", - "serviceAddress": "0.0.0.0", - "servicePort": 5006, - "servicePublicURL": "", - "smtpAddress": "0.0.0.0", - "smtpPort": 2500, - "dbEngine": "SQLite", - "dbHost": "", - "dbPort": 0, - "dbDatabase": "./mailslurper.db", - "dbUserName": "", - "dbPassword": "", - "maxWorkers": 1000, - "autoStartBrowser": false, - "keyFile": "", - "certFile": "", - "adminKeyFile": "", - "adminCertFile": "", - "authenticationScheme": "", - "authSecret": "", - "authSalt": "", - "authTimeoutInMinutes": 120, - "credentials": {} -} diff --git a/justfile b/justfile index 8f788ca8c..693a9d1de 100644 --- a/justfile +++ b/justfile @@ -129,3 +129,7 @@ _stop_all: _up +containers: {{ drc }} up --wait {{ containers }} + +show_emails: + {{ drc }} --progress=none up -d dev-celery-worker dev-mail + {{ drc }} logs --no-log-prefix -f dev-mail