summaryrefslogtreecommitdiff
path: root/src/mailman/model/docs/domains.rst
blob: 878e5835a1cd43b4533dc29ad93983a271a15d60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
=======
Domains
=======

..  # The test framework starts out with an example domain, so let's delete
    # that first.
    >>> from mailman.interfaces.domain import IDomainManager
    >>> from zope.component import getUtility
    >>> manager = getUtility(IDomainManager)
    >>> manager.remove('example.com')
    <Domain example.com...>

Domains are how Mailman interacts with email host names and web host names.
::

    >>> from operator import attrgetter
    >>> def show_domains():
    ...     if len(manager) == 0:
    ...         print 'no domains'
    ...         return
    ...     for domain in sorted(manager, key=attrgetter('mail_host')):
    ...         print domain

    >>> show_domains()
    no domains

Adding a domain requires some basic information, of which the email host name
is the only required piece.  The other parts are inferred from that.

    >>> manager.add('example.org')
    <Domain example.org, base_url: http://example.org,
            contact_address: postmaster@example.org>
    >>> show_domains()
    <Domain example.org, base_url: http://example.org,
            contact_address: postmaster@example.org>

We can remove domains too.

    >>> manager.remove('example.org')
    <Domain example.org, base_url: http://example.org,
            contact_address: postmaster@example.org>
    >>> show_domains()
    no domains

Sometimes the email host name is different than the base url for hitting the
web interface for the domain.

    >>> manager.add('example.com', base_url='https://mail.example.com')
    <Domain example.com, base_url: https://mail.example.com,
            contact_address: postmaster@example.com>
    >>> show_domains()
    <Domain example.com, base_url: https://mail.example.com,
            contact_address: postmaster@example.com>

Domains can have explicit descriptions and contact addresses.
::

    >>> manager.add(
    ...     'example.net',
    ...     base_url='http://lists.example.net',
    ...     contact_address='postmaster@example.com',
    ...     description='The example domain')
    <Domain example.net, The example domain,
            base_url: http://lists.example.net,
            contact_address: postmaster@example.com>

    >>> show_domains()
    <Domain example.com, base_url: https://mail.example.com,
            contact_address: postmaster@example.com>
    <Domain example.net, The example domain,
            base_url: http://lists.example.net,
            contact_address: postmaster@example.com>

Domains can list all associated mailing lists with the mailing_lists property.
::

    >>> def show_lists(domain):
    ...     mlists = list(domain.mailing_lists)
    ...     for mlist in mlists:
    ...         print mlist
    ...     if len(mlists) == 0:
    ...         print 'no lists'

    >>> net_domain = manager['example.net']
    >>> com_domain = manager['example.com']
    >>> show_lists(net_domain)
    no lists

    >>> create_list('test@example.net')
    <mailing list "test@example.net" at ...>
    >>> transaction.commit()
    >>> show_lists(net_domain)
    <mailing list "test@example.net" at ...>

    >>> show_lists(com_domain)
    no lists

In the global domain manager, domains are indexed by their email host name.
::

    >>> for domain in sorted(manager, key=attrgetter('mail_host')):
    ...     print domain.mail_host
    example.com
    example.net

    >>> print manager['example.net']
    <Domain example.net, The example domain,
            base_url: http://lists.example.net,
            contact_address: postmaster@example.com>

    >>> print manager['doesnotexist.com']
    Traceback (most recent call last):
    ...
    KeyError: u'doesnotexist.com'

As with a dictionary, you can also get the domain.  If the domain does not
exist, ``None`` or a default is returned.
::

    >>> print manager.get('example.net')
    <Domain example.net, The example domain,
            base_url: http://lists.example.net,
            contact_address: postmaster@example.com>

    >>> print manager.get('doesnotexist.com')
    None

    >>> print manager.get('doesnotexist.com', 'blahdeblah')
    blahdeblah

Non-existent domains cannot be removed.

    >>> manager.remove('doesnotexist.com')
    Traceback (most recent call last):
    ...
    KeyError: u'doesnotexist.com'


Confirmation tokens
===================

Confirmation tokens can be added to the domain's url to generate the URL to a
page users can use to confirm their subscriptions.

    >>> domain = manager['example.net']
    >>> print domain.confirm_url('abc')
    http://lists.example.net/confirm/abc