summaryrefslogtreecommitdiff
path: root/src/mailman/commands/docs/inject.txt
blob: e8c405b0733298928ebb0e9fc37cb0c2c1982cd7 (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
==============================
Command line message injection
==============================

You can inject a message directly into a queue directory via the command
line.
::

    >>> from mailman.commands.cli_inject import Inject
    >>> command = Inject()

    >>> class FakeArgs:
    ...     queue = None
    ...     show = False
    ...     filename = None
    ...     listname = None
    >>> args = FakeArgs()

    >>> class FakeParser:
    ...     def error(self, message):
    ...         print message
    >>> command.parser = FakeParser()

It's easy to find out which queues are available.
::

    >>> args.show = True
    >>> command.process(args)
    Available queues:
        archive
        bad
        bounces
        command
        digest
        in
        lmtp
        maildir
        news
        out
        pipeline
        rest
        retry
        shunt
        virgin

    >>> args.show = False

Usually, the text of the message to inject is in a file.

    >>> import os, tempfile
    >>> fd, filename = tempfile.mkstemp()
    >>> with os.fdopen(fd, 'w') as fp:
    ...     print >> fp, """\
    ... From: aperson@example.com
    ... To: test@example.com
    ... Subject: testing
    ...
    ... This is a test message.
    ... """

However, the mailing list name is always required.

    >>> args.filename = filename
    >>> command.process(args)
    List name is required

Let's provide a list name and try again.
::

    >>> mlist = create_list('test@example.com')
    >>> transaction.commit()

    >>> in_queue = config.switchboards['in']
    >>> len(in_queue.files)
    0
    >>> args.listname = ['test@example.com']
    >>> command.process(args)

By default, the incoming queue is used.
::

    >>> len(in_queue.files)
    1

    >>> from mailman.testing.helpers import get_queue_messages
    >>> item = get_queue_messages('in')[0]
    >>> print item.msg.as_string()
    From: aperson@example.com
    To: test@example.com
    Subject: testing
    Message-ID: ...
    Date: ...
    <BLANKLINE>
    This is a test message.
    <BLANKLINE>
    <BLANKLINE>

    >>> dump_msgdata(item.msgdata)
    _parsemsg    : False
    listname     : test@example.com
    original_size: 90
    version      : 3

But a different queue can be specified on the command line.
::

    >>> args.queue = 'virgin'
    >>> command.process(args)

    >>> len(in_queue.files)
    0
    >>> virgin_queue = config.switchboards['virgin']
    >>> len(virgin_queue.files)
    1
    >>> item = get_queue_messages('virgin')[0]
    >>> print item.msg.as_string()
    From: aperson@example.com
    To: test@example.com
    Subject: testing
    Message-ID: ...
    Date: ...
    <BLANKLINE>
    This is a test message.
    <BLANKLINE>
    <BLANKLINE>

    >>> dump_msgdata(item.msgdata)
    _parsemsg    : False
    listname     : test@example.com
    original_size: 90
    version      : 3

    # Clean up the tempfile.
    >>> os.remove(filename)


Standard input
==============

The message text can also be provided on standard input.
::

    >>> from StringIO import StringIO

    # Remember: we've got unicode literals turned on.
    >>> standard_in = StringIO(str("""\
    ... From: bperson@example.com
    ... To: test@example.com
    ... Subject: another test
    ...
    ... This is another test message.
    ... """))

    >>> import sys
    >>> sys.stdin = standard_in
    >>> args.filename = '-'
    >>> args.queue = None

    >>> command.process(args)
    >>> len(in_queue.files)
    1
    >>> item = get_queue_messages('in')[0]
    >>> print item.msg.as_string()
    From: bperson@example.com
    To: test@example.com
    Subject: another test
    Message-ID: ...
    Date: ...
    <BLANKLINE>
    This is another test message.
    <BLANKLINE>
    <BLANKLINE>

    >>> dump_msgdata(item.msgdata)
    _parsemsg    : False
    listname     : test@example.com
    original_size: 100
    version      : 3

    # Clean up.
    >>> sys.stdin = sys.__stdin__
    >>> args.filename = filename


Errors
======

It is an error to specify a queue that doesn't exist.

    >>> args.queue = 'xxbogusxx'
    >>> command.process(args)
    No such queue: xxbogusxx

It is also an error to specify a mailing list that doesn't exist.

    >>> args.queue = None
    >>> args.listname = ['bogus']
    >>> command.process(args)
    No such list: bogus