summaryrefslogtreecommitdiff
path: root/src/mailman/app/docs/lifecycle.rst
blob: 08a25ccff10642e942cd664e33a43b0afd803060 (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
148
149
150
151
152
153
154
155
156
157
=================================
Application level list life cycle
=================================

The low-level way to create and delete a mailing list is to use the
``IListManager`` interface.  This interface simply adds or removes the
appropriate database entries to record the list's creation.

There is a higher level interface for creating and deleting mailing lists
which performs additional tasks such as:

 * validating the list's posting address (which also serves as the list's
   fully qualified name);
 * ensuring that the list's domain is registered;
 * applying all matching styles to the new list;
 * creating and assigning list owners;
 * notifying watchers of list creation;
 * creating ancillary artifacts (such as the list's on-disk directory)


Posting address validation
==========================

If you try to use the higher-level interface to create a mailing list with a
bogus posting address, you get an exception.

    >>> create_list('not a valid address')
    Traceback (most recent call last):
    ...
    InvalidEmailAddressError: not a valid address

If the posting address is valid, but the domain has not been registered with
Mailman yet, you get an exception.

    >>> create_list('test@example.org')
    Traceback (most recent call last):
    ...
    BadDomainSpecificationError: example.org


Creating a list applies its styles
==================================

Start by registering a test style.
::

    >>> from zope.interface import implements
    >>> from mailman.interfaces.styles import IStyle
    >>> class TestStyle(object):
    ...     implements(IStyle)
    ...     name = 'test'
    ...     priority = 10
    ...     def apply(self, mailing_list):
    ...         # Just does something very simple.
    ...         mailing_list.msg_footer = 'test footer'
    ...     def match(self, mailing_list, styles):
    ...         # Applies to any test list
    ...         if 'test' in mailing_list.fqdn_listname:
    ...             styles.append(self)

    >>> from zope.component import getUtility
    >>> from mailman.interfaces.styles import IStyleManager
    >>> getUtility(IStyleManager).register(TestStyle())

Using the higher level interface for creating a list, applies all matching
list styles.

    >>> mlist_1 = create_list('test_1@example.com')
    >>> print mlist_1.fqdn_listname
    test_1@example.com
    >>> print mlist_1.msg_footer
    test footer


Creating a list with owners
===========================

You can also specify a list of owner email addresses.  If these addresses are
not yet known, they will be registered, and new users will be linked to them.
However the addresses are not verified.

    >>> owners = [
    ...     'aperson@example.com',
    ...     'bperson@example.com',
    ...     'cperson@example.com',
    ...     'dperson@example.com',
    ...     ]
    >>> mlist_2 = create_list('test_2@example.com', owners)
    >>> print mlist_2.fqdn_listname
    test_2@example.com
    >>> print mlist_2.msg_footer
    test footer
    >>> dump_list(address.email for address in mlist_2.owners.addresses)
    aperson@example.com
    bperson@example.com
    cperson@example.com
    dperson@example.com

None of the owner addresses are verified.

    >>> any(address.verified_on is not None
    ...     for address in mlist_2.owners.addresses)
    False

However, all addresses are linked to users.

    >>> # The owners have no names yet
    >>> len(list(mlist_2.owners.users))
    4

If you create a mailing list with owner addresses that are already known to
the system, they won't be created again.
::

    >>> from mailman.interfaces.usermanager import IUserManager
    >>> user_manager = getUtility(IUserManager)

    >>> user_a = user_manager.get_user('aperson@example.com')
    >>> user_b = user_manager.get_user('bperson@example.com')
    >>> user_c = user_manager.get_user('cperson@example.com')
    >>> user_d = user_manager.get_user('dperson@example.com')
    >>> user_a.display_name = 'Anne Person'
    >>> user_b.display_name = 'Bart Person'
    >>> user_c.display_name = 'Caty Person'
    >>> user_d.display_name = 'Dirk Person'

    >>> mlist_3 = create_list('test_3@example.com', owners)
    >>> dump_list(user.display_name for user in mlist_3.owners.users)
    Anne Person
    Bart Person
    Caty Person
    Dirk Person


Deleting a list
===============

Removing a mailing list deletes the list, all its subscribers, and any related
artifacts.
::

    >>> from mailman.app.lifecycle import remove_list
    >>> remove_list(mlist_2.fqdn_listname, mlist_2)

    >>> from mailman.interfaces.listmanager import IListManager
    >>> from zope.component import getUtility
    >>> print getUtility(IListManager).get('test_2@example.com')
    None

We should now be able to completely recreate the mailing list.

    >>> mlist_2a = create_list('test_2@example.com', owners)
    >>> dump_list(address.email for address in mlist_2a.owners.addresses)
    aperson@example.com
    bperson@example.com
    cperson@example.com
    dperson@example.com