summaryrefslogtreecommitdiff
path: root/src/mailman/runners/docs/digester.rst
blob: d0231a89570dfe60cecda85fd8e106a45a994cf6 (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
=========
Digesting
=========

Mailman crafts and sends digests by a separate digest runner process.  This
starts by a number of messages being posted to the mailing list.
::

    >>> mlist = create_list('test@example.com')
    >>> mlist.digest_size_threshold = 0.6
    >>> mlist.volume = 1
    >>> mlist.next_digest_number = 1

    >>> from string import Template
    >>> process = config.handlers['to-digest'].process

    >>> def fill_digest():
    ...     size = 0
    ...     for i in range(1, 5):
    ...         text = Template("""\
    ... From: aperson@example.com
    ... To: xtest@example.com
    ... Subject: Test message $i
    ... List-Post: <test@example.com>
    ...
    ... Here is message $i
    ... """).substitute(i=i)
    ...         msg = message_from_string(text)
    ...         process(mlist, msg, {})
    ...         size += len(text)
    ...         if size >= mlist.digest_size_threshold * 1024:
    ...             break

    >>> fill_digest()

The runner gets kicked off when a marker message gets dropped into the digest
queue.  The message metadata points to the mailbox file containing the
messages to put in the digest.
::

    >>> digestq = config.switchboards['digest']
    >>> len(digestq.files)
    1

    >>> from mailman.testing.helpers import get_queue_messages
    >>> entry = get_queue_messages('digest')[0]

The marker message is empty.

    >>> print entry.msg.as_string()

But the message metadata has a reference to the digest file.
::

    >>> dump_msgdata(entry.msgdata)
    _parsemsg    : False
    digest_number: 1
    digest_path  : .../lists/test@example.com/digest.1.1.mmdf
    listname     : test@example.com
    version      : 3
    volume       : 1

    # Put the messages back in the queue for the runner to handle.
    >>> filebase = digestq.enqueue(entry.msg, entry.msgdata)

There are 4 messages in the digest.

    >>> from mailman.utilities.mailbox import Mailbox
    >>> sum(1 for item in Mailbox(entry.msgdata['digest_path']))
    4

When the runner runs, it processes the digest mailbox, crafting both the plain
text (RFC 1153) digest and the MIME digest.

    >>> from mailman.runners.digest import DigestRunner
    >>> from mailman.testing.helpers import make_testable_runner
    >>> runner = make_testable_runner(DigestRunner)
    >>> runner.run()

The digest runner places both digests into the virgin queue for final
delivery.

    >>> messages = get_queue_messages('virgin')
    >>> len(messages)
    2

The MIME digest is a multipart, and the RFC 1153 digest is the other one.
::

    >>> def mime_rfc1153(messages):
    ...     if messages[0].msg.is_multipart():
    ...         return messages[0], messages[1]
    ...     return messages[1], messages[0]

    >>> mime, rfc1153 = mime_rfc1153(messages)

The MIME digest has lots of good stuff, all contained in the multipart.

    >>> print mime.msg.as_string()
    Content-Type: multipart/mixed; boundary="===============...=="
    MIME-Version: 1.0
    From: test-request@example.com
    Subject: Test Digest, Vol 1, Issue 1
    To: test@example.com
    Reply-To: test@example.com
    Date: ...
    Message-ID: ...
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Description: Test Digest, Vol 1, Issue 1
    <BLANKLINE>
    Send Test mailing list submissions to
        test@example.com
    <BLANKLINE>
    To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.example.com/listinfo/test@example.com
    or, via email, send a message with subject or body 'help' to
        test-request@example.com
    <BLANKLINE>
    You can reach the person managing the list at
        test-owner@example.com
    <BLANKLINE>
    When replying, please edit your Subject line so it is more specific
    than "Re: Contents of Test digest..."
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Description: Today's Topics (4 messages)
    <BLANKLINE>
    Today's Topics:
    <BLANKLINE>
       1. Test message 1 (aperson@example.com)
       2. Test message 2 (aperson@example.com)
       3. Test message 3 (aperson@example.com)
       4. Test message 4 (aperson@example.com)
    <BLANKLINE>
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.com
    To: xtest@example.com
    Subject: Test message 1
    List-Post: <test@example.com>
    <BLANKLINE>
    Here is message 1
    <BLANKLINE>
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.com
    To: xtest@example.com
    Subject: Test message 2
    List-Post: <test@example.com>
    <BLANKLINE>
    Here is message 2
    <BLANKLINE>
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.com
    To: xtest@example.com
    Subject: Test message 3
    List-Post: <test@example.com>
    <BLANKLINE>
    Here is message 3
    <BLANKLINE>
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.com
    To: xtest@example.com
    Subject: Test message 4
    List-Post: <test@example.com>
    <BLANKLINE>
    Here is message 4
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Description: Digest Footer
    <BLANKLINE>
    _______________________________________________
    Test mailing list
    test@example.com
    http://lists.example.com/listinfo/test@example.com
    <BLANKLINE>
    --===============...==--

The RFC 1153 contains the digest in a single plain text message.

    >>> print rfc1153.msg.as_string()
    From: test-request@example.com
    Subject: Test Digest, Vol 1, Issue 1
    To: test@example.com
    Reply-To: test@example.com
    Date: ...
    Message-ID: ...
    MIME-Version: 1.0
    Content-Type: text/plain; charset="us-ascii"
    Content-Transfer-Encoding: 7bit
    <BLANKLINE>
    Send Test mailing list submissions to
        test@example.com
    <BLANKLINE>
    To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.example.com/listinfo/test@example.com
    or, via email, send a message with subject or body 'help' to
        test-request@example.com
    <BLANKLINE>
    You can reach the person managing the list at
        test-owner@example.com
    <BLANKLINE>
    When replying, please edit your Subject line so it is more specific
    than "Re: Contents of Test digest..."
    <BLANKLINE>
    Today's Topics:
    <BLANKLINE>
       1. Test message 1 (aperson@example.com)
       2. Test message 2 (aperson@example.com)
       3. Test message 3 (aperson@example.com)
       4. Test message 4 (aperson@example.com)
    <BLANKLINE>
    <BLANKLINE>
    ----------------------------------------------------------------------
    <BLANKLINE>
    From: aperson@example.com
    Subject: Test message 1
    To: xtest@example.com
    <BLANKLINE>
    Here is message 1
    <BLANKLINE>
    ------------------------------
    <BLANKLINE>
    From: aperson@example.com
    Subject: Test message 2
    To: xtest@example.com
    <BLANKLINE>
    Here is message 2
    <BLANKLINE>
    ------------------------------
    <BLANKLINE>
    From: aperson@example.com
    Subject: Test message 3
    To: xtest@example.com
    <BLANKLINE>
    Here is message 3
    <BLANKLINE>
    ------------------------------
    <BLANKLINE>
    From: aperson@example.com
    Subject: Test message 4
    To: xtest@example.com
    <BLANKLINE>
    Here is message 4
    <BLANKLINE>
    ------------------------------
    <BLANKLINE>
    Subject: Digest Footer
    <BLANKLINE>
    _______________________________________________
    Test mailing list
    test@example.com
    http://lists.example.com/listinfo/test@example.com
    <BLANKLINE>
    <BLANKLINE>
    ------------------------------
    <BLANKLINE>
    End of Test Digest, Vol 1, Issue 1
    **********************************
    <BLANKLINE>


Internationalized digests
=========================

When messages come in with a content-type character set different than that of
the list's preferred language, recipients will get an internationalized
digest.  French is not enabled by default site-wide, so enable that now.
::

    # Simulate the site administrator setting the default server language to
    # French in the configuration file.  Without this, the English template
    # will be found and the masthead won't be translated.
    >>> config.push('french', """
    ... [mailman]
    ... default_language: fr
    ... """)

    >>> mlist.preferred_language =  'fr'
    >>> msg = message_from_string("""\
    ... From: aperson@example.org
    ... To: test@example.com
    ... Subject: =?iso-2022-jp?b?GyRCMGxIVhsoQg==?=
    ... MIME-Version: 1.0
    ... Content-Type: text/plain; charset=iso-2022-jp
    ... Content-Transfer-Encoding: 7bit
    ...
    ... \x1b$B0lHV\x1b(B
    ... """)

Set the digest threshold to zero so that the digests will be sent immediately.

    >>> mlist.digest_size_threshold = 0
    >>> process(mlist, msg, {})

The marker message is sitting in the digest queue.

    >>> len(digestq.files)
    1
    >>> entry = get_queue_messages('digest')[0]
    >>> dump_msgdata(entry.msgdata)
    _parsemsg    : False
    digest_number: 2
    digest_path  : .../lists/test@example.com/digest.1.2.mmdf
    listname     : test@example.com
    version      : 3
    volume       : 1

The digest runner runs a loop, placing the two digests into the virgin queue.

    # Put the messages back in the queue for the runner to handle.
    >>> filebase = digestq.enqueue(entry.msg, entry.msgdata)
    >>> runner.run()
    >>> messages = get_queue_messages('virgin')
    >>> len(messages)
    2

One of which is the MIME digest and the other of which is the RFC 1153 digest.

    >>> mime, rfc1153 = mime_rfc1153(messages)

You can see that the digests contain a mix of French and Japanese.

    >>> print mime.msg.as_string()
    Content-Type: multipart/mixed; boundary="===============...=="
    MIME-Version: 1.0
    From: test-request@example.com
    Subject: Groupe Test, Vol 1, Parution 2
    To: test@example.com
    Reply-To: test@example.com
    Date: ...
    Message-ID: ...
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="iso-8859-1"
    MIME-Version: 1.0
    Content-Transfer-Encoding: quoted-printable
    Content-Description: Groupe Test, Vol 1, Parution 2
    <BLANKLINE>
    Envoyez vos messages pour la liste Test =E0
        test@example.com
    <BLANKLINE>
    Pour vous (d=E9s)abonner par le web, consultez
        http://lists.example.com/listinfo/test@example.com
    <BLANKLINE>
    ou, par courriel, envoyez un message avec =AB=A0help=A0=BB dans le corps ou
    dans le sujet =E0
        test-request@example.com
    <BLANKLINE>
    Vous pouvez contacter l'administrateur de la liste =E0 l'adresse
        test-owner@example.com
    <BLANKLINE>
    Si vous r=E9pondez, n'oubliez pas de changer l'objet du message afin
    qu'il soit plus sp=E9cifique que =AB=A0Re: Contenu du groupe de Test...=A0=
    =BB
    --===============...==
    Content-Type: text/plain; charset="utf-8"
    MIME-Version: 1.0
    Content-Transfer-Encoding: base64
    Content-Description: Today's Topics (1 messages)
    <BLANKLINE>
    VGjDqG1lcyBkdSBqb3VyIDoKCiAgIDEuIOS4gOeVqiAoYXBlcnNvbkBleGFtcGxlLm9yZykK
    <BLANKLINE>
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.org
    To: test@example.com
    Subject: =?iso-2022-jp?b?GyRCMGxIVhsoQg==?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=iso-2022-jp
    Content-Transfer-Encoding: 7bit
    <BLANKLINE>
    $B0lHV(B
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="iso-8859-1"
    MIME-Version: 1.0
    Content-Transfer-Encoding: quoted-printable
    Content-Description: =?utf-8?q?Pied_de_page_des_remises_group=C3=A9es?=
    <BLANKLINE>
    _______________________________________________
    Test mailing list
    test@example.com
    http://lists.example.com/listinfo/test@example.com
    <BLANKLINE>
    --===============...==--

The RFC 1153 digest will be encoded in UTF-8 since it contains a mixture of
French and Japanese characters.

    >>> print rfc1153.msg.as_string()
    From: test-request@example.com
    Subject: Groupe Test, Vol 1, Parution 2
    To: test@example.com
    Reply-To: test@example.com
    Date: ...
    Message-ID: ...
    MIME-Version: 1.0
    Content-Type: text/plain; charset="utf-8"
    Content-Transfer-Encoding: base64
    <BLANKLINE>
    RW52b...
    <BLANKLINE>

The content can be decoded to see the actual digest text.
::

    # We must display the repr of the decoded value because doctests cannot
    # handle the non-ascii characters.
    >>> [repr(line)
    ...  for line in rfc1153.msg.get_payload(decode=True).splitlines()]
    ["'Envoyez vos messages pour la liste Test \\xc3\\xa0'",
    "'\\ttest@example.com'",
    "''",
    "'Pour vous (d\\xc3\\xa9s)abonner par le web, consultez'",
    "'\\thttp://lists.example.com/listinfo/test@example.com'",
    "''",
    "'ou, par courriel, envoyez un message avec \\xc2\\xab\\xc2\\xa0...
    "'dans le sujet \\xc3\\xa0'",
    "'\\ttest-request@example.com'",
    "''",
    '"Vous pouvez contacter l\'administrateur de la liste \\xc3\\xa0 ...
    "'\\ttest-owner@example.com'",
    "''",
    '"Si vous r\\xc3\\xa9pondez, n\'oubliez pas de changer l\'objet du ...
    '"qu\'il soit plus sp\\xc3\\xa9cifique que \\xc2\\xab\\xc2\\xa0Re: ...
    "''",
    "'Th\\xc3\\xa8mes du jour :'",
    "''",
    "'   1. \\xe4\\xb8\\x80\\xe7\\x95\\xaa (aperson@example.org)'",
    "''",
    "''",
    "'---------------------------------------------------------------------...
    "''",
    "'From: aperson@example.org'",
    "'Subject: \\xe4\\xb8\\x80\\xe7\\x95\\xaa'",
    "'To: test@example.com'",
    "'Content-Type: text/plain; charset=iso-2022-jp'",
    "''",
    "'\\xe4\\xb8\\x80\\xe7\\x95\\xaa'",
    "''",
    "'------------------------------'",
    "''",
    "'Subject: Pied de page des remises group\\xc3\\xa9es'",
    "''",
    "'_______________________________________________'",
    "'Test mailing list'",
    "'test@example.com'",
    "'http://lists.example.com/listinfo/test@example.com'",
    "''",
    "''",
    "'------------------------------'",
    "''",
    "'Fin de Groupe Test, Vol 1, Parution 2'",
    "'*************************************'"]

     >>> config.pop('french')


Digest delivery
===============

A mailing list's members can choose to receive normal delivery, plain text
digests, or MIME digests.
::

    >>> len(get_queue_messages('virgin'))
    0

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

    >>> from mailman.interfaces.member import DeliveryMode, MemberRole
    >>> def subscribe(email, mode):
    ...     address = user_manager.create_address(email)
    ...     member = mlist.subscribe(address, MemberRole.member)
    ...     member.preferences.delivery_mode = mode
    ...     return member

Two regular delivery members subscribe to the mailing list.

    >>> member_1 = subscribe('uperson@example.com', DeliveryMode.regular)
    >>> member_2 = subscribe('vperson@example.com', DeliveryMode.regular)

Two MIME digest members subscribe to the mailing list.

    >>> member_3 = subscribe('wperson@example.com', DeliveryMode.mime_digests)
    >>> member_4 = subscribe('xperson@example.com', DeliveryMode.mime_digests)

One RFC 1153 digest member subscribes to the mailing list.

    >>> member_5 = subscribe(
    ...     'yperson@example.com', DeliveryMode.plaintext_digests)
    >>> member_6 = subscribe(
    ...     'zperson@example.com', DeliveryMode.plaintext_digests)

When a digest gets sent, the appropriate recipient list is chosen.

    >>> mlist.preferred_language = 'en'
    >>> mlist.digest_size_threshold = 0.5
    >>> fill_digest()
    >>> runner.run()

The digests are sitting in the virgin queue.  One of them is the MIME digest
and the other is the RFC 1153 digest.
::

    >>> messages = get_queue_messages('virgin')
    >>> len(messages)
    2

    >>> mime, rfc1153 = mime_rfc1153(messages)

Only wperson and xperson get the MIME digests.

    >>> sorted(mime.msgdata['recipients'])
    [u'wperson@example.com', u'xperson@example.com']

Only yperson and zperson get the RFC 1153 digests.

    >>> sorted(rfc1153.msgdata['recipients'])
    [u'yperson@example.com', u'zperson@example.com']

Now uperson decides that they would like to start receiving digests too.
::

    >>> member_1.preferences.delivery_mode = DeliveryMode.mime_digests
    >>> fill_digest()
    >>> runner.run()

    >>> messages = get_queue_messages('virgin')
    >>> len(messages)
    2

    >>> mime, rfc1153 = mime_rfc1153(messages)
    >>> sorted(mime.msgdata['recipients'])
    [u'uperson@example.com', u'wperson@example.com', u'xperson@example.com']

    >>> sorted(rfc1153.msgdata['recipients'])
    [u'yperson@example.com', u'zperson@example.com']

At this point, both uperson and wperson decide that they'd rather receive
regular deliveries instead of digests.  uperson would like to get any last
digest that may be sent so that she doesn't miss anything.  wperson does care
as much and does not want to receive one last digest.
::

    >>> mlist.send_one_last_digest_to(
    ...     member_1.address, member_1.preferences.delivery_mode)

    >>> member_1.preferences.delivery_mode = DeliveryMode.regular
    >>> member_3.preferences.delivery_mode = DeliveryMode.regular

    >>> fill_digest()
    >>> runner.run()

    >>> messages = get_queue_messages('virgin')
    >>> mime, rfc1153 = mime_rfc1153(messages)
    >>> sorted(mime.msgdata['recipients'])
    [u'uperson@example.com', u'xperson@example.com']

    >>> sorted(rfc1153.msgdata['recipients'])
    [u'yperson@example.com', u'zperson@example.com']

Since uperson has received their last digest, they will not get any more of
them.
::

    >>> fill_digest()
    >>> runner.run()

    >>> messages = get_queue_messages('virgin')
    >>> len(messages)
    2

    >>> mime, rfc1153 = mime_rfc1153(messages)
    >>> sorted(mime.msgdata['recipients'])
    [u'xperson@example.com']

    >>> sorted(rfc1153.msgdata['recipients'])
    [u'yperson@example.com', u'zperson@example.com']