Barry Warsaw pushed to branch master at mailman / Mailman Core

Commits:
8071d4a2 by Aurélien Bompard at 2017-11-09T23:04:44+01:00
Don't assume the list-id from the list fqdn

Fixes: #428

- - - - -
06764cdd by Barry Warsaw at 2017-11-10T15:25:46+00:00
Merge branch 'fix-renaming' into 'master'

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

Closes #428

See merge request mailman/mailman!334
- - - - -


5 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/model/listmanager.py
- src/mailman/model/tests/test_listmanager.py
- src/mailman/runners/lmtp.py
- src/mailman/runners/tests/test_lmtp.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -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
 ------------


=====================================
src/mailman/model/listmanager.py
=====================================
--- a/src/mailman/model/listmanager.py
+++ b/src/mailman/model/listmanager.py
@@ -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):


=====================================
src/mailman/model/tests/test_listmanager.py
=====================================
--- a/src/mailman/model/tests/test_listmanager.py
+++ b/src/mailman/model/tests/test_listmanager.py
@@ -153,6 +153,15 @@ class TestListManager(unittest.TestCase):
         self.assertEqual(list_manager.get_by_fqdn('a...@example.com'), ant)
         self.assertIsNone(list_manager.get_by_fqdn('ant.example.com'))
 
+    def test_find_by_fqdn_renamed(self):
+        ant = create_list('a...@example.com')
+        ant.list_name = 'renamed'
+        self.assertEqual(ant.posting_address, 'rena...@example.com')
+        self.assertEqual(ant.list_id, 'ant.example.com')
+        list_manager = getUtility(IListManager)
+        self.assertEqual(list_manager.get_by_fqdn('rena...@example.com'), ant)
+        self.assertIsNone(list_manager.get_by_fqdn('a...@example.com'))
+
 
 class TestListLifecycleEvents(unittest.TestCase):
     layer = ConfigLayer


=====================================
src/mailman/runners/lmtp.py
=====================================
--- a/src/mailman/runners/lmtp.py
+++ b/src/mailman/runners/lmtp.py
@@ -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)


=====================================
src/mailman/runners/tests/test_lmtp.py
=====================================
--- a/src/mailman/runners/tests/test_lmtp.py
+++ b/src/mailman/runners/tests/test_lmtp.py
@@ -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, 'rena...@example.com')
+        self._lmtp.sendmail('a...@example.com', ['rena...@example.com'], """\
+From: a...@example.com
+To: rena...@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."""



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/31f434d0866dbab5ebb4748fa9987eaac475eb0d...06764cdd23f11539ac47b21b6b066b1ca40ababb

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/31f434d0866dbab5ebb4748fa9987eaac475eb0d...06764cdd23f11539ac47b21b6b066b1ca40ababb
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to