summaryrefslogtreecommitdiff
path: root/src/mailman/commands/docs/unshunt.rst
blob: fb2a4b6029ccb3c53d2f55bf3a7d9a8e0cf74be2 (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
=======
Unshunt
=======

When errors occur while processing email messages, the messages will end up in
the ``shunt`` queue.  The ``unshunt`` command allows system administrators to
manage the shunt queue.
::

    >>> command = cli('mailman.commands.cli_unshunt.unshunt')

Let's say there is a message in the shunt queue.
::

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: A broken message
    ... Message-ID: <aardvark>
    ...
    ... """)

    >>> shuntq = config.switchboards['shunt']
    >>> len(list(shuntq.files))
    0
    >>> base_name = shuntq.enqueue(msg, {})
    >>> len(list(shuntq.files))
    1

The ``unshunt`` command by default moves the message back to the incoming
queue.
::

    >>> inq = config.switchboards['in']
    >>> len(list(inq.files))
    0

    >>> command('mailman unshunt')

    >>> from mailman.testing.helpers import get_queue_messages
    >>> items = get_queue_messages('in')
    >>> len(items)
    1
    >>> print(items[0].msg.as_string())
    From: aperson@example.com
    To: test@example.com
    Subject: A broken message
    Message-ID: <aardvark>
    <BLANKLINE>
    <BLANKLINE>

``unshunt`` moves all shunt queue messages.
::

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: A broken message
    ... Message-ID: <badgers>
    ...
    ... """)
    >>> base_name = shuntq.enqueue(msg, {})

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: A broken message
    ... Message-ID: <crow>
    ...
    ... """)
    >>> base_name = shuntq.enqueue(msg, {})

    >>> len(list(shuntq.files))
    2

    >>> command('mailman unshunt')
    >>> items = get_queue_messages('in')
    >>> len(items)
    2

    >>> sorted(item.msg['message-id'] for item in items)
    ['<badgers>', '<crow>']


Return to the original queue
============================

While the messages in the shunt queue are generally returned to the incoming
queue, if the error occurred while the message was being processed from a
different queue, it will be returned to the queue it came from.

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: A broken message
    ... Message-ID: <dingo>
    ...
    ... """)

The queue that the message comes from is in message metadata.
::

    >>> base_name = shuntq.enqueue(msg, {}, whichq='bounces')

    >>> len(list(shuntq.files))
    1
    >>> len(list(config.switchboards['bounces'].files))
    0

The message is automatically re-queued to the bounces queue.
::

    >>> command('mailman unshunt')
    >>> len(list(shuntq.files))
    0
    >>> items = get_queue_messages('bounces')
    >>> len(items)
    1

    >>> print(items[0].msg.as_string())
    From: aperson@example.com
    To: test@example.com
    Subject: A broken message
    Message-ID: <dingo>
    <BLANKLINE>
    <BLANKLINE>


Discarding all shunted messages
===============================

If you don't care about the shunted messages, just discard them.
::

    >>> msg = message_from_string("""\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: A broken message
    ... Message-ID: <elephant>
    ...
    ... """)
    >>> base_name = shuntq.enqueue(msg, {})

    >>> command('mailman unshunt --discard')

The messages are now gone.

    >>> items = get_queue_messages('in')
    >>> len(items)
    0