Compare commits

...

2 Commits

4 changed files with 33 additions and 11 deletions

View File

@ -56,13 +56,14 @@ class PopCfg(ServerCfg):
class SmtpStartTLSCfg(ServerCfg):
server_type = "smtp_starttls"
smtputf8 = True # Not used yet
require_starttls = True
smtputf8 = True
port = 25
class SmtpCfg(ServerCfg):
server_type = "smtp_starttls"
smtputf8 = True # Not used yet
server_type = "smtp"
smtputf8 = True
port = 465

View File

@ -84,6 +84,8 @@ async def a_main(cfg: config.Config) -> None:
mails_path=Path(cfg.mails_path),
mbox_finder=mbox_finder,
ssl_context=stls_context,
require_starttls=stls.require_starttls,
smtputf8=stls.smtputf8,
)
servers.append(smtp_server_starttls)
elif scfg.server_type == "smtp":
@ -94,6 +96,7 @@ async def a_main(cfg: config.Config) -> None:
mails_path=Path(cfg.mails_path),
mbox_finder=mbox_finder,
ssl_context=get_tls_context(smtp.tls),
smtputf8=smtp.smtputf8,
)
servers.append(smtp_server)
else:

View File

@ -59,16 +59,20 @@ class MyHandler(AsyncMessage):
def protocol_factory_starttls(
mails_path: Path, mbox_finder: Callable[[str], list[str]], context: ssl.SSLContext
mails_path: Path,
mbox_finder: Callable[[str], list[str]],
context: ssl.SSLContext,
require_starttls: bool,
smtputf8: bool,
):
logger.info("Got smtp client cb starttls")
try:
handler = MyHandler(mails_path, mbox_finder)
smtp = SMTP(
handler=handler,
require_starttls=True,
require_starttls=require_starttls,
tls_context=context,
enable_SMTPUTF8=True,
enable_SMTPUTF8=smtputf8,
)
except:
logger.exception("Something went wrong")
@ -76,11 +80,13 @@ def protocol_factory_starttls(
return smtp
def protocol_factory(mails_path: Path, mbox_finder: Callable[[str], list[str]]):
def protocol_factory(
mails_path: Path, mbox_finder: Callable[[str], list[str]], smtputf8: bool
):
logger.info("Got smtp client cb")
try:
handler = MyHandler(mails_path, mbox_finder)
smtp = SMTP(handler=handler, enable_SMTPUTF8=True)
smtp = SMTP(handler=handler, enable_SMTPUTF8=smtputf8)
except:
logger.exception("Something went wrong")
raise
@ -93,13 +99,22 @@ async def create_smtp_server_starttls(
mails_path: Path,
mbox_finder: Callable[[str], list[str]],
ssl_context: ssl.SSLContext,
require_starttls: bool,
smtputf8: bool,
) -> asyncio.Server:
logging.info(
f"Starting SMTP STARTTLS server {host=}, {port=}, {mails_path=!s}, {ssl_context != None=}"
)
loop = asyncio.get_event_loop()
return await loop.create_server(
partial(protocol_factory_starttls, mails_path, mbox_finder, ssl_context),
partial(
protocol_factory_starttls,
mails_path,
mbox_finder,
ssl_context,
require_starttls,
smtputf8,
),
host=host,
port=port,
start_serving=False,
@ -111,14 +126,15 @@ async def create_smtp_server(
port: int,
mails_path: Path,
mbox_finder: Callable[[str], list[str]],
ssl_context: Optional[ssl.SSLContext] = None,
ssl_context: Optional[ssl.SSLContext],
smtputf8: bool,
) -> asyncio.Server:
logging.info(
f"Starting SMTP server {host=}, {port=}, {mails_path=!s}, {ssl_context != None=}"
)
loop = asyncio.get_event_loop()
return await loop.create_server(
partial(protocol_factory, mails_path, mbox_finder),
partial(protocol_factory, mails_path, mbox_finder, smtputf8),
host=host,
port=port,
ssl=ssl_context,

View File

@ -33,6 +33,8 @@ class TestSMTP(unittest.IsolatedAsyncioTestCase):
port=7996,
mails_path=MAILS_PATH,
mbox_finder=lambda addr: [TEST_MBOX],
ssl_context=None,
smtputf8=True,
)
self.task = asyncio.create_task(smtp_server.serve_forever())