5
All members and nonmembers have a moderation action. When the action is not
6
`defer`, the `moderation` rule flags the message as needing moderation. This
7
might be to automatically accept, discard, reject, or hold the message.
9
Two separate rules check for member and nonmember moderation. Member
10
moderation happens early in the built-in chain, while nonmember moderation
11
happens later in the chain, after normal moderation checks.
13
>>> mlist = create_list('test@example.com')
19
>>> member_rule = config.rules['member-moderation']
20
>>> print member_rule.name
23
Anne, a mailing list member, sends a message to the mailing list. Her
24
postings are not moderated.
27
>>> from mailman.testing.helpers import subscribe
28
>>> subscribe(mlist, 'Anne')
29
>>> member = mlist.members.get_member('aperson@example.com')
30
>>> print member.moderation_action
33
Because Anne is not moderated, the member moderation rule does not match.
35
>>> member_msg = message_from_string("""\
36
... From: aperson@example.com
37
... To: test@example.com
38
... Subject: A posted message
41
>>> member_rule.check(mlist, member_msg, {})
44
Once the member's moderation action is set to something other than `defer`,
45
the rule matches. Also, the message metadata has a few extra pieces of
46
information for the eventual moderation chain.
48
>>> from mailman.interfaces.action import Action
49
>>> member.moderation_action = Action.hold
51
>>> member_rule.check(mlist, member_msg, msgdata)
53
>>> dump_msgdata(msgdata)
54
moderation_action: hold
55
moderation_sender: aperson@example.com
61
Nonmembers are handled in a similar way, although by default, nonmember
62
postings are held for moderator approval.
64
>>> nonmember_rule = config.rules['nonmember-moderation']
65
>>> print nonmember_rule.name
68
Bart, who is not a member of the mailing list, sends a message to the list.
70
>>> from mailman.interfaces.member import MemberRole
71
>>> subscribe(mlist, 'Bart', MemberRole.nonmember)
72
>>> nonmember = mlist.nonmembers.get_member('bperson@example.com')
73
>>> print nonmember.moderation_action
76
When Bart is registered as a nonmember of the list, his moderation action is
77
set to hold by default. Thus the rule matches and the message metadata again
78
carries some useful information.
80
>>> nonmember_msg = message_from_string("""\
81
... From: bperson@example.com
82
... To: test@example.com
83
... Subject: A posted message
87
>>> nonmember_rule.check(mlist, nonmember_msg, msgdata)
89
>>> dump_msgdata(msgdata)
90
moderation_action: hold
91
moderation_sender: bperson@example.com
93
Of course, the nonmember action can be set to defer the decision, in which
94
case the rule does not match.
96
>>> nonmember.moderation_action = Action.defer
97
>>> nonmember_rule.check(mlist, nonmember_msg, {})
101
Unregistered nonmembers
102
=======================
104
The incoming runner ensures that all sender addresses are registered in the
105
system, but it is the moderation rule that subscribes nonmember addresses to
106
the mailing list if they are not already subscribed.
109
>>> from mailman.interfaces.usermanager import IUserManager
110
>>> from zope.component import getUtility
111
>>> address = getUtility(IUserManager).create_address(
112
... 'cperson@example.com')
114
<Address: cperson@example.com [not verified] at ...>
116
>>> msg = message_from_string("""\
117
... From: cperson@example.com
118
... To: test@example.com
119
... Subject: A posted message
123
cperson is neither a member, nor a nonmember of the mailing list.
126
>>> def memberkey(member):
127
... return member.mailing_list, member.address.email, int(member.role)
129
>>> dump_list(mlist.members.members, key=memberkey)
130
<Member: Anne Person <aperson@example.com>
131
on test@example.com as MemberRole.member>
132
>>> dump_list(mlist.nonmembers.members, key=memberkey)
133
<Member: Bart Person <bperson@example.com>
134
on test@example.com as MemberRole.nonmember>
136
However, when the nonmember moderation rule runs, it adds the cperson as a
137
nonmember of the list. The rule also matches.
140
>>> nonmember_rule.check(mlist, msg, msgdata)
142
>>> dump_msgdata(msgdata)
143
moderation_action: hold
144
moderation_sender: cperson@example.com
146
>>> dump_list(mlist.members.members, key=memberkey)
147
<Member: Anne Person <aperson@example.com>
148
on test@example.com as MemberRole.member>
149
>>> dump_list(mlist.nonmembers.members, key=memberkey)
150
<Member: Bart Person <bperson@example.com>
151
on test@example.com as MemberRole.nonmember>
152
<Member: cperson@example.com
153
on test@example.com as MemberRole.nonmember>
156
Cross-membership checks
157
=======================
159
Of course, the member moderation rule does not match for nonmembers...
161
>>> member_rule.check(mlist, nonmember_msg, {})
163
>>> nonmember_rule.check(mlist, member_msg, {})