From ad5b781f59f8c7290ee4b67ea766d58021af4fbb Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 19 Aug 2025 15:26:24 -0300 Subject: [PATCH 1/3] chore: smtpd debug server -> aiosmtpd --- .vscode/tasks.json | 5 +++-- docker/scripts/app-init.sh | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4bd0b99363..bd0beb3d6a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -105,10 +105,11 @@ "command": "/usr/local/bin/python", "args": [ "-m", - "smtpd", + "aiosmtpd", "-n", "-c", - "DebuggingServer", + "aiosmtpd.handlers.Debugging", + "-l", "localhost:2025" ], "presentation": { diff --git a/docker/scripts/app-init.sh b/docker/scripts/app-init.sh index 17e0c6c764..2018001d30 100755 --- a/docker/scripts/app-init.sh +++ b/docker/scripts/app-init.sh @@ -108,7 +108,7 @@ echo "Running initial checks..." if [ -z "$EDITOR_VSCODE" ]; then CODE=0 - python -m smtpd -n -c DebuggingServer localhost:2025 & + python -m aiosmtpd -n -c aiosmtpd.handlers.Debugging -l localhost:2025 & if [ -z "$*" ]; then echo "-----------------------------------------------------------------" echo "Ready!" From 018a4553de647eeb06e7fc1b2ae5f512da45f53c Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 19 Aug 2025 15:48:30 -0300 Subject: [PATCH 2/3] chore(dev): accept long SMTP lines --- .../utils/{test_smtpserver.py => aiosmtpd.py} | 21 +++++++++++++++++-- ietf/utils/test_runner.py | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) rename ietf/utils/{test_smtpserver.py => aiosmtpd.py} (72%) diff --git a/ietf/utils/test_smtpserver.py b/ietf/utils/aiosmtpd.py similarity index 72% rename from ietf/utils/test_smtpserver.py rename to ietf/utils/aiosmtpd.py index 40da758d66..3e4cd65dd9 100644 --- a/ietf/utils/test_smtpserver.py +++ b/ietf/utils/aiosmtpd.py @@ -1,10 +1,14 @@ # Copyright The IETF Trust 2014-2025, All Rights Reserved -# -*- coding: utf-8 -*- +"""aiosmtpd-related utilities +These are for testing / dev use. If you're using this for production code, think very +hard about the choices you're making... +""" +from aiosmtpd import handlers from aiosmtpd.controller import Controller from aiosmtpd.smtp import SMTP from email.utils import parseaddr -from typing import Optional +from typing import Optional, TextIO class SMTPTestHandler: @@ -54,3 +58,16 @@ def start(self): def stop(self): self.controller.stop() + + +class DevDebuggingHandler(handlers.Debugging): + """Debugging handler for use in dev ONLY""" + def __init__(self, stream: Optional[TextIO] = None): + # Allow longer lines than the 1001 that RFC 5321 requires. As of 2025-04-16 the + # datatracker emits some non-compliant messages. + # See https://aiosmtpd.aio-libs.org/en/latest/smtp.html + # Doing this in a handler class is a huge hack. Tests all pass with this set + # to 4000, but make the limit longer for dev just in case. + SMTP.line_length_limit = 10000 + super().__init__(stream) + diff --git a/ietf/utils/test_runner.py b/ietf/utils/test_runner.py index 08e81fd15c..1a3d4e5c3d 100644 --- a/ietf/utils/test_runner.py +++ b/ietf/utils/test_runner.py @@ -82,7 +82,7 @@ import ietf import ietf.utils.mail from ietf.utils.management.commands import pyflakes -from ietf.utils.test_smtpserver import SMTPTestServerDriver +from ietf.utils.aiosmtpd import SMTPTestServerDriver from ietf.utils.test_utils import TestCase from mypy_boto3_s3.service_resource import Bucket From 889db990b65d1992f7a0c4730fc3388ec5bb3c6c Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 19 Aug 2025 15:50:21 -0300 Subject: [PATCH 3/3] chore(dev): use correct aiosmtpd handler --- .vscode/tasks.json | 2 +- docker/scripts/app-init.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bd0beb3d6a..8b36b0e6ac 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -108,7 +108,7 @@ "aiosmtpd", "-n", "-c", - "aiosmtpd.handlers.Debugging", + "ietf.utils.aiosmtpd.DevDebuggingHandler", "-l", "localhost:2025" ], diff --git a/docker/scripts/app-init.sh b/docker/scripts/app-init.sh index 2018001d30..1d895cdf53 100755 --- a/docker/scripts/app-init.sh +++ b/docker/scripts/app-init.sh @@ -108,7 +108,7 @@ echo "Running initial checks..." if [ -z "$EDITOR_VSCODE" ]; then CODE=0 - python -m aiosmtpd -n -c aiosmtpd.handlers.Debugging -l localhost:2025 & + python -m aiosmtpd -n -c ietf.utils.aiosmtpd.DevDebuggingHandler -l localhost:2025 & if [ -z "$*" ]; then echo "-----------------------------------------------------------------" echo "Ready!"