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
|
The command queue runner
========================
This queue runner's purpose is to process and respond to email commands.
Commands are extensible using the Mailman plugin system, but Mailman comes
with a number of email commands out of the box. These are processed when a
message is sent to the list's -request address.
>>> from mailman.app.lifecycle import create_list
>>> mlist = create_list(u'test@example.com')
A command in the Subject
------------------------
For example, the 'echo' command simply echoes the original command back to the
sender. The command can be in the Subject header.
>>> msg = message_from_string("""\
... From: aperson@example.com
... To: test-request@example.com
... Subject: echo hello
... Message-ID: <aardvark>
...
... """)
>>> from mailman.inject import inject_message
>>> inject_message(mlist, msg, switchboard='command')
>>> from mailman.queue.command import CommandRunner
>>> from mailman.testing.helpers import make_testable_runner
>>> command = make_testable_runner(CommandRunner)
>>> command.run()
And now the response is in the virgin queue.
>>> from mailman.queue import Switchboard
>>> virgin_queue = config.switchboards['virgin']
>>> len(virgin_queue.files)
1
>>> from mailman.testing.helpers import get_queue_messages
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
Subject: The results of your email commands
From: test-bounces@example.com
To: aperson@example.com
...
<BLANKLINE>
The results of your email command are provided below.
<BLANKLINE>
- Original message details:
From: aperson@example.com
Subject: echo hello
Date: ...
Message-ID: <aardvark>
<BLANKLINE>
- Results:
echo hello
<BLANKLINE>
- Done.
<BLANKLINE>
>>> sorted(item.msgdata.items())
[..., ('listname', u'test@example.com'), ...,
('recips', [u'aperson@example.com']),
...]
A command in the body
---------------------
The command can also be found in the body of the message, as long as the
message is plain text.
>>> msg = message_from_string("""\
... From: bperson@example.com
... To: test-request@example.com
... Message-ID: <bobcat>
...
... echo foo bar
... """)
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
Subject: The results of your email commands
From: test-bounces@example.com
To: bperson@example.com
...
Precedence: bulk
<BLANKLINE>
The results of your email command are provided below.
<BLANKLINE>
- Original message details:
From: bperson@example.com
Subject: n/a
Date: ...
Message-ID: <bobcat>
<BLANKLINE>
- Results:
echo foo bar
<BLANKLINE>
- Done.
<BLANKLINE>
Stopping command processing
---------------------------
The 'end' command stops email processing, so that nothing following is looked
at by the command queue.
>>> msg = message_from_string("""\
... From: cperson@example.com
... To: test-request@example.com
... Message-ID: <caribou>
...
... echo foo bar
... end ignored
... echo baz qux
... """)
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
Subject: The results of your email commands
...
<BLANKLINE>
- Results:
echo foo bar
<BLANKLINE>
- Unprocessed:
echo baz qux
<BLANKLINE>
- Done.
<BLANKLINE>
The 'stop' command is an alias for 'end'.
>>> msg = message_from_string("""\
... From: cperson@example.com
... To: test-request@example.com
... Message-ID: <caribou>
...
... echo foo bar
... stop ignored
... echo baz qux
... """)
>>> inject_message(mlist, msg, switchboard='command')
>>> command.run()
>>> len(virgin_queue.files)
1
>>> item = get_queue_messages('virgin')[0]
>>> print item.msg.as_string()
Subject: The results of your email commands
...
<BLANKLINE>
- Results:
echo foo bar
<BLANKLINE>
- Unprocessed:
echo baz qux
<BLANKLINE>
- Done.
<BLANKLINE>
|