summaryrefslogtreecommitdiff
path: root/src/mailman/domain.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/domain.py')
-rw-r--r--src/mailman/domain.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/mailman/domain.py b/src/mailman/domain.py
new file mode 100644
index 000000000..4a7bef755
--- /dev/null
+++ b/src/mailman/domain.py
@@ -0,0 +1,70 @@
+# Copyright (C) 2008-2009 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/>.
+
+"""Domains."""
+
+from __future__ import unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'Domain',
+ ]
+
+from urlparse import urljoin, urlparse
+from zope.interface import implements
+
+from mailman.interfaces.domain import IDomain
+
+
+
+class Domain:
+ """Domains."""
+
+ implements(IDomain)
+
+ def __init__(self, email_host, base_url=None, description=None,
+ contact_address=None):
+ """Create and register a domain.
+
+ :param email_host: The host name for the email interface.
+ :type email_host: string
+ :param base_url: The optional base url for the domain, including
+ scheme. If not given, it will be constructed from the
+ `email_host` using the http protocol.
+ :type base_url: string
+ :param description: An optional description of the domain.
+ :type description: string
+ :type contact_address: The email address to contact a human for this
+ domain. If not given, postmaster@`email_host` will be used.
+ """
+ self.email_host = email_host
+ self.base_url = (base_url
+ if base_url is not None
+ else 'http://' + email_host)
+ self.description = description
+ self.contact_address = (contact_address
+ if contact_address is not None
+ else 'postmaster@' + email_host)
+ self.url_host = urlparse(self.base_url).netloc
+
+ def confirm_address(self, token=''):
+ """See `IDomain`."""
+ return 'confirm-{0}@{1}'.format(token, self.email_host)
+
+ def confirm_url(self, token=''):
+ """See `IDomain`."""
+ return urljoin(self.base_url, 'confirm/' + token)