summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/model/address.py5
-rw-r--r--src/mailman/model/tests/test_address.py45
2 files changed, 49 insertions, 1 deletions
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py
index f5e7ddbfd..890047445 100644
--- a/src/mailman/model/address.py
+++ b/src/mailman/model/address.py
@@ -27,11 +27,13 @@ __all__ = [
from email.utils import formataddr
from storm.locals import DateTime, Int, Reference, Unicode
+from zope.component import getUtility
from zope.event import notify
from zope.interface import implementer
from mailman.database.model import Model
-from mailman.interfaces.address import AddressVerificationEvent, IAddress
+from mailman.interfaces.address import (AddressVerificationEvent, IAddress,
+ IEmailValidator)
from mailman.utilities.datetime import now
@@ -54,6 +56,7 @@ class Address(Model):
def __init__(self, email, display_name):
super(Address, self).__init__()
+ getUtility(IEmailValidator).validate(email)
lower_case = email.lower()
self.email = lower_case
self.display_name = display_name
diff --git a/src/mailman/model/tests/test_address.py b/src/mailman/model/tests/test_address.py
new file mode 100644
index 000000000..f436bacf7
--- /dev/null
+++ b/src/mailman/model/tests/test_address.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test addresses."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestAddress',
+ ]
+
+
+import unittest
+
+from zope.component import getUtility
+
+from mailman.email.validate import InvalidEmailAddressError
+from mailman.model.address import Address
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestAddress(unittest.TestCase):
+ """Test addresses."""
+
+ layer = ConfigLayer
+
+ def test_invalid_email_string_raises_exception(self):
+ with self.assertRaises(InvalidEmailAddressError):
+ Address('not_a_valid_email_string', '')