Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core

Commits:
5ae34e81 by Mark Sapiro at 2018-07-27T03:28:16Z
Import all acceptable_aliases as regexps.

- - - - -
55443b04 by Mark Sapiro at 2018-07-27T16:45:09Z
Merge branch 'import' into 'master'

Import all acceptable_aliases as regexps.

Closes #496

See merge request mailman/mailman!406
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/utilities/importer.py
- src/mailman/utilities/tests/test_import.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -10,6 +10,12 @@ Here is a history of user visible changes to Mailman.
 
 3.3.0 -- "Tom Sawyer"
 =====================
+(20xx-xx-xx)
+
+Command line
+------------
+* The ``mailman import21`` command properly converts all acceptable_aliases
+  to regexps.  (Closes #496)
 
 
 3.2.0 -- "La Villa Strangiato"


=====================================
src/mailman/utilities/importer.py
=====================================
@@ -351,12 +351,14 @@ def import_config_pck(mlist, config_dict):
         if len(address) == 0:
             continue
         address = bytes_to_str(address)
-        try:
-            alias_set.add(address)
-        except ValueError:
-            # When .add() rejects this, the line probably contains a regular
-            # expression.  Make that explicit for MM3.
-            alias_set.add('^' + address)
+        # All 2.1 acceptable aliases are regexps whether or not they start
+        # with '^' or contain '@'.
+        if not address.startswith('^'):
+            address = '^' + address
+        # This used to be in a try which would catch ValueError and add a '^',
+        # but .add() would not raise ValueError if address contained '@' and
+        # that needs the '^' too as it could be a regexp with an '@' in it.
+        alias_set.add(address)
     # Handle header_filter_rules conversion to header_matches.
     header_matches = IHeaderMatchList(mlist)
     header_filter_rules = config_dict.get('header_filter_rules', [])


=====================================
src/mailman/utilities/tests/test_import.py
=====================================
@@ -265,7 +265,9 @@ class TestBasicImport(unittest.TestCase):
             self.assertTrue(IBanManager(self._mlist).is_banned(addr))
 
     def test_acceptable_aliases(self):
-        # This used to be a plain-text field (values are newline-separated).
+        # This used to be a plain-text field (values are newline-separated)
+        # but values were interpreted as regexps even without '^' so we need
+        # to add the '^'.
         aliases = ['ali...@example.com',
                    'ali...@exemple.com',
                    'non-ascii-\x...@example.com',
@@ -273,7 +275,8 @@ class TestBasicImport(unittest.TestCase):
         self._pckdict['acceptable_aliases'] = list_to_string(aliases)
         self._import()
         alias_set = IAcceptableAliasSet(self._mlist)
-        self.assertEqual(sorted(alias_set.aliases), aliases)
+        self.assertEqual(sorted(alias_set.aliases),
+                         [('^' + alias) for alias in aliases])
 
     def test_acceptable_aliases_invalid(self):
         # Values without an '@' sign used to be matched against the local
@@ -287,13 +290,23 @@ class TestBasicImport(unittest.TestCase):
 
     def test_acceptable_aliases_as_list(self):
         # In some versions of the pickle, this can be a list, not a string
-        # (seen in the wild).
+        # (seen in the wild).  We still need to add the '^'.
         aliases = [b'ali...@example.com', b'ali...@exemple.com']
         self._pckdict['acceptable_aliases'] = aliases
         self._import()
         alias_set = IAcceptableAliasSet(self._mlist)
         self.assertEqual(sorted(alias_set.aliases),
-                         sorted(a.decode('utf-8') for a in aliases))
+                         sorted(('^' + a.decode('utf-8')) for a in aliases))
+
+    def test_dont_add_caret_if_present(self):
+        # The 2.1 alias could have had a leading '^' even though not required.
+        aliases = ['^ali...@example.com',
+                   '^alias2@.*',
+                   ]
+        self._pckdict['acceptable_aliases'] = list_to_string(aliases)
+        self._import()
+        alias_set = IAcceptableAliasSet(self._mlist)
+        self.assertEqual(sorted(alias_set.aliases), aliases)
 
     def test_info_non_ascii(self):
         # info can contain non-ascii characters.



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/6aecc2d65dd37d06fac640dae62dc45c16901516...55443b04ff185ca908b1dcd8261d8b2d0f67626e

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/6aecc2d65dd37d06fac640dae62dc45c16901516...55443b04ff185ca908b1dcd8261d8b2d0f67626e
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