Commit 8071d4a2 authored by Aurélien Bompard's avatar Aurélien Bompard

Don't assume the list-id from the list fqdn

Fixes: #428
parent 31f434d0
......@@ -40,6 +40,7 @@ Bugs
subaddresses can now be posted to. (Closes #433)
* The ``admin`` subaddress, a synonym for ``bounces`` and deprecated since
Mailman 2.1, has been removed. (Closes #435)
* Better support for changing the ``list_name`` property. (Closes #428)
Command line
------------
......
......@@ -74,8 +74,8 @@ class ListManager:
def get_by_fqdn(self, store, fqdn_listname):
"""See `IListManager`."""
listname, at, hostname = fqdn_listname.partition('@')
list_id = '{}.{}'.format(listname, hostname)
return store.query(MailingList).filter_by(_list_id=list_id).first()
return store.query(MailingList).filter_by(
list_name=listname, mail_host=hostname).first()
@dbconnection
def delete(self, store, mlist):
......
......@@ -153,6 +153,15 @@ class TestListManager(unittest.TestCase):
self.assertEqual(list_manager.get_by_fqdn('ant@example.com'), ant)
self.assertIsNone(list_manager.get_by_fqdn('ant.example.com'))
def test_find_by_fqdn_renamed(self):
ant = create_list('ant@example.com')
ant.list_name = 'renamed'
self.assertEqual(ant.posting_address, 'renamed@example.com')
self.assertEqual(ant.list_id, 'ant.example.com')
list_manager = getUtility(IListManager)
self.assertEqual(list_manager.get_by_fqdn('renamed@example.com'), ant)
self.assertIsNone(list_manager.get_by_fqdn('ant@example.com'))
class TestListLifecycleEvents(unittest.TestCase):
layer = ConfigLayer
......
......@@ -165,12 +165,12 @@ class LMTPHandler:
if listname not in listnames:
status.append(ERR_550)
continue
listid = '{}.{}'.format(local, domain)
mlist = getUtility(IListManager).get_by_fqdn(listname)
# The recipient is a valid mailing list. Find the subaddress
# if there is one, and set things up to enqueue to the proper
# queue.
queue = None
msgdata = dict(listid=listid,
msgdata = dict(listid=mlist.list_id,
original_size=msg.original_size,
received_time=received_time)
canonical_subaddress = SUBADDRESS_NAMES.get(subaddress)
......
......@@ -197,6 +197,24 @@ Subject: This will be recognized as a post to the -join list.
get_queue_messages('in', expected_count=1)
get_queue_messages('command', expected_count=0)
def test_mailing_list_with_different_address_and_list_id(self):
# A mailing list can be renamed, in which case the list_name
# will be different but the list_id will remain the same.
# https://gitlab.com/mailman/mailman/issues/428
with transaction():
self._mlist.list_name = 'renamed'
self.assertEqual(self._mlist.posting_address, 'renamed@example.com')
self._lmtp.sendmail('anne@example.com', ['renamed@example.com'], """\
From: anne@example.com
To: renamed@example.com
Message-ID: <ant>
Subject: This should be accepted.
""")
# The message is in the incoming queue but not the command queue.
items = get_queue_messages('in', expected_count=1)
self.assertEqual(items[0].msgdata['listid'], 'test.example.com')
class TestBugs(unittest.TestCase):
"""Test some LMTP related bugs."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment