summaryrefslogtreecommitdiff
path: root/src/mailman/model/docs/requests.txt
blob: 2ff173422e61ffdd809d8c3b4226f156454a632a (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
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
==================
Moderator requests
==================

Various actions will be held for moderator approval, such as subscriptions to
closed lists, or postings by non-members.  The requests database is the low
level interface to these actions requiring approval.

Here is a helper function for printing out held requests.

    >>> def show_holds(requests):
    ...     for request in requests.held_requests:
    ...         key, data = requests.get_request(request.id)
    ...         print request.id, str(request.request_type), key
    ...         if data is not None:
    ...             for key in sorted(data):
    ...                 print '    {0}: {1}'.format(key, data[key])

And another helper for displaying messages in the virgin queue.

    >>> virginq = config.switchboards['virgin']
    >>> def dequeue(whichq=None, expected_count=1):
    ...     if whichq is None:
    ...         whichq = virginq
    ...     assert len(whichq.files) == expected_count, (
    ...         'Unexpected file count: %d' % len(whichq.files))
    ...     filebase = whichq.files[0]
    ...     qmsg, qdata = whichq.dequeue(filebase)
    ...     whichq.finish(filebase)
    ...     return qmsg, qdata


Mailing list centric
====================

A set of requests are always related to a particular mailing list, so given a
mailing list you need to get its requests object.
::

    >>> from mailman.interfaces.requests import IListRequests, IRequests
    >>> from zope.component import getUtility
    >>> from zope.interface.verify import verifyObject

    >>> mlist = create_list('test@example.com')
    >>> requests = getUtility(IRequests).get_list_requests(mlist)
    >>> verifyObject(IListRequests, requests)
    True
    >>> requests.mailing_list
    <mailing list "test@example.com" at ...>


Holding requests
================

The list's requests database starts out empty.

    >>> requests.count
    0
    >>> dump_list(requests.held_requests)
    *Empty*

At the lowest level, the requests database is very simple.  Holding a request
requires a request type (as an enum value), a key, and an optional dictionary
of associated data.  The request database assigns no semantics to the held
data, except for the request type.  Here we hold some simple bits of data.

    >>> from mailman.interfaces.requests import RequestType
    >>> id_1 = requests.hold_request(RequestType.held_message,   'hold_1')
    >>> id_2 = requests.hold_request(RequestType.subscription,   'hold_2')
    >>> id_3 = requests.hold_request(RequestType.unsubscription, 'hold_3')
    >>> id_4 = requests.hold_request(RequestType.held_message,   'hold_4')
    >>> id_1, id_2, id_3, id_4
    (1, 2, 3, 4)

And of course, now we can see that there are four requests being held.

    >>> requests.count
    4
    >>> requests.count_of(RequestType.held_message)
    2
    >>> requests.count_of(RequestType.subscription)
    1
    >>> requests.count_of(RequestType.unsubscription)
    1
    >>> show_holds(requests)
    1 RequestType.held_message hold_1
    2 RequestType.subscription hold_2
    3 RequestType.unsubscription hold_3
    4 RequestType.held_message hold_4

If we try to hold a request with a bogus type, we get an exception.

    >>> requests.hold_request(5, 'foo')
    Traceback (most recent call last):
    ...
    TypeError: 5

We can hold requests with additional data.

    >>> data = dict(foo='yes', bar='no')
    >>> id_5 = requests.hold_request(RequestType.held_message, 'hold_5', data)
    >>> id_5
    5
    >>> requests.count
    5
    >>> show_holds(requests)
    1 RequestType.held_message hold_1
    2 RequestType.subscription hold_2
    3 RequestType.unsubscription hold_3
    4 RequestType.held_message hold_4
    5 RequestType.held_message hold_5
        bar: no
        foo: yes


Getting requests
================

We can ask the requests database for a specific request, by providing the id
of the request data we want.  This returns a 2-tuple of the key and data we
originally held.

    >>> key, data = requests.get_request(2)
    >>> print key
    hold_2

Because we did not store additional data with request 2, it comes back as None
now.

    >>> print data
    None

However, if we ask for a request that had data, we'd get it back now.

    >>> key, data = requests.get_request(5)
    >>> print key
    hold_5
    >>> dump_msgdata(data)
    bar: no
    foo: yes

If we ask for a request that is not in the database, we get None back.

    >>> print requests.get_request(801)
    None


Iterating over requests
=======================

To make it easier to find specific requests, the list requests can be iterated
over by type.

    >>> requests.count_of(RequestType.held_message)
    3
    >>> for request in requests.of_type(RequestType.held_message):
    ...     assert request.request_type is RequestType.held_message
    ...     key, data = requests.get_request(request.id)
    ...     print request.id, key
    ...     if data is not None:
    ...         for key in sorted(data):
    ...             print '    {0}: {1}'.format(key, data[key])
    1 hold_1
    4 hold_4
    5 hold_5
    bar: no
    foo: yes


Deleting requests
=================

Once a specific request has been handled, it will be deleted from the requests
database.

    >>> requests.delete_request(2)
    >>> requests.count
    4
    >>> show_holds(requests)
    1 RequestType.held_message hold_1
    3 RequestType.unsubscription hold_3
    4 RequestType.held_message hold_4
    5 RequestType.held_message hold_5
        bar: no
        foo: yes
    >>> print requests.get_request(2)
    None

We get an exception if we ask to delete a request that isn't in the database.

    >>> requests.delete_request(801)
    Traceback (most recent call last):
    ...
    KeyError: 801

For the next section, we first clean up all the current requests.

    >>> for request in requests.held_requests:
    ...     requests.delete_request(request.id)
    >>> requests.count
    0


Application support
===================

There are several higher level interfaces available in the ``mailman.app``
package which can be used to hold messages, subscription, and unsubscriptions.
There are also interfaces for disposing of these requests in an application
specific and consistent way.

    >>> from mailman.app import moderator


Holding messages
================

For this section, we need a mailing list and at least one message.

    >>> mlist = create_list('alist@example.com')
    >>> mlist.preferred_language = 'en'
    >>> mlist.real_name = 'A Test List'
    >>> msg = message_from_string("""\
    ... From: aperson@example.org
    ... To: alist@example.com
    ... Subject: Something important
    ...
    ... Here's something important about our mailing list.
    ... """)

Holding a message means keeping a copy of it that a moderator must approve
before the message is posted to the mailing list.  To hold the message, you
must supply the message, message metadata, and a text reason for the hold.  In
this case, we won't include any additional metadata.

    >>> id_1 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
    >>> requests.get_request(id_1) is not None
    True

We can also hold a message with some additional metadata.
::

    # Delete the Message-ID from the previous hold so we don't try to store
    # collisions in the message storage.
    >>> del msg['message-id']
    >>> msgdata = dict(sender='aperson@example.com',
    ...                approved=True,
    ...                received_time=123.45)
    >>> id_2 = moderator.hold_message(mlist, msg, msgdata, 'Feeling ornery')
    >>> requests.get_request(id_2) is not None
    True

Once held, the moderator can select one of several dispositions.  The most
trivial is to simply defer a decision for now.

    >>> from mailman.interfaces.action import Action
    >>> moderator.handle_message(mlist, id_1, Action.defer)
    >>> requests.get_request(id_1) is not None
    True

The moderator can also discard the message.  This is often done with spam.
Bye bye message!

    >>> moderator.handle_message(mlist, id_1, Action.discard)
    >>> print requests.get_request(id_1)
    None
    >>> virginq.files
    []

The message can be rejected, meaning it is bounced back to the sender.

    >>> moderator.handle_message(mlist, id_2, Action.reject, 'Off topic')
    >>> print requests.get_request(id_2)
    None
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: Request to mailing list "A Test List" rejected
    From: alist-bounces@example.com
    To: aperson@example.org
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your request to the alist@example.com mailing list
    <BLANKLINE>
        Posting of your message titled "Something important"
    <BLANKLINE>
    has been rejected by the list moderator.  The moderator gave the
    following reason for rejecting your request:
    <BLANKLINE>
    "Off topic"
    <BLANKLINE>
    Any questions or comments should be directed to the list administrator
    at:
    <BLANKLINE>
        alist-owner@example.com
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'aperson@example.org']
    reduced_list_headers: True
    version             : 3

Or the message can be approved.  This actually places the message back into
the incoming queue for further processing, however the message metadata
indicates that the message has been approved.

    >>> id_3 = moderator.hold_message(mlist, msg, msgdata, 'Needs approval')
    >>> moderator.handle_message(mlist, id_3, Action.accept)
    >>> inq = config.switchboards['in']
    >>> qmsg, qdata = dequeue(inq)
    >>> print qmsg.as_string()
    From: aperson@example.org
    To: alist@example.com
    Subject: Something important
    Message-ID: ...
    X-Message-ID-Hash: ...
    X-Mailman-Approved-At: ...
    <BLANKLINE>
    Here's something important about our mailing list.
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg         : False
    approved          : True
    moderator_approved: True
    sender            : aperson@example.com
    version           : 3

In addition to any of the above dispositions, the message can also be
preserved for further study.  Ordinarily the message is removed from the
global message store after its disposition (though approved messages may be
re-added to the message store).  When handling a message, we can tell the
moderator interface to also preserve a copy, essentially telling it not to
delete the message from the storage.  First, without the switch, the message
is deleted.
::

    >>> msg = message_from_string("""\
    ... From: aperson@example.org
    ... To: alist@example.com
    ... Subject: Something important
    ... Message-ID: <12345>
    ...
    ... Here's something important about our mailing list.
    ... """)
    >>> id_4 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
    >>> moderator.handle_message(mlist, id_4, Action.discard)

    >>> from mailman.interfaces.messages import IMessageStore
    >>> from zope.component import getUtility
    >>> message_store = getUtility(IMessageStore)

    >>> print message_store.get_message_by_id('<12345>')
    None

But if we ask to preserve the message when we discard it, it will be held in
the message store after disposition.

    >>> id_4 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
    >>> moderator.handle_message(mlist, id_4, Action.discard, preserve=True)
    >>> stored_msg = message_store.get_message_by_id('<12345>')
    >>> print stored_msg.as_string()
    From: aperson@example.org
    To: alist@example.com
    Subject: Something important
    Message-ID: <12345>
    X-Message-ID-Hash: 4CF7EAU3SIXBPXBB5S6PEUMO62MWGQN6
    <BLANKLINE>
    Here's something important about our mailing list.
    <BLANKLINE>

Orthogonal to preservation, the message can also be forwarded to another
address.  This is helpful for getting the message into the inbox of one of the
moderators.
::

    # Set a new Message-ID from the previous hold so we don't try to store
    # collisions in the message storage.
    >>> del msg['message-id']
    >>> msg['Message-ID'] = '<abcde>'
    >>> id_4 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
    >>> moderator.handle_message(mlist, id_4, Action.discard,
    ...                          forward=['zperson@example.com'])
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    Subject: Forward of moderated message
    From: alist-bounces@example.com
    To: zperson@example.com
    MIME-Version: 1.0
    Content-Type: message/rfc822
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    From: aperson@example.org
    To: alist@example.com
    Subject: Something important
    Message-ID: <abcde>
    X-Message-ID-Hash: EN2R5UQFMOUTCL44FLNNPLSXBIZW62ER
    <BLANKLINE>
    Here's something important about our mailing list.
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'zperson@example.com']
    reduced_list_headers: True
    version             : 3


Holding subscription requests
=============================

For closed lists, subscription requests will also be held for moderator
approval.  In this case, several pieces of information related to the
subscription must be provided, including the subscriber's address and real
name, their password (possibly hashed), what kind of delivery option they are
choosing and their preferred language.

    >>> from mailman.interfaces.member import DeliveryMode
    >>> mlist.admin_immed_notify = False
    >>> id_3 = moderator.hold_subscription(mlist,
    ...     'bperson@example.org', 'Ben Person',
    ...     '{NONE}abcxyz', DeliveryMode.regular, 'en')
    >>> requests.get_request(id_3) is not None
    True

In the above case the mailing list was not configured to send the list
moderators a notice about the hold, so no email message is in the virgin
queue.

    >>> virginq.files
    []

But if we set the list up to notify the list moderators immediately when a
message is held for approval, there will be a message placed in the virgin
queue when the message is held.

    >>> mlist.admin_immed_notify = True
    >>> # XXX This will almost certainly change once we've worked out the web
    >>> # space layout for mailing lists now.
    >>> id_4 = moderator.hold_subscription(mlist,
    ...     'cperson@example.org', 'Claire Person',
    ...     '{NONE}zyxcba', DeliveryMode.regular, 'en')
    >>> requests.get_request(id_4) is not None
    True
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: New subscription request to list A Test List from
     cperson@example.org
    From: alist-owner@example.com
    To: alist-owner@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your authorization is required for a mailing list subscription request
    approval:
    <BLANKLINE>
        For:  cperson@example.org
        List: alist@example.com
    <BLANKLINE>
    At your convenience, visit:
    <BLANKLINE>
        http://lists.example.com/admindb/alist@example.com
    <BLANKLINE>
    to process the request.
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'alist-owner@example.com']
    reduced_list_headers: True
    tomoderators        : True
    version             : 3

Once held, the moderator can select one of several dispositions.  The most
trivial is to simply defer a decision for now.

    >>> moderator.handle_subscription(mlist, id_3, Action.defer)
    >>> requests.get_request(id_3) is not None
    True

The held subscription can also be discarded.

    >>> moderator.handle_subscription(mlist, id_3, Action.discard)
    >>> print requests.get_request(id_3)
    None

The request can be rejected, in which case a message is sent to the
subscriber.

    >>> moderator.handle_subscription(mlist, id_4, Action.reject,
    ...     'This is a closed list')
    >>> print requests.get_request(id_4)
    None
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: Request to mailing list "A Test List" rejected
    From: alist-bounces@example.com
    To: cperson@example.org
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your request to the alist@example.com mailing list
    <BLANKLINE>
        Subscription request
    <BLANKLINE>
    has been rejected by the list moderator.  The moderator gave the
    following reason for rejecting your request:
    <BLANKLINE>
    "This is a closed list"
    <BLANKLINE>
    Any questions or comments should be directed to the list administrator
    at:
    <BLANKLINE>
        alist-owner@example.com
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'cperson@example.org']
    reduced_list_headers: True
    version             : 3

The subscription can also be accepted.  This subscribes the address to the
mailing list.

    >>> mlist.send_welcome_msg = True
    >>> id_4 = moderator.hold_subscription(mlist,
    ...     'fperson@example.org', 'Frank Person',
    ...     '{NONE}abcxyz', DeliveryMode.regular, 'en')

A message will be sent to the moderators telling them about the held
subscription and the fact that they may need to approve it.

    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: New subscription request to list A Test List from
     fperson@example.org
    From: alist-owner@example.com
    To: alist-owner@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your authorization is required for a mailing list subscription request
    approval:
    <BLANKLINE>
        For:  fperson@example.org
        List: alist@example.com
    <BLANKLINE>
    At your convenience, visit:
    <BLANKLINE>
        http://lists.example.com/admindb/alist@example.com
    <BLANKLINE>
    to process the request.
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'alist-owner@example.com']
    reduced_list_headers: True
    tomoderators        : True
    version             : 3

Accept the subscription request.

    >>> mlist.admin_notify_mchanges = True
    >>> moderator.handle_subscription(mlist, id_4, Action.accept)

There are now two messages in the virgin queue.  One is a welcome message
being sent to the user and the other is a subscription notification that is
sent to the moderators.  The only good way to tell which is which is to look
at the recipient list.

    >>> qmsg_1, qdata_1 = dequeue(expected_count=2)
    >>> qmsg_2, qdata_2 = dequeue()
    >>> if 'fperson@example.org' in qdata_1['recipients']:
    ...     # The first message is the welcome message
    ...     welcome_qmsg = qmsg_1
    ...     welcome_qdata = qdata_1
    ...     admin_qmsg = qmsg_2
    ...     admin_qdata = qdata_2
    ... else:
    ...     welcome_qmsg = qmsg_2
    ...     welcome_qdata = qdata_2
    ...     admin_qmsg = qmsg_1
    ...     admin_qdata = qdata_1

The welcome message is sent to the person who just subscribed.

    >>> print welcome_qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: Welcome to the "A Test List" mailing list
    From: alist-request@example.com
    To: fperson@example.org
    X-No-Archive: yes
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Welcome to the "A Test List" mailing list!
    <BLANKLINE>
    To post to this list, send your email to:
    <BLANKLINE>
      alist@example.com
    <BLANKLINE>
    General information about the mailing list is at:
    <BLANKLINE>
      http://lists.example.com/listinfo/alist@example.com
    <BLANKLINE>
    If you ever want to unsubscribe or change your options (eg, switch to
    or from digest mode, change your password, etc.), visit your
    subscription page at:
    <BLANKLINE>
      http://example.com/fperson@example.org
    <BLANKLINE>
    You can also make such adjustments via email by sending a message to:
    <BLANKLINE>
      alist-request@example.com
    <BLANKLINE>
    with the word 'help' in the subject or body (don't include the
    quotes), and you will get back a message with instructions.  You will
    need your password to change your options, but for security purposes,
    this email is not included here.  There is also a button on your
    options page that will send your current password to you.
    <BLANKLINE>
    >>> dump_msgdata(welcome_qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'fperson@example.org']
    reduced_list_headers: True
    verp                : False
    version             : 3

The admin message is sent to the moderators.

    >>> print admin_qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: A Test List subscription notification
    From: changeme@example.com
    To: alist-owner@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Frank Person <fperson@example.org> has been successfully subscribed to
    A Test List.
    <BLANKLINE>
    >>> dump_msgdata(admin_qdata)
    _parsemsg           : False
    envsender           : changeme@example.com
    listname            : alist@example.com
    nodecorate          : True
    recipients          : []
    reduced_list_headers: True
    version             : 3

Frank Person is now a member of the mailing list.
::

    >>> member = mlist.members.get_member('fperson@example.org')
    >>> member
    <Member: Frank Person <fperson@example.org>
             on alist@example.com as MemberRole.member>
    >>> member.preferred_language
    <Language [en] English (USA)>
    >>> print member.delivery_mode
    DeliveryMode.regular
    >>> print member.user.real_name
    Frank Person
    >>> print member.user.password
    {NONE}abcxyz


Holding unsubscription requests
===============================

Some lists, though it is rare, require moderator approval for unsubscriptions.
In this case, only the unsubscribing address is required.  Like subscriptions,
unsubscription holds can send the list's moderators an immediate
notification.
::


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

    >>> mlist.admin_immed_notify = False
    >>> from mailman.interfaces.member import MemberRole
    >>> user_1 = user_manager.create_user('gperson@example.com')
    >>> address_1 = list(user_1.addresses)[0]
    >>> address_1.subscribe(mlist, MemberRole.member)
    <Member: gperson@example.com on alist@example.com as MemberRole.member>

    >>> user_2 = user_manager.create_user('hperson@example.com')
    >>> address_2 = list(user_2.addresses)[0]
    >>> address_2.subscribe(mlist, MemberRole.member)
    <Member: hperson@example.com on alist@example.com as MemberRole.member>

    >>> id_5 = moderator.hold_unsubscription(mlist, 'gperson@example.com')
    >>> requests.get_request(id_5) is not None
    True
    >>> virginq.files
    []
    >>> mlist.admin_immed_notify = True
    >>> id_6 = moderator.hold_unsubscription(mlist, 'hperson@example.com')
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: New unsubscription request from A Test List by hperson@example.com
    From: alist-owner@example.com
    To: alist-owner@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your authorization is required for a mailing list unsubscription
    request approval:
    <BLANKLINE>
        By:   hperson@example.com
        From: alist@example.com
    <BLANKLINE>
    At your convenience, visit:
    <BLANKLINE>
        http://lists.example.com/admindb/alist@example.com
    <BLANKLINE>
    to process the request.
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'alist-owner@example.com']
    reduced_list_headers: True
    tomoderators        : True
    version             : 3

There are now two addresses with held unsubscription requests.  As above, one
of the actions we can take is to defer to the decision.

    >>> moderator.handle_unsubscription(mlist, id_5, Action.defer)
    >>> requests.get_request(id_5) is not None
    True

The held unsubscription can also be discarded, and the member will remain
subscribed.

    >>> moderator.handle_unsubscription(mlist, id_5, Action.discard)
    >>> print requests.get_request(id_5)
    None
    >>> mlist.members.get_member('gperson@example.com')
    <Member: gperson@example.com on alist@example.com as MemberRole.member>

The request can be rejected, in which case a message is sent to the member,
and the person remains a member of the mailing list.
::

    >>> moderator.handle_unsubscription(mlist, id_6, Action.reject,
    ...     'This list is a prison.')
    >>> print requests.get_request(id_6)
    None
    >>> qmsg, qdata = dequeue()
    >>> print qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: Request to mailing list "A Test List" rejected
    From: alist-bounces@example.com
    To: hperson@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    Your request to the alist@example.com mailing list
    <BLANKLINE>
        Unsubscription request
    <BLANKLINE>
    has been rejected by the list moderator.  The moderator gave the
    following reason for rejecting your request:
    <BLANKLINE>
    "This list is a prison."
    <BLANKLINE>
    Any questions or comments should be directed to the list administrator
    at:
    <BLANKLINE>
        alist-owner@example.com
    <BLANKLINE>
    >>> dump_msgdata(qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'hperson@example.com']
    reduced_list_headers: True
    version             : 3

    >>> mlist.members.get_member('hperson@example.com')
    <Member: hperson@example.com on alist@example.com as MemberRole.member>

The unsubscription request can also be accepted.  This removes the member from
the mailing list.

    >>> mlist.send_goodbye_msg = True
    >>> mlist.goodbye_msg = 'So long!'
    >>> mlist.admin_immed_notify = False
    >>> id_7 = moderator.hold_unsubscription(mlist, 'gperson@example.com')
    >>> moderator.handle_unsubscription(mlist, id_7, Action.accept)
    >>> print mlist.members.get_member('gperson@example.com')
    None

There are now two messages in the virgin queue, one to the member who was just
unsubscribed and another to the moderators informing them of this membership
change.

    >>> qmsg_1, qdata_1 = dequeue(expected_count=2)
    >>> qmsg_2, qdata_2 = dequeue()
    >>> if 'gperson@example.com' in qdata_1['recipients']:
    ...     # The first message is the goodbye message
    ...     goodbye_qmsg = qmsg_1
    ...     goodbye_qdata = qdata_1
    ...     admin_qmsg = qmsg_2
    ...     admin_qdata = qdata_2
    ... else:
    ...     goodbye_qmsg = qmsg_2
    ...     goodbye_qdata = qdata_2
    ...     admin_qmsg = qmsg_1
    ...     admin_qdata = qdata_1

The goodbye message...

    >>> print goodbye_qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: You have been unsubscribed from the A Test List mailing list
    From: alist-bounces@example.com
    To: gperson@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    So long!
    <BLANKLINE>
    >>> dump_msgdata(goodbye_qdata)
    _parsemsg           : False
    listname            : alist@example.com
    nodecorate          : True
    recipients          : [u'gperson@example.com']
    reduced_list_headers: True
    verp                : False
    version             : 3

...and the admin message.

    >>> print admin_qmsg.as_string()
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    Subject: A Test List unsubscription notification
    From: changeme@example.com
    To: alist-owner@example.com
    Message-ID: ...
    Date: ...
    Precedence: bulk
    <BLANKLINE>
    gperson@example.com has been removed from A Test List.
    <BLANKLINE>
    >>> dump_msgdata(admin_qdata)
    _parsemsg           : False
    envsender           : changeme@example.com
    listname            : alist@example.com
    nodecorate          : True
    recipients          : []
    reduced_list_headers: True
    version             : 3