diff options
| author | Barry Warsaw | 2015-10-20 22:48:59 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2015-10-20 22:48:59 -0400 |
| commit | 5f917c8aec735608cb85195e691fb68fbb835af7 (patch) | |
| tree | 2a963a102f7610a118cd211711c4df90aada94cd /src/mailman/utilities | |
| parent | adb9e3164ee1e19802a4373e76b42b1435d1e687 (diff) | |
| download | mailman-5f917c8aec735608cb85195e691fb68fbb835af7.tar.gz mailman-5f917c8aec735608cb85195e691fb68fbb835af7.tar.zst mailman-5f917c8aec735608cb85195e691fb68fbb835af7.zip | |
Diffstat (limited to 'src/mailman/utilities')
| -rw-r--r-- | src/mailman/utilities/importer.py | 41 | ||||
| -rw-r--r-- | src/mailman/utilities/tests/test_import.py | 66 |
2 files changed, 59 insertions, 48 deletions
diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py index 4e3eab6cf..a15eac7f9 100644 --- a/src/mailman/utilities/importer.py +++ b/src/mailman/utilities/importer.py @@ -39,7 +39,6 @@ from mailman.interfaces.archiver import ArchivePolicy from mailman.interfaces.autorespond import ResponseAction from mailman.interfaces.bans import IBanManager from mailman.interfaces.bounce import UnrecognizedBounceDisposition -from mailman.interfaces.chain import LinkAction from mailman.interfaces.digests import DigestFrequency from mailman.interfaces.languages import ILanguageManager from mailman.interfaces.mailinglist import IAcceptableAliasSet, IHeaderMatchSet @@ -132,18 +131,18 @@ def nonmember_action_mapping(value): def action_to_chain(value): # Converts an action number in Mailman 2.1 to the name of the corresponding - # chain in 3.x. The actions "approve", "subscribe" and "unsubscribe" are - # ignored. The defer action is converted to None, because it is not a jump - # to a terminal chain. + # chain in 3.x. The actions 'approve', 'subscribe' and 'unsubscribe' are + # ignored. The defer action is converted to None, because it is not + # a jump to a terminal chain. return { 0: None, - #1: "approve", - 2: "reject", - 3: "discard", - #4: "subscribe", - #5: "unsubscribe", - 6: "accept", - 7: "hold", + #1: 'approve', + 2: 'reject', + 3: 'discard', + #4: 'subscribe', + #5: 'unsubscribe', + 6: 'accept', + 7: 'hold', }[value] @@ -333,7 +332,7 @@ def import_config_pck(mlist, config_dict): # When .add() rejects this, the line probably contains a regular # expression. Make that explicit for MM3. alias_set.add('^' + address) - # Handle header_filter_rules conversion to header_matches + # Handle header_filter_rules conversion to header_matches. header_match_set = IHeaderMatchSet(mlist) header_filter_rules = config_dict.get('header_filter_rules', []) for line_patterns, action, _unused in header_filter_rules: @@ -343,26 +342,28 @@ def import_config_pck(mlist, config_dict): log.warning('Unsupported header_filter_rules action: %r', action) continue - # now split the pattern in a header and a pattern + # Now split the line into a header and a pattern. for line_pattern in line_patterns.splitlines(): - if not line_pattern.strip(): + if len(line_pattern.strip()) == 0: continue for sep in (': ', ':.', ':'): header, sep, pattern = line_pattern.partition(sep) if sep: - break # found it. + # We found it. + break else: - # matches any header. Those are not supported. XXX + # Matches any header, which is not supported. XXX log.warning('Unsupported header_filter_rules pattern: %r', line_pattern) continue - header = header.strip().lstrip("^").lower() + header = header.strip().lstrip('^').lower() header = header.replace('\\', '') if not header: - log.warning('Can\'t parse the header in header_filter_rule: %r', - line_pattern) + log.warning( + 'Cannot parse the header in header_filter_rule: %r', + line_pattern) continue - if not pattern: + if len(pattern) == 0: # The line matched only the header, therefore the header can # be anything. pattern = '.*' diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py index 64f8e061f..e687e8a00 100644 --- a/src/mailman/utilities/tests/test_import.py +++ b/src/mailman/utilities/tests/test_import.py @@ -44,7 +44,7 @@ from mailman.interfaces.bans import IBanManager from mailman.interfaces.bounce import UnrecognizedBounceDisposition from mailman.interfaces.languages import ILanguageManager from mailman.interfaces.mailinglist import ( - IAcceptableAliasSet, IHeaderMatchSet, SubscriptionPolicy) + IAcceptableAliasSet, SubscriptionPolicy) from mailman.interfaces.member import DeliveryMode, DeliveryStatus from mailman.interfaces.nntp import NewsgroupModeration from mailman.interfaces.templates import ITemplateLoader @@ -344,7 +344,8 @@ class TestBasicImport(unittest.TestCase): ('X-Git-Module: rhq.*git', 6, False), ('Approved: verysecretpassword', 6, False), ('^Subject: dev-\r\n^Subject: staging-', 3, False), - ('from: .*info@aolanchem.com\r\nfrom: .*@jw-express.com', 2, False), + ('from: .*info@aolanchem.com\r\nfrom: .*@jw-express.com', + 2, False), ('^Received: from smtp-.*\\.fedoraproject\\.org\r\n' '^Received: from mx.*\\.redhat.com\r\n' '^Resent-date:\r\n' @@ -356,15 +357,17 @@ class TestBasicImport(unittest.TestCase): ('^Received: from fedorahosted\\.org.*by fedorahosted\\.org\r\n' '^Received: from hosted.*\\.fedoraproject.org.*by ' 'hosted.*\\.fedoraproject\\.org\r\n' - '^Received: from hosted.*\\.fedoraproject.org.*by fedoraproject\\.org\r\n' - '^Received: from hosted.*\\.fedoraproject.org.*by fedorahosted\\.org', + '^Received: from hosted.*\\.fedoraproject.org.*by ' + 'fedoraproject\\.org\r\n' + '^Received: from hosted.*\\.fedoraproject.org.*by ' + 'fedorahosted\\.org', 6, False), ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual( - [ (hm.header, hm.pattern, hm.chain) - for hm in self._mlist.header_matches ], [ + [(hm.header, hm.pattern, hm.chain) + for hm in self._mlist.header_matches ], [ ('x-spam-status', 'Yes.*', 'discard'), ('x-spam-status', 'Yes', 'reject'), ('x-spam-level', '\\*\\*\\*.*$', 'discard'), @@ -386,19 +389,26 @@ class TestBasicImport(unittest.TestCase): ('resent-message-id', '.*', 'hold'), ('resent-to', '.*', 'hold'), ('subject', '[^mtv]', 'hold'), - ('received', 'from fedorahosted\\.org.*by fedorahosted\\.org', 'accept'), - ('received', 'from hosted.*\\.fedoraproject.org.*by hosted.*\\.fedoraproject\\.org', 'accept'), - ('received', 'from hosted.*\\.fedoraproject.org.*by fedoraproject\\.org', 'accept'), - ('received', 'from hosted.*\\.fedoraproject.org.*by fedorahosted\\.org', 'accept'), + ('received', 'from fedorahosted\\.org.*by fedorahosted\\.org', + 'accept'), + ('received', + 'from hosted.*\\.fedoraproject.org.*by ' + 'hosted.*\\.fedoraproject\\.org', 'accept'), + ('received', + 'from hosted.*\\.fedoraproject.org.*by ' + 'fedoraproject\\.org', 'accept'), + ('received', + 'from hosted.*\\.fedoraproject.org.*by ' + 'fedorahosted\\.org', 'accept'), ]) loglines = error_log.read().strip() self.assertEqual(len(loglines), 0) def test_header_matches_header_only(self): - # Check that an empty pattern is skipped + # Check that an empty pattern is skipped. self._pckdict['header_filter_rules'] = [ ('SomeHeaderName', 3, False), - ] + ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual(self._mlist.header_matches, []) @@ -406,10 +416,10 @@ class TestBasicImport(unittest.TestCase): error_log.readline()) def test_header_matches_anything(self): - # Check that an empty pattern is skipped + # Check that a wild card header pattern is skipped. self._pckdict['header_filter_rules'] = [ ('.*', 7, False), - ] + ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual(self._mlist.header_matches, []) @@ -417,10 +427,10 @@ class TestBasicImport(unittest.TestCase): error_log.readline()) def test_header_matches_invalid_re(self): - # Check that an empty pattern is skipped + # Check that an invalid regular expression pattern is skipped. self._pckdict['header_filter_rules'] = [ ('SomeHeaderName: *invalid-re', 3, False), - ] + ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual(self._mlist.header_matches, []) @@ -431,20 +441,20 @@ class TestBasicImport(unittest.TestCase): # Check that a defer action is properly converted. self._pckdict['header_filter_rules'] = [ ('^X-Spam-Status: Yes', 0, False), - ] + ] self._import() self.assertListEqual( - [ (hm.header, hm.pattern, hm.chain) - for hm in self._mlist.header_matches ], - [ ('x-spam-status', 'Yes', None) ] - ) + [(hm.header, hm.pattern, hm.chain) + for hm in self._mlist.header_matches], + [('x-spam-status', 'Yes', None)] + ) def test_header_matches_unsupported_action(self): - # Check that an unsupported actions are skipped + # Check that unsupported actions are skipped. for action_num in (1, 4, 5): self._pckdict['header_filter_rules'] = [ ('HeaderName: test-re', action_num, False), - ] + ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual(self._mlist.header_matches, []) @@ -457,17 +467,17 @@ class TestBasicImport(unittest.TestCase): member.unsubscribe() def test_header_matches_duplicate(self): - # Check that duplicate patterns don't cause tracebacks + # Check that duplicate patterns don't cause tracebacks. self._pckdict['header_filter_rules'] = [ ('SomeHeaderName: test-pattern', 3, False), ('SomeHeaderName: test-pattern', 2, False), - ] + ] error_log = LogFileMark('mailman.error') self._import() self.assertListEqual( - [ (hm.header, hm.pattern, hm.chain) - for hm in self._mlist.header_matches ], - [ ('someheadername', 'test-pattern', 'discard') ] + [(hm.header, hm.pattern, hm.chain) + for hm in self._mlist.header_matches], + [('someheadername', 'test-pattern', 'discard')] ) self.assertIn('Skipping duplicate header_filter rule', error_log.readline()) |
