filtermail: use single SMTP connection to reinject mails

This commit is contained in:
link2xt
2024-07-13 00:04:29 +00:00
parent 1eca8aa143
commit 2a3495090d

View File

@@ -143,12 +143,18 @@ def check_encrypted(message):
async def asyncmain_beforequeue(config): async def asyncmain_beforequeue(config):
port = config.filtermail_smtp_port port = config.filtermail_smtp_port
Controller(BeforeQueueHandler(config), hostname="127.0.0.1", port=port).start() smtp_client = SMTPClient("localhost", config.postfix_reinject_port)
Controller(
BeforeQueueHandler(config, smtp_client=smtp_client),
hostname="127.0.0.1",
port=port,
).start()
class BeforeQueueHandler: class BeforeQueueHandler:
def __init__(self, config): def __init__(self, config, smtp_client):
self.config = config self.config = config
self.smtp_client = smtp_client
self.send_rate_limiter = SendRateLimiter() self.send_rate_limiter = SendRateLimiter()
async def handle_MAIL(self, server, session, envelope, address, mail_options): async def handle_MAIL(self, server, session, envelope, address, mail_options):
@@ -170,8 +176,9 @@ class BeforeQueueHandler:
if error: if error:
return error return error
logging.info("re-injecting the mail that passed checks") logging.info("re-injecting the mail that passed checks")
client = SMTPClient("localhost", self.config.postfix_reinject_port) self.smtp_client.sendmail(
client.sendmail(envelope.mail_from, envelope.rcpt_tos, envelope.content) envelope.mail_from, envelope.rcpt_tos, envelope.content
)
return "250 OK" return "250 OK"
def check_DATA(self, envelope): def check_DATA(self, envelope):