summaryrefslogtreecommitdiff
path: root/src/mailman/rules/docs/emergency.txt
blob: 70f455dca459987fbd5b5b113d4a57bb24e13f5b (plain) (blame)
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
=========
Emergency
=========

When the mailing list has its emergency flag set, all messages posted to the
list are held for moderator approval.

    >>> mlist = create_list('_xtest@example.com')
    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: _xtest@example.com
    ... Subject: My first post
    ... Message-ID: <first>
    ...
    ... An important message.
    ... """)

The emergency rule is matched as part of the built-in chain.  The emergency
rule matches if the flag is set on the mailing list.

    >>> from mailman.core.chains import process
    >>> mlist.emergency = True
    >>> process(mlist, msg, {}, 'built-in')

There are two messages in the virgin queue.  The one addressed to the original
sender will contain a token we can use to grab the held message out of the
pending requests.

    >>> virginq = config.switchboards['virgin']

    >>> from mailman.interfaces.messages import IMessageStore
    >>> from mailman.interfaces.pending import IPendings
    >>> from mailman.interfaces.requests import IRequests
    >>> from zope.component import getUtility
    >>> message_store = getUtility(IMessageStore)

    >>> def get_held_message():
    ...     import re
    ...     qfiles = []
    ...     for filebase in virginq.files:
    ...         qmsg, qdata = virginq.dequeue(filebase)
    ...         virginq.finish(filebase)
    ...         qfiles.append(qmsg)
    ...     from operator import itemgetter
    ...     qfiles.sort(key=itemgetter('to'))
    ...     cookie = None
    ...     for line in qfiles[1].get_payload().splitlines():
    ...         mo = re.search('confirm/[^/]+/(?P<cookie>.*)$', line)
    ...         if mo:
    ...             cookie = mo.group('cookie')
    ...             break
    ...     assert cookie is not None, 'No confirmation token found'
    ...     data = getUtility(IPendings).confirm(cookie)
    ...     requestdb = getUtility(IRequests).get_list_requests(mlist)
    ...     rkey, rdata = requestdb.get_request(data['id'])
    ...     return message_store.get_message_by_id(
    ...         rdata['_mod_message_id'])

    >>> msg = get_held_message()
    >>> print msg.as_string()
    From: aperson@example.com
    To: _xtest@example.com
    Subject: My first post
    Message-ID: <first>
    X-Mailman-Rule-Hits: emergency
    X-Mailman-Rule-Misses: approved
    X-Message-ID-Hash: RXJU4JL6N2OUN3OYMXXPPSCR7P7JE2BW
    <BLANKLINE>
    An important message.
    <BLANKLINE>

However, if the message metadata has a 'moderator_approved' key set, then even
if the mailing list has its emergency flag set, the message still goes through
to the membership.

    >>> process(mlist, msg, dict(moderator_approved=True), 'built-in')
    >>> len(virginq.files)
    0