summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2017-04-06 18:58:44 -0400
committerBarry Warsaw2017-04-06 18:58:44 -0400
commit845eaedfdffd879af2ef3a50227f3b3fa763d26e (patch)
treef042fafb500ccc7a67a001281cf1124afd9d6e97
parent263711b3b7988c7c474e3b8952dc7e0f02f04fa2 (diff)
downloadmailman-845eaedfdffd879af2ef3a50227f3b3fa763d26e.tar.gz
mailman-845eaedfdffd879af2ef3a50227f3b3fa763d26e.tar.zst
mailman-845eaedfdffd879af2ef3a50227f3b3fa763d26e.zip
-rw-r--r--src/mailman/runners/lmtp.py20
-rw-r--r--src/mailman/testing/mta.py25
2 files changed, 19 insertions, 26 deletions
diff --git a/src/mailman/runners/lmtp.py b/src/mailman/runners/lmtp.py
index f24107bd7..d19cbd763 100644
--- a/src/mailman/runners/lmtp.py
+++ b/src/mailman/runners/lmtp.py
@@ -35,7 +35,7 @@ so that the peer mail server can provide better diagnostics.
"""
import email
-import socket
+import asyncio
import logging
from aiosmtpd.controller import Controller
@@ -122,19 +122,20 @@ def split_recipient(address):
class LMTPHandler:
+ @asyncio.coroutine
@transactional
- def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
+ def handle_DATA(self, server, session, envelope):
try:
# Refresh the list of list names every time we process a message
# since the set of mailing lists could have changed.
listnames = set(getUtility(IListManager).names)
# Parse the message data. If there are any defects in the
# message, reject it right away; it's probably spam.
- msg = email.message_from_bytes(data, Message)
+ msg = email.message_from_bytes(envelope.content, Message)
except Exception:
elog.exception('LMTP message parsing')
config.db.abort()
- return CRLF.join(ERR_451 for to in rcpttos)
+ return CRLF.join(ERR_451 for to in envelope.rcpt_tos)
# Do basic post-processing of the message, checking it for defects or
# other missing information.
message_id = msg.get('message-id')
@@ -142,9 +143,9 @@ class LMTPHandler:
return ERR_550_MID
if msg.defects:
return ERR_501
- msg.original_size = len(data)
+ msg.original_size = len(envelope.content)
add_message_hash(msg)
- msg['X-MailFrom'] = mailfrom
+ msg['X-MailFrom'] = envelope.mail_from
# RFC 2033 requires us to return a status code for every recipient.
status = []
# Now for each address in the recipients, parse the address to first
@@ -152,7 +153,7 @@ class LMTPHandler:
# the message to the appropriate place and record a 250 status for
# that recipient. If not, record a failure status for that recipient.
received_time = now()
- for to in rcpttos:
+ for to in envelope.rcpt_tos:
try:
to = parseaddr(to)[1].lower()
local, subaddress, domain = split_recipient(to)
@@ -219,11 +220,6 @@ class LMTPController(Controller):
server.__ident__ = 'GNU Mailman LMTP runner 2.0'
return server
- def make_socket(self):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
- return sock
-
@public
class LMTPRunner(Runner):
diff --git a/src/mailman/testing/mta.py b/src/mailman/testing/mta.py
index 6b803b41a..ef4d39233 100644
--- a/src/mailman/testing/mta.py
+++ b/src/mailman/testing/mta.py
@@ -17,7 +17,6 @@
"""Fake MTA for testing purposes."""
-import socket
import asyncio
import smtplib
@@ -54,6 +53,17 @@ class ConnectionCountingHandler(MessageHandler):
def handle_message(self, message):
self._msg_queue.put(message)
+ @asyncio.coroutine
+ def handle_EHLO(self, server, session, envelope, hostname):
+ session.host_name = hostname
+ yield from server.push('250-AUTH PLAIN')
+ return '250 HELP'
+
+ @asyncio.coroutine
+ def handle_RSET(self, server, session, envelope):
+ self.connection_count = 0
+ return '250 OK'
+
class ConnectionCountingSMTP(SMTP):
def __init__(self, handler, oob_queue, err_queue, *args, **kws):
@@ -96,14 +106,6 @@ class ConnectionCountingSMTP(SMTP):
yield from self.push('571 Bad authentication')
@asyncio.coroutine
- def ehlo_hook(self):
- yield from self.push('250-AUTH PLAIN')
-
- @asyncio.coroutine
- def rset_hook(self):
- self.event_handler.connection_count = 0
-
- @asyncio.coroutine
def smtp_STAT(self, arg):
"""Cause the server to send statistics to its controller."""
# Do not count the connection caused by the STAT connect.
@@ -175,11 +177,6 @@ class ConnectionCountingController(Controller):
return ConnectionCountingSMTP(
self.handler, self._oob_queue, self.err_queue)
- def make_socket(self):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
- return sock
-
def start(self):
super().start()
# Reset the connection statistics, since the base class's start()