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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
XMLRPC access to mailing list memberships
=========================================
Just like the creation and deactivation of mailing lists, membership changes
to mailing lists must be communicated to Mailman over XMLRPC. Because the
bandwidth involved is not expected to be overwhelming, a simplified interface
was chosen.
The communication pattern is initiated by Mailman in all cases; in other
words, Mailman polls Launchpad to see if there is any work for Mailman to do.
>>> # Note that this test is run multiple times, with the harness
>>> # providing `mailinglist_api` and `commit` for impedance matching.
Requesting membership information
---------------------------------
Mailman requests membership information for specific list of teams. Let's
create and populate some teams to demonstrate.
# login() as an admin so that we can call join() on anyone
# and change their mailing list auto-subscription settings.
>>> login('foo.bar@canonical.com')
>>> from lp.registry.tests.mailinglists_helper import new_team
>>> team_one, list_one = new_team('team-one', with_list=True)
>>> anne = factory.makePersonByName('Anne')
>>> bart = factory.makePersonByName('Bart')
>>> cris = factory.makePersonByName('Cris')
>>> dirk = factory.makePersonByName('Dirk')
>>> elle = factory.makePersonByName('Elle')
>>> fred = factory.makePersonByName('Fred')
>>> gwen = factory.makePersonByName('Gwen')
>>> hank = factory.makePersonByName('Hank')
>>> people = [anne, bart, cris, dirk, elle, fred, gwen, hank]
>>> for person in people:
... person.join(team_one)
... list_one.subscribe(person)
# The IMailingListSet APIs use the SLAVE_FLAVOR since they are read-only.
# Commit the transaction so that the changes are visible there.
>>> transaction.commit()
Asking for the membership information for team-one's list returns all the
above people. We want to see all the email addresses for all the people
subscribed to the mailing list, along with their full name. We'll also print
the address's flags (which will currently always be zero), and the address's
delivery status. A status of RECIPIENT means the address will receive
messages posted to the list. A status of X means that delivery to this
address is suppressed. The important point is that all addresses regardless
of status, will be able to post to the mailing list.
>>> info = mailinglist_api.getMembershipInformation(('team-one',))
>>> from lp.registry.tests.mailinglists_helper import print_info
>>> print_info(info)
team-one
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
bart.person@example.com Bart Person 0 RECIPIENT
bperson@example.org Bart Person 0 X
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
fperson@example.org Fred Person 0 X
fred.person@example.com Fred Person 0 RECIPIENT
gperson@example.org Gwen Person 0 X
gwen.person@example.com Gwen Person 0 RECIPIENT
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
We can also ask for the membership information for more than one mailing list
at a time. Mix things up for the fun of it.
>>> team_two, list_two = new_team('team-two', with_list=True)
>>> fred.leave(team_one)
>>> gwen.leave(team_one)
>>> for person in people:
... if person is bart:
... continue
... person.join(team_two)
... list_two.subscribe(person)
>>> transaction.commit()
>>> info = mailinglist_api.getMembershipInformation(
... ('team-one', 'team-two'))
>>> print_info(info)
team-one
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
bart.person@example.com Bart Person 0 RECIPIENT
bperson@example.org Bart Person 0 X
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
team-two
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
fperson@example.org Fred Person 0 X
fred.person@example.com Fred Person 0 RECIPIENT
gperson@example.org Gwen Person 0 X
gwen.person@example.com Gwen Person 0 RECIPIENT
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
Membership tests
----------------
Mailman may also occasionally ask whether a specific email address is
registered with Launchpad. It does this as a simple line-of-defense against
spam. Email from addresses not registered with Launchpad are summarily
discarded.
>>> mailinglist_api.isRegisteredInLaunchpad('dirk.person@example.com')
True
>>> mailinglist_api.isRegisteredInLaunchpad('dperson@example.org')
True
>>> mailinglist_api.isRegisteredInLaunchpad('geddy.lee@canonical.com')
False
Similarly, email addresses with an unvalidated status are not considered
registered either.
>>> from lp.services.identity.interfaces.emailaddress import IEmailAddressSet
>>> emailset = getUtility(IEmailAddressSet)
>>> new_address = emailset.new('frederick@example.com', fred)
>>> new_address.email, new_address.status.title
(u'frederick@example.com', 'New Email Address')
>>> sorted((email_address.email, email_address.status.title)
... for email_address in emailset.getByPerson(fred))
[(u'fperson@example.org', 'Validated Email Address'),
(u'fred.person@example.com', 'Preferred Email Address'),
(u'frederick@example.com', 'New Email Address')]
>>> mailinglist_api.isRegisteredInLaunchpad('frederick@example.com')
False
Standing tests
--------------
Mailman may also occasionally ask whether a specific email address is a
Launchpad member in good (or better) standing. It does this when a non-member
of a mailing list tries to post to the mailing list. By default, an address
not registered in Launchpad is not in good standing (even though the previous
membership test should always take precedence).
>>> mailinglist_api.inGoodStanding('frederick@example.com')
False
Since standing makes no sense for teams, an email address assigned to a team
is also not in good standing.
>>> team_address = list(emailset.getByPerson(team_one))[0]
>>> mailinglist_api.inGoodStanding(team_address.email)
False
By default, Launchpad members have an unknown, and thus not good, standing.
>>> anne.personal_standing
<DBItem PersonalStanding.UNKNOWN...
>>> mailinglist_api.inGoodStanding('anne.person@example.com')
False
Anne is a bad person and the Launchpad administrator assigns her a poor
standing.
>>> from lp.registry.interfaces.person import PersonalStanding
>>> anne.personal_standing = PersonalStanding.POOR
>>> transaction.commit()
>>> mailinglist_api.inGoodStanding('anne.person@example.com')
False
Anne makes amends and the Launchpad administrator improves her standing.
>>> anne.personal_standing = PersonalStanding.GOOD
>>> transaction.commit()
>>> mailinglist_api.inGoodStanding('anne.person@example.com')
True
It turns out that Anne is a wonderful person! Her standing is really
excellent.
>>> anne.personal_standing = PersonalStanding.EXCELLENT
>>> transaction.commit()
>>> mailinglist_api.inGoodStanding('anne.person@example.com')
True
The archive address
-------------------
We archive messages by sending them to The Mail Archive
<http://www.mail-archive.com>. They automatically determine which list a
message is posted to so all we need to do is include them in the recipients
list and the rest is taken care of.
>>> from lp.services.config import config
>>> config.mailman.archive_address
'archive@mail-archive.dev'
Every public team should have this address as an enabled recipient. There is
no real name for this member.
>>> list_one.is_public
True
>>> list_two.is_public
True
>>> info = mailinglist_api.getMembershipInformation(
... ('team-one', 'team-two'))
>>> print_info(info, full=True)
team-one
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
archive@mail-archive.dev (n/a) 0 RECIPIENT
bart.person@example.com Bart Person 0 RECIPIENT
bperson@example.org Bart Person 0 X
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
team-two
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
archive@mail-archive.dev (n/a) 0 RECIPIENT
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
fperson@example.org Fred Person 0 X
fred.person@example.com Fred Person 0 RECIPIENT
gperson@example.org Gwen Person 0 X
gwen.person@example.com Gwen Person 0 RECIPIENT
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
However, in order to prevent this address from being used to forge spam onto
the lists, the archive address is hard-coded to not be registered in
Launchpad.
>>> mailinglist_api.isRegisteredInLaunchpad(
... config.mailman.archive_address)
False
This is true even if by dumb luck the address actually gets registered in
Launchpad.
>>> from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
>>> new_address = emailset.new(
... config.mailman.archive_address, fred,
... EmailAddressStatus.VALIDATED)
>>> transaction.commit()
>>> mailinglist_api.isRegisteredInLaunchpad(
... config.mailman.archive_address)
False
The Mail Archive is only used for public team mailing lists. If the team
itself is private, so is its archive, and then messages are not sent to the
archiver email address.
>>> from zope.component import queryAdapter
>>> from lp.services.privacy.interfaces import IObjectPrivacy
>>> from lp.registry.interfaces.person import PersonVisibility
>>> team_three = new_team('team-three')
>>> queryAdapter(team_three, IObjectPrivacy).is_private
False
Teams with mailing lists cannot change visibility, so the team must be made
private before its mailing list is created.
>>> team_three.visibility = PersonVisibility.PRIVATE
>>> queryAdapter(team_three, IObjectPrivacy).is_private
True
When Anne subscribes to the team-three mailing list, her validated addresses
are the only recipients in the list's membership information. Because the
team is private, the special archive@mail-archive.dev address is not
included.
>>> from lp.registry.tests.mailinglists_helper import (
... new_list_for_team)
>>> list_three = new_list_for_team(team_three)
>>> list_three.is_public
False
>>> anne.join(team_three)
>>> list_three.subscribe(anne)
>>> transaction.commit()
>>> info = mailinglist_api.getMembershipInformation(
... ('team-one', 'team-two', 'team-three'))
>>> print_info(info, full=True)
team-one
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
archive@mail-archive.dev (n/a) 0 RECIPIENT
bart.person@example.com Bart Person 0 RECIPIENT
bperson@example.org Bart Person 0 X
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
team-three
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
no-priv@canonical.com No Privileges Person 0 X
team-two
anne.person@example.com Anne Person 0 RECIPIENT
aperson@example.org Anne Person 0 X
archive@mail-archive.dev (n/a) 0 RECIPIENT
cperson@example.org Cris Person 0 X
cris.person@example.com Cris Person 0 RECIPIENT
dirk.person@example.com Dirk Person 0 RECIPIENT
dperson@example.org Dirk Person 0 X
elle.person@example.com Elle Person 0 RECIPIENT
eperson@example.org Elle Person 0 X
fperson@example.org Fred Person 0 X
fred.person@example.com Fred Person 0 RECIPIENT
gperson@example.org Gwen Person 0 X
gwen.person@example.com Gwen Person 0 RECIPIENT
hank.person@example.com Hank Person 0 RECIPIENT
hperson@example.org Hank Person 0 X
no-priv@canonical.com No Privileges Person 0 X
Error cases
-----------
If Mailman requests the membership information for a team that doesn't exist,
the team name will have a value of None in the resulting dictionary.
>>> mailinglist_api.getMembershipInformation(('no-such-team',))
{'no-such-team': None}
|