Extended test_documentation.py to be able to find doctests in subdirectories
[mailman.git] / Mailman / rules / docs / loop.txt
blob3174805b9a06ad6eaa808117dc3619b6cc98ba08
1 Posting loops
2 =============
4 To avoid a posting loop, Mailman has a rule to check for the existence of an
5 X-BeenThere header with the value of the list's posting address.
7     >>> from Mailman.configuration import config
8     >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
9     >>> from Mailman.app.rules import find_rule
10     >>> rule = find_rule('loop')
11     >>> rule.name
12     'loop'
14 The header could be missing, in which case the rule does not match.
16     >>> msg = message_from_string(u"""\
17     ... From: aperson@example.com
18     ...
19     ... An important message.
20     ... """)
21     >>> rule.check(mlist, msg, {})
22     False
24 The header could be present, but not match the list's posting address.
26     >>> msg['X-BeenThere'] = u'not-this-list@example.com'
27     >>> rule.check(mlist, msg, {})
28     False
30 If the header is present and does match the posting address, the rule
31 matches.
33     >>> del msg['x-beenthere']
34     >>> msg['X-BeenThere'] = mlist.posting_address
35     >>> rule.check(mlist, msg, {})
36     True
38 Even if there are multiple X-BeenThere headers, as long as one with the
39 posting address exists, the rule matches.
41     >>> msg = message_from_string(u"""\
42     ... From: aperson@example.com
43     ... X-BeenThere: not-this-list@example.com
44     ... X-BeenThere: _xtest@example.com
45     ... X-BeenThere: foo@example.com
46     ...
47     ... An important message.
48     ... """)
49     >>> rule.check(mlist, msg, {})
50     True