Skip to content

Commit

Permalink
Replace Mailslurper with script printing to cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
FestplattenSchnitzel committed Feb 14, 2024
1 parent 8d62480 commit 7e8f605
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
3 changes: 0 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ services:
dev:
aliases:
- mail
ports:
- "5005:5005"
- "5006:5006"

volumes:
home:
Expand Down
21 changes: 8 additions & 13 deletions docker/mail.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
49 changes: 49 additions & 0 deletions docker/mail/mail.py
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 0 additions & 27 deletions docker/mailslurper.conf

This file was deleted.

4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7e8f605

Please sign in to comment.