Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 39c774cb by Daniel Teichmann at 2019-08-06T02:39:53Z Catch InvalidEmailAddressError for adding user to mailing list in cli_members.py - - - - - c79d3ece by Abhilash Raj at 2019-08-06T02:39:53Z Merge branch 'mr/catch_invalid_email' into 'master' Catch InvalidEmailAddressError for adding user to mailing list in cli_members.py See merge request mailman/mailman!544 - - - - - 3 changed files: - src/mailman/commands/cli_members.py - src/mailman/commands/tests/test_cli_members.py - src/mailman/docs/NEWS.rst Changes: ===================================== src/mailman/commands/cli_members.py ===================================== @@ -23,6 +23,7 @@ from email.utils import formataddr, parseaddr from mailman.app.membership import add_member from mailman.core.i18n import _ from mailman.database.transaction import transactional +from mailman.interfaces.address import InvalidEmailAddressError from mailman.interfaces.command import ICLISubCommand from mailman.interfaces.listmanager import IListManager from mailman.interfaces.member import ( @@ -116,6 +117,12 @@ def add_members(mlist, infp): RequestRecord(email, display_name, DeliveryMode.regular, mlist.preferred_language.code)) + except InvalidEmailAddressError: + # It's okay if the address is invalid, we print a + # warning and continue. + line = line.strip() + print(_('Cannot parse as valid subscriber ' + 'address (skipping): $line')) except AlreadySubscribedError: # It's okay if the address is already subscribed, just print a # warning and continue. ===================================== src/mailman/commands/tests/test_cli_members.py ===================================== @@ -111,3 +111,13 @@ class TestCLIMembers(unittest.TestCase): result.output, 'Already subscribed (skipping): Anne Person <aper...@example.com>\n' ) + + def test_add_invalid_email(self): + with NamedTemporaryFile('w', buffering=1, encoding='utf-8') as infp: + print('foobar@', file=infp) + result = self._command.invoke(members, ( + '--add', infp.name, 'ant.example.com')) + self.assertEqual( + result.output, + 'Cannot parse as valid subscriber address (skipping): foobar@\n' + ) ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -57,6 +57,8 @@ Command line (Closes #607) * A ``mailman gatenews`` command has been implemented to be run by cron to gate messages from usenet to those lists which have the gateway configured. +* The ``mailman members --add`` command no longer prints a stack trace if an + invalid email address is given. (See !544) REST ---- View it on GitLab: https://gitlab.com/mailman/mailman/compare/9bf0b1160aa2df862566769a373fb0a796b00857...c79d3ece5db3c701a6f15824671e1797d1592beb -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/9bf0b1160aa2df862566769a373fb0a796b00857...c79d3ece5db3c701a6f15824671e1797d1592beb 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