Aurélien Bompard has proposed merging lp:~abompard/mailman/fix-import-from-mm2
into lp:mailman.
Requested reviews:
Mailman Coders (mailman-coders)
For more details, see:
https://code.launchpad.net/~abompard/mailman/fix-import-from-mm2/+merge/250535
This branch contains a few fixes for the import-from-mailman2 codepath.
--
Your team Mailman Coders is requested to review the proposed merge of
lp:~abompard/mailman/fix-import-from-mm2 into lp:mailman.
=== modified file 'src/mailman/commands/cli_import.py'
--- src/mailman/commands/cli_import.py 2015-01-05 01:40:47 +0000
+++ src/mailman/commands/cli_import.py 2015-02-21 18:52:15 +0000
@@ -35,6 +35,14 @@
+# Mock the Bouncer class from Mailman 2.1, we don't use it but there are
+# instances in the pickled config files
+class Bouncer:
+ class _BounceInfo:
+ pass
+
+
+
@implementer(ICLISubCommand)
class Import21:
"""Import Mailman 2.1 list data."""
@@ -74,10 +82,11 @@
assert len(args.pickle_file) == 1, (
'Unexpected positional arguments: %s' % args.pickle_file)
filename = args.pickle_file[0]
+ sys.modules["Mailman.Bouncer"] = Bouncer
with open(filename, 'rb') as fp:
while True:
try:
- config_dict = pickle.load(fp)
+ config_dict = pickle.load(fp, encoding="utf-8", errors="ignore")
except EOFError:
break
except pickle.UnpicklingError:
@@ -94,3 +103,4 @@
except Import21Error as error:
print(error, file=sys.stderr)
sys.exit(1)
+ del sys.modules["Mailman.Bouncer"]
=== modified file 'src/mailman/utilities/importer.py'
--- src/mailman/utilities/importer.py 2015-01-05 01:40:47 +0000
+++ src/mailman/utilities/importer.py 2015-02-21 18:52:15 +0000
@@ -32,6 +32,7 @@
from mailman.core.errors import MailmanError
from mailman.handlers.decorate import decorate, decorate_template
from mailman.interfaces.action import Action, FilterAction
+from mailman.interfaces.address import IEmailValidator
from mailman.interfaces.archiver import ArchivePolicy
from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.bans import IBanManager
@@ -387,11 +388,17 @@
regulars_set = set(config_dict.get('members', {}))
digesters_set = set(config_dict.get('digest_members', {}))
members = regulars_set.union(digesters_set)
- import_roster(mlist, config_dict, members, MemberRole.member)
- import_roster(mlist, config_dict, config_dict.get('owner', []),
- MemberRole.owner)
- import_roster(mlist, config_dict, config_dict.get('moderator', []),
- MemberRole.moderator)
+ # don't send welcome messages...
+ send_welcome_message = mlist.send_welcome_message
+ mlist.send_welcome_message = False
+ try:
+ import_roster(mlist, config_dict, members, MemberRole.member)
+ import_roster(mlist, config_dict, config_dict.get('owner', []),
+ MemberRole.owner)
+ import_roster(mlist, config_dict, config_dict.get('moderator', []),
+ MemberRole.moderator)
+ finally:
+ mlist.send_welcome_message = send_welcome_message
@@ -427,8 +434,12 @@
merged_members.update(config_dict.get('digest_members', {}))
if merged_members.get(email, 0) != 0:
original_email = bytes_to_str(merged_members[email])
+ if not getUtility(IEmailValidator).is_valid(original_email):
+ original_email = email
else:
original_email = email
+ if not getUtility(IEmailValidator).is_valid(original_email):
+ continue # skip this one entirely
address = usermanager.create_address(original_email)
address.verified_on = datetime.datetime.now()
user.link(address)
=== modified file 'src/mailman/utilities/tests/test_import.py'
--- src/mailman/utilities/tests/test_import.py 2015-01-05 01:40:47 +0000
+++ src/mailman/utilities/tests/test_import.py 2015-02-21 18:52:15 +0000
@@ -38,6 +38,7 @@
from mailman.config import config
from mailman.handlers.decorate import decorate
from mailman.interfaces.action import Action, FilterAction
+from mailman.interfaces.address import InvalidEmailAddressError
from mailman.interfaces.archiver import ArchivePolicy
from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.bans import IBanManager
@@ -747,6 +748,40 @@
anne = self._usermanager.get_user('[email protected]')
self.assertTrue(anne.controls('[email protected]'))
+ def test_invalid_original_email(self):
+ self._pckdict["members"]["[email protected]"] = b'invalid email address'
+ try:
+ import_config_pck(self._mlist, self._pckdict)
+ except InvalidEmailAddressError as e:
+ self.fail(e)
+ self.assertIn('[email protected]',
+ [a.email for a in self._mlist.members.addresses])
+ anne = self._usermanager.get_address('[email protected]')
+ self.assertEqual(anne.original_email, '[email protected]')
+
+ def test_invalid_email(self):
+ self._pckdict["members"] = {
+ '[email protected]': 0,
+ 'invalid email address': b'invalid email address'
+ }
+ self._pckdict["digest_members"] = {}
+ try:
+ import_config_pck(self._mlist, self._pckdict)
+ except InvalidEmailAddressError as e:
+ self.fail(e)
+ self.assertEqual(['[email protected]'],
+ [a.email for a in self._mlist.members.addresses])
+
+ def test_no_email_sent(self):
+ self._pckdict
+ import_config_pck(self._mlist, self._pckdict)
+ self.assertIn("[email protected]",
+ [a.email for a in self._mlist.members.addresses])
+ # no email in any queue
+ for qname, sb in config.switchboards.items():
+ self.assertEqual(len(sb.files), 0,
+ "Queue '{}' has {} emails".format(qname, len(sb.files)))
+ self.assertTrue(self._mlist.send_welcome_message)
_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders