summaryrefslogtreecommitdiff
path: root/src/mailman/handlers/docs/file-recips.rst
blob: 73b47adb172feafd9a3f51b24b8c7690efee589c (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
===============
File recipients
===============

Mailman can calculate the recipients for a message from a Sendmail-style
include file.  This file must be called ``members.txt`` and it must live in
the list's data directory.

    >>> mlist = create_list('_xtest@example.com')


Short circuiting
================

If the message's metadata already has recipients, this handler immediately
returns.
::

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ...
    ... A message.
    ... """)
    >>> msgdata = {'recipients': 7}

    >>> handler = config.handlers['file-recipients']
    >>> handler.process(mlist, msg, msgdata)
    >>> print(msg.as_string())
    From: aperson@example.com
    <BLANKLINE>
    A message.
    <BLANKLINE>
    >>> dump_msgdata(msgdata)
    recipients: 7


Existing file
=============

If the file exists, it contains a list of addresses, one per line.  These
addresses are returned as the set of recipients.
::

    >>> import os
    >>> file_path = os.path.join(mlist.data_path, 'members.txt')
    >>> with open(file_path, 'w', encoding='utf-8') as fp:
    ...     print('bperson@example.com', file=fp)
    ...     print('cperson@example.com', file=fp)
    ...     print('dperson@example.com', file=fp)
    ...     print('eperson@example.com', file=fp)
    ...     print('fperson@example.com', file=fp)
    ...     print('gperson@example.com', file=fp)

    >>> msgdata = {}
    >>> handler.process(mlist, msg, msgdata)
    >>> dump_list(msgdata['recipients'])
    bperson@example.com
    cperson@example.com
    dperson@example.com
    eperson@example.com
    fperson@example.com
    gperson@example.com

However, if the sender of the original message is a member of the list and
their address is in the include file, the sender's address is *not* included
in the recipients list.
::

    >>> from mailman.interfaces.usermanager import IUserManager
    >>> from zope.component import getUtility
    >>> address_1 = getUtility(IUserManager).create_address(
    ...     'cperson@example.com')

    >>> from mailman.interfaces.member import MemberRole
    >>> mlist.subscribe(address_1, MemberRole.member)
    <Member: cperson@example.com on _xtest@example.com as MemberRole.member>

    >>> msg = message_from_string("""\
    ... From: cperson@example.com
    ...
    ... A message.
    ... """)
    >>> msgdata = {}
    >>> handler.process(mlist, msg, msgdata)
    >>> dump_list(msgdata['recipients'])
    bperson@example.com
    dperson@example.com
    eperson@example.com
    fperson@example.com
    gperson@example.com