summaryrefslogtreecommitdiff
path: root/src/mailman/queue/docs/incoming.txt
blob: 74326820ffa055f463a5d3abc8d765db14f8dd76 (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
=========================
The incoming queue runner
=========================

This runner's sole purpose in life is to decide the disposition of the
message.  It can either be accepted for delivery, rejected (i.e. bounced),
held for moderator approval, or discarded.

The runner operates by processing chains on a message/metadata pair in the
context of a mailing list.  Each mailing list may have a 'start chain' where
processing begins, with a global default.  This chain is processed with the
message eventually ending up in one of the four disposition states described
above.

    >>> mlist = create_list('_xtest@example.com')
    >>> print mlist.start_chain
    built-in


Accepted messages
=================

We have a message that is going to be sent to the mailing list.  This message
is so perfectly fine for posting that it will be accepted and forward to the
pipeline queue.

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: _xtest@example.com
    ... Subject: My first post
    ... Message-ID: <first>
    ...
    ... First post!
    ... """)

Normally, the upstream mail server would drop the message in the incoming
queue, but this is an effective simulation.

    >>> from mailman.inject import inject_message
    >>> inject_message(mlist, msg)

The incoming queue runner runs until it is empty.

    >>> from mailman.queue.incoming import IncomingRunner
    >>> from mailman.testing.helpers import make_testable_runner
    >>> incoming = make_testable_runner(IncomingRunner, 'in')
    >>> incoming.run()

And now the message is in the pipeline queue.

    >>> pipeline_queue = config.switchboards['pipeline']
    >>> len(pipeline_queue.files)
    1
    >>> incoming_queue = config.switchboards['in']
    >>> len(incoming_queue.files)
    0
    >>> from mailman.testing.helpers import get_queue_messages
    >>> item = get_queue_messages('pipeline')[0]
    >>> print item.msg.as_string()
    From: aperson@example.com
    To: _xtest@example.com
    Subject: My first post
    Message-ID: <first>
    Date: ...
    X-Mailman-Rule-Misses: approved; emergency; loop; administrivia;
        implicit-dest;
        max-recipients; max-size; news-moderation; no-subject;
        suspicious-header
    <BLANKLINE>
    First post!
    <BLANKLINE>
    >>> dump_msgdata(item.msgdata)
    _parsemsg    : False
    envsender    : noreply@example.com
    ...


Held messages
=============

The list moderator sets the emergency flag on the mailing list.  The built-in
chain will now hold all posted messages, so nothing will show up in the
pipeline queue.

    # XXX This checks the vette log file because there is no other evidence
    # that this chain has done anything.
    >>> import os
    >>> fp = open(os.path.join(config.LOG_DIR, 'vette'))
    >>> fp.seek(0, 2)

    >>> mlist.emergency = True
    >>> inject_message(mlist, msg)
    >>> file_pos = fp.tell()
    >>> incoming.run()
    >>> len(pipeline_queue.files)
    0
    >>> len(incoming_queue.files)
    0
    >>> fp.seek(file_pos)
    >>> print 'LOG:', fp.read()
    LOG: ... HOLD: _xtest@example.com post from aperson@example.com held,
    message-id=<first>: n/a
    <BLANKLINE>

    >>> mlist.emergency = False


Discarded messages
==================

Another possibility is that the message would get immediately discarded.  The
built-in chain does not have such a disposition by default, so let's craft a
new chain and set it as the mailing list's start chain.

    >>> from mailman.chains.base import Chain, Link
    >>> from mailman.interfaces.chain import LinkAction
    >>> truth_rule = config.rules['truth']
    >>> discard_chain = config.chains['discard']
    >>> test_chain = Chain('always-discard', 'Testing discards')
    >>> link = Link(truth_rule, LinkAction.jump, discard_chain)
    >>> test_chain.append_link(link)
    >>> mlist.start_chain = 'always-discard'

    >>> inject_message(mlist, msg)
    >>> file_pos = fp.tell()
    >>> incoming.run()
    >>> len(pipeline_queue.files)
    0
    >>> len(incoming_queue.files)
    0
    >>> fp.seek(file_pos)
    >>> print 'LOG:', fp.read()
    LOG: ... DISCARD: <first>
    <BLANKLINE>

    >>> del config.chains['always-discard']


Rejected messages
=================

Similar to discarded messages, a message can be rejected, or bounced back to
the original sender.  Again, the built-in chain doesn't support this so we'll
just create a new chain that does.

    >>> reject_chain = config.chains['reject']
    >>> test_chain = Chain('always-reject', 'Testing rejections')
    >>> link = Link(truth_rule, LinkAction.jump, reject_chain)
    >>> test_chain.append_link(link)
    >>> mlist.start_chain = 'always-reject'

The virgin queue needs to be cleared out due to artifacts from the previous
tests above.

    >>> virgin_queue = config.switchboards['virgin']
    >>> ignore = get_queue_messages('virgin')

    >>> inject_message(mlist, msg)
    >>> file_pos = fp.tell()
    >>> incoming.run()
    >>> len(pipeline_queue.files)
    0
    >>> len(incoming_queue.files)
    0

    >>> len(virgin_queue.files)
    1
    >>> item = get_queue_messages('virgin')[0]
    >>> print item.msg.as_string()
    Subject: My first post
    From: _xtest-owner@example.com
    To: aperson@example.com
    ...
    <BLANKLINE>
    --===============...
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    <BLANKLINE>
    [No bounce details are available]
    --===============...
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    From: aperson@example.com
    To: _xtest@example.com
    Subject: My first post
    Message-ID: <first>
    Date: ...
    <BLANKLINE>
    First post!
    <BLANKLINE>
    --===============...

    >>> dump_msgdata(item.msgdata)
    _parsemsg           : False
    ...
    recipients          : [u'aperson@example.com']
    ...

    >>> fp.seek(file_pos)
    >>> print 'LOG:', fp.read()
    LOG: ... REJECT: <first>
    <BLANKLINE>

    >>> del config.chains['always-reject']