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
|
============================
Membership changes via email
============================
Membership changes such as joining and leaving a mailing list, can be effected
via the email interface. The Mailman email commands ``join``, ``leave``, and
``confirm`` are used.
Joining a mailing list
======================
The mail command ``join`` subscribes an email address to the mailing list.
``subscribe`` is an alias for ``join``.
>>> from mailman.commands.eml_membership import Join
>>> from mailman.utilities.string import wrap
>>> join = Join()
>>> print(join.name)
join
>>> print(wrap(join.description))
You will be asked to confirm your subscription request and you may be
issued a provisional password.
<BLANKLINE>
By using the 'digest' option, you can specify whether you want digest
delivery or not. If not specified, the mailing list's default
delivery mode will be used.
>>> print(join.argument_description)
[digest=<no|mime|plain>]
No address to join
------------------
>>> mlist = create_list('alpha@example.com')
>>> mlist.send_welcome_message = False
When no address argument is given, the message's From address will be used.
If that's missing though, then an error is returned.
::
>>> from mailman.runners.command import Results
>>> results = Results()
>>> from mailman.email.message import Message
>>> print(join.process(mlist, Message(), {}, (), results))
ContinueProcessing.no
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
join: No valid address found to subscribe
<BLANKLINE>
The ``subscribe`` command is an alias.
>>> from mailman.commands.eml_membership import Subscribe
>>> subscribe = Subscribe()
>>> print(subscribe.name)
subscribe
>>> results = Results()
>>> print(subscribe.process(mlist, Message(), {}, (), results))
ContinueProcessing.no
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
subscribe: No valid address found to subscribe
<BLANKLINE>
Joining the sender
------------------
When the message has a ``From`` field, that address will be subscribed.
>>> msg = message_from_string("""\
... From: Anne Person <anne@example.com>
...
... """)
>>> results = Results()
>>> print(join.process(mlist, msg, {}, (), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Confirmation email sent to Anne Person <anne@example.com>
<BLANKLINE>
Anne is not yet a member of the mailing list because she must confirm her
subscription request first.
>>> print(mlist.members.get_member('anne@example.com'))
None
Mailman has sent her the confirmation message.
>>> from mailman.testing.helpers import get_queue_messages
>>> items = get_queue_messages('virgin')
>>> len(items)
1
>>> print(items[0].msg.as_string())
MIME-Version: 1.0
...
Subject: confirm ...
From: alpha-confirm+...@example.com
To: anne@example.com
...
<BLANKLINE>
Email Address Registration Confirmation
<BLANKLINE>
Hello, this is the GNU Mailman server at example.com.
<BLANKLINE>
We have received a registration request for the email address
<BLANKLINE>
anne@example.com
<BLANKLINE>
Before you can start using GNU Mailman at this site, you must first confirm
that this is your email address. You can do this by replying to this me...
keeping the Subject header intact.
<BLANKLINE>
If you do not wish to register this email address, simply disregard this
message. If you think you are being maliciously subscribed to the list, or
have any other questions, you may contact
<BLANKLINE>
alpha-owner@example.com
<BLANKLINE>
Anne confirms her registration.
::
>>> def extract_token(message):
... return str(message['subject']).split()[1].strip()
>>> token = extract_token(items[0].msg)
>>> from mailman.commands.eml_confirm import Confirm
>>> confirm = Confirm()
>>> msg = message_from_string("""\
... To: alpha-confirm+{token}@example.com
... From: anne@example.com
... Subject: Re: confirm {token}
...
... """.format(token=token))
>>> results = Results()
>>> print(confirm.process(mlist, msg, {}, (token,), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Confirmed
<BLANKLINE>
Anne is now a member of the mailing list.
>>> mlist.members.get_member('anne@example.com')
<Member: Anne Person <anne@example.com>
on alpha@example.com as MemberRole.member>
Joining a second list
---------------------
>>> mlist_2 = create_list('baker@example.com')
>>> msg = message_from_string("""\
... From: Anne Person <anne@example.com>
...
... """)
>>> print(join.process(mlist_2, msg, {}, (), Results()))
ContinueProcessing.yes
Anne is not a member of the mailing list.
>>> print(mlist_2.members.get_member('anne@example.com'))
None
One Anne confirms this subscription, she becomes a member of the mailing
list.
::
>>> items = get_queue_messages('virgin')
>>> len(items)
1
>>> token = extract_token(items[0].msg)
>>> msg = message_from_string("""\
... To: baker-confirm+{token}@example.com
... From: anne@example.com
... Subject: Re: confirm {token}
...
... """.format(token=token))
>>> results = Results()
>>> print(confirm.process(mlist_2, msg, {}, (token,), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Confirmed
<BLANKLINE>
>>> print(mlist_2.members.get_member('anne@example.com'))
<Member: Anne Person <anne@example.com>
on baker@example.com as MemberRole.member>
Leaving a mailing list
======================
The mail command ``leave`` unsubscribes an email address from the mailing
list. ``unsubscribe`` is an alias for ``leave``.
>>> from mailman.commands.eml_membership import Leave
>>> leave = Leave()
>>> print(leave.name)
leave
>>> print(leave.description)
Leave this mailing list.
<BLANKLINE>
You may be asked to confirm your request.
Anne is a member of the ``baker@example.com`` mailing list, when she decides
to leave it. Because the mailing list allows for *open* unsubscriptions
(i.e. no confirmation is needed), when she sends a message to the ``-leave``
address for the list, she is immediately removed.
>>> from mailman.interfaces.mailinglist import SubscriptionPolicy
>>> mlist_2.unsubscription_policy = SubscriptionPolicy.open
>>> mlist.unsubscription_policy = SubscriptionPolicy.open
>>> results = Results()
>>> print(leave.process(mlist_2, msg, {}, (), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Anne Person <anne@example.com> left baker@example.com
<BLANKLINE>
Anne is no longer a member of the mailing list.
>>> print(mlist_2.members.get_member('anne@example.com'))
None
Anne does not need to leave a mailing list with the same email address she's
subscribe with. Any of her registered, linked, and validated email addresses
will do.
::
>>> from mailman.interfaces.usermanager import IUserManager
>>> from zope.component import getUtility
>>> anne = getUtility(IUserManager).get_user('anne@example.com')
>>> address = anne.register('anne.person@example.org')
>>> results = Results()
>>> print(mlist.members.get_member('anne@example.com'))
<Member: Anne Person <anne@example.com>
on alpha@example.com as MemberRole.member>
>>> msg = message_from_string("""\
... To: alpha-leave@example.com
... From: anne.person@example.org
...
... """)
Since Anne's alternative address has not yet been verified, it can't be used
to unsubscribe Anne from the alpha mailing list.
::
>>> print(leave.process(mlist, msg, {}, (), results))
ContinueProcessing.no
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Invalid or unverified email address: anne.person@example.org
<BLANKLINE>
>>> print(mlist.members.get_member('anne@example.com'))
<Member: Anne Person <anne@example.com>
on alpha@example.com as MemberRole.member>
Once Anne has verified her alternative address though, it can be used to
unsubscribe her from the list.
::
>>> from mailman.utilities.datetime import now
>>> address.verified_on = now()
>>> results = Results()
>>> print(leave.process(mlist, msg, {}, (), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Anne Person <anne.person@example.org> left alpha@example.com
<BLANKLINE>
>>> print(mlist.members.get_member('anne@example.com'))
None
Confirmations
=============
Bart wants to join the alpha list, so he sends his subscription request.
::
>>> msg = message_from_string("""\
... From: Bart Person <bart@example.com>
...
... """)
>>> print(join.process(mlist, msg, {}, (), Results()))
ContinueProcessing.yes
There are two messages in the virgin queue, one of which is the confirmation
message.
>>> for item in get_queue_messages('virgin'):
... if str(item.msg['subject']).startswith('confirm'):
... break
... else:
... raise AssertionError('No confirmation message')
>>> token = extract_token(item.msg)
Bart replies to the original message, specifically keeping the Subject header
intact except for any prefix. Mailman matches the token and confirms Bart as
a user of the system.
::
>>> msg = message_from_string("""\
... From: Bart Person <bart@example.com>
... To: alpha-confirm+{token}@example.com
... Subject: Re: confirm {token}
...
... """.format(token=token))
>>> results = Results()
>>> print(confirm.process(mlist, msg, {}, (token,), results))
ContinueProcessing.yes
>>> print(results)
The results of your email command are provided below.
<BLANKLINE>
Confirmed
<BLANKLINE>
Now Bart is now a member of the mailing list.
>>> print(mlist.members.get_member('bart@example.com'))
<Member: Bart Person <bart@example.com>
on alpha@example.com as MemberRole.member>
|