summaryrefslogtreecommitdiff
path: root/src/mailman/docs/lifecycle.txt
blob: ee4657f1d08dd75c0c63856edf954baa4a8823e4 (plain)
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
=================================
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)

    >>> from mailman.app.lifecycle import create_list


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):
    ...
    InvalidEmailAddress: u'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)

    >>> config.style_manager.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
    >>> sorted(addr.address for addr in mlist_2.owners.addresses)
    [u'aperson@example.com', u'bperson@example.com',
     u'cperson@example.com', u'dperson@example.com']

None of the owner addresses are verified.

    >>> any(addr.verified_on is not None for addr 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
    >>> from zope.component import getUtility
    >>> 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.real_name = 'Anne Person'
    >>> user_b.real_name = 'Bart Person'
    >>> user_c.real_name = 'Caty Person'
    >>> user_d.real_name = 'Dirk Person'

    >>> mlist_3 = create_list('test_3@example.com', owners)
    >>> sorted(user.real_name for user in mlist_3.owners.users)
    [u'Anne Person', u'Bart Person', u'Caty Person', u'Dirk Person']


Removing 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, True)

    >>> 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)
    >>> sorted(addr.address for addr in mlist_2a.owners.addresses)
    [u'aperson@example.com', u'bperson@example.com',
     u'cperson@example.com', u'dperson@example.com']