Merge lp:~abompard/mailman/fix-import-from-mm2 into lp:mailman

Proposed by Aurélien Bompard
Status: Merged
Merged at revision: 7310
Proposed branch: lp:~abompard/mailman/fix-import-from-mm2
Merge into: lp:mailman
Diff against target: 134 lines (+62/-6)
3 files modified
src/mailman/commands/cli_import.py (+11/-1)
src/mailman/utilities/importer.py (+16/-5)
src/mailman/utilities/tests/test_import.py (+35/-0)
To merge this branch: bzr merge lp:~abompard/mailman/fix-import-from-mm2
Reviewer Review Type Date Requested Status
Barry Warsaw Approve
Review via email: mp+250535@code.launchpad.net

Description of the change

This branch contains a few fixes for the import-from-mailman2 codepath.

To post a comment you must log in.
7300. By Barry Warsaw

Move some old bin scripts to a holding tank.

7301. By Barry Warsaw

Doc fixes given by Abhilash Raj.

7302. By Barry Warsaw

copybump should ignore .git directories. This isn't currently relevant for
Mailman, but I use this script for other repos.

7303. By Barry Warsaw

Fix a read used during the PostgreSQL tests.

7304. By Barry Warsaw

 * When trying to subscribe an address to a mailing list through the REST API
   where a case-differing version of the address is already subscribed, return
   a 409 error instead of a 500 error. Found by Ankush Sharma. (LP: #1425359)

7305. By Barry Warsaw

Documentation fixes, given by Abhilash Raj.

7306. By Barry Warsaw

 * ``mailman lists --domain`` was not properly handling its arguments. Given
   by Manish Gill. (LP: #1166911)

7307. By Aurélien Bompard

Fixes in the import process

Revision history for this message
Aurélien Bompard (abompard) wrote :

I merged the changes in HEAD, please check out those fixes.

Revision history for this message
Barry Warsaw (barry) wrote :

Accepted and merged, with some style changes:

* Single quotes for double quotes in several places.
* Full sentences in comments.
* No hanging comments.
* Refactored getUtility()
* Comments after test function name/signature.
* Long lines.
* Abbreviations.

I'm moderately concerned that the Bouncer class isn't tested explicitly; does this show up in real data or in the test sample data? Any chance you can write a follow up test for that? (It's fine that bounce info is thrown away during an import.)

I also added a context manager to ensure sys.modules gets cleaned up, and then I used an ExitStack in the with statement. These things are awesome. :)

review: Approve
Revision history for this message
Aurélien Bompard (abompard) wrote :

Thanks a lot for this merge. I'll try to keep your changes in mind for future MP (single quotes are preferred, describe tests with comments, etc.)
I don't quite understand your concern about the Bouncer class. It's there to allow loading the pickles when they include instances of a Bouncer._BounceInfo class (where Bouncer is the name of a module in MM2.1). I don't do anything with it, but the unpickling will fail without it (with real data from the Fedora lists).

Revision history for this message
Barry Warsaw (barry) wrote :

On Mar 26, 2015, at 06:55 AM, Aurélien Bompard wrote:

>I don't quite understand your concern about the Bouncer class. It's there to
>allow loading the pickles when they include instances of a
>Bouncer._BounceInfo class (where Bouncer is the name of a module in MM2.1). I
>don't do anything with it, but the unpickling will fail without it (with real
>data from the Fedora lists).

Yep, that was my question. I don't think we have any tests that require the
new Bouncer mock, so I was wondering why you added it. "To handle real data
from Fedora lists" is a good reason. :) I was just hoping we could get a
test that shows how and verifies that this works.

Revision history for this message
Aurélien Bompard (abompard) wrote :

Ah, gotcha. I need to find a pickle file that has these _BouncerInfo instances and write a test that uses it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mailman/commands/cli_import.py'
2--- src/mailman/commands/cli_import.py 2015-01-05 01:40:47 +0000
3+++ src/mailman/commands/cli_import.py 2015-03-16 10:22:44 +0000
4@@ -35,6 +35,14 @@
5
6
7
8
9+# Mock the Bouncer class from Mailman 2.1, we don't use it but there are
10+# instances in the pickled config files
11+class Bouncer:
12+ class _BounceInfo:
13+ pass
14+
15+
16+
17
18 @implementer(ICLISubCommand)
19 class Import21:
20 """Import Mailman 2.1 list data."""
21@@ -74,10 +82,11 @@
22 assert len(args.pickle_file) == 1, (
23 'Unexpected positional arguments: %s' % args.pickle_file)
24 filename = args.pickle_file[0]
25+ sys.modules["Mailman.Bouncer"] = Bouncer
26 with open(filename, 'rb') as fp:
27 while True:
28 try:
29- config_dict = pickle.load(fp)
30+ config_dict = pickle.load(fp, encoding="utf-8", errors="ignore")
31 except EOFError:
32 break
33 except pickle.UnpicklingError:
34@@ -94,3 +103,4 @@
35 except Import21Error as error:
36 print(error, file=sys.stderr)
37 sys.exit(1)
38+ del sys.modules["Mailman.Bouncer"]
39
40=== modified file 'src/mailman/utilities/importer.py'
41--- src/mailman/utilities/importer.py 2015-01-05 01:40:47 +0000
42+++ src/mailman/utilities/importer.py 2015-03-16 10:22:44 +0000
43@@ -32,6 +32,7 @@
44 from mailman.core.errors import MailmanError
45 from mailman.handlers.decorate import decorate, decorate_template
46 from mailman.interfaces.action import Action, FilterAction
47+from mailman.interfaces.address import IEmailValidator
48 from mailman.interfaces.archiver import ArchivePolicy
49 from mailman.interfaces.autorespond import ResponseAction
50 from mailman.interfaces.bans import IBanManager
51@@ -387,11 +388,17 @@
52 regulars_set = set(config_dict.get('members', {}))
53 digesters_set = set(config_dict.get('digest_members', {}))
54 members = regulars_set.union(digesters_set)
55- import_roster(mlist, config_dict, members, MemberRole.member)
56- import_roster(mlist, config_dict, config_dict.get('owner', []),
57- MemberRole.owner)
58- import_roster(mlist, config_dict, config_dict.get('moderator', []),
59- MemberRole.moderator)
60+ # don't send welcome messages...
61+ send_welcome_message = mlist.send_welcome_message
62+ mlist.send_welcome_message = False
63+ try:
64+ import_roster(mlist, config_dict, members, MemberRole.member)
65+ import_roster(mlist, config_dict, config_dict.get('owner', []),
66+ MemberRole.owner)
67+ import_roster(mlist, config_dict, config_dict.get('moderator', []),
68+ MemberRole.moderator)
69+ finally:
70+ mlist.send_welcome_message = send_welcome_message
71
72
73
74
75@@ -427,8 +434,12 @@
76 merged_members.update(config_dict.get('digest_members', {}))
77 if merged_members.get(email, 0) != 0:
78 original_email = bytes_to_str(merged_members[email])
79+ if not getUtility(IEmailValidator).is_valid(original_email):
80+ original_email = email
81 else:
82 original_email = email
83+ if not getUtility(IEmailValidator).is_valid(original_email):
84+ continue # skip this one entirely
85 address = usermanager.create_address(original_email)
86 address.verified_on = datetime.datetime.now()
87 user.link(address)
88
89=== modified file 'src/mailman/utilities/tests/test_import.py'
90--- src/mailman/utilities/tests/test_import.py 2015-01-05 01:40:47 +0000
91+++ src/mailman/utilities/tests/test_import.py 2015-03-16 10:22:44 +0000
92@@ -38,6 +38,7 @@
93 from mailman.config import config
94 from mailman.handlers.decorate import decorate
95 from mailman.interfaces.action import Action, FilterAction
96+from mailman.interfaces.address import InvalidEmailAddressError
97 from mailman.interfaces.archiver import ArchivePolicy
98 from mailman.interfaces.autorespond import ResponseAction
99 from mailman.interfaces.bans import IBanManager
100@@ -747,6 +748,40 @@
101 anne = self._usermanager.get_user('anne@example.com')
102 self.assertTrue(anne.controls('anne@example.com'))
103
104+ def test_invalid_original_email(self):
105+ self._pckdict["members"]["anne@example.com"] = b'invalid email address'
106+ try:
107+ import_config_pck(self._mlist, self._pckdict)
108+ except InvalidEmailAddressError as e:
109+ self.fail(e)
110+ self.assertIn('anne@example.com',
111+ [a.email for a in self._mlist.members.addresses])
112+ anne = self._usermanager.get_address('anne@example.com')
113+ self.assertEqual(anne.original_email, 'anne@example.com')
114+
115+ def test_invalid_email(self):
116+ self._pckdict["members"] = {
117+ 'anne@example.com': 0,
118+ 'invalid email address': b'invalid email address'
119+ }
120+ self._pckdict["digest_members"] = {}
121+ try:
122+ import_config_pck(self._mlist, self._pckdict)
123+ except InvalidEmailAddressError as e:
124+ self.fail(e)
125+ self.assertEqual(['anne@example.com'],
126+ [a.email for a in self._mlist.members.addresses])
127+
128+ def test_no_email_sent(self):
129+ self._pckdict
130+ import_config_pck(self._mlist, self._pckdict)
131+ self.assertIn("anne@example.com",
132+ [a.email for a in self._mlist.members.addresses])
133+ # no email in any queue
134+ for qname, sb in config.switchboards.items():
135+ self.assertEqual(len(sb.files), 0,
136+ "Queue '{}' has {} emails".format(qname, len(sb.files)))
137+ self.assertTrue(self._mlist.send_welcome_message)
138
139
140