diff options
| author | Barry Warsaw | 2017-07-22 03:02:05 +0000 |
|---|---|---|
| committer | Barry Warsaw | 2017-07-22 03:02:05 +0000 |
| commit | f00b94f18e1d82d1488cbcee6053f03423bc2f49 (patch) | |
| tree | 1a8e56dff0eab71e58e5fc9ecc5f3c614d7edca7 /src/mailman/commands/docs/inject.rst | |
| parent | f54c045519300f6f70947d1114f46c2b8ae0d368 (diff) | |
| download | mailman-f00b94f18e1d82d1488cbcee6053f03423bc2f49.tar.gz mailman-f00b94f18e1d82d1488cbcee6053f03423bc2f49.tar.zst mailman-f00b94f18e1d82d1488cbcee6053f03423bc2f49.zip | |
Diffstat (limited to 'src/mailman/commands/docs/inject.rst')
| -rw-r--r-- | src/mailman/commands/docs/inject.rst | 126 |
1 files changed, 33 insertions, 93 deletions
diff --git a/src/mailman/commands/docs/inject.rst b/src/mailman/commands/docs/inject.rst index 163f62886..3db22013a 100644 --- a/src/mailman/commands/docs/inject.rst +++ b/src/mailman/commands/docs/inject.rst @@ -4,29 +4,12 @@ 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 - ... keywords = [] - >>> args = FakeArgs() - >>> class FakeParser: - ... def error(self, message): - ... print(message) - >>> command.parser = FakeParser() + >>> command = cli('mailman.commands.cli_inject.inject') It's easy to find out which queues are available. -:: - >>> args.show = True - >>> command.process(args) + >>> command('mailman inject --show') Available queues: archive bad @@ -41,49 +24,40 @@ It's easy to find out which queues are available. 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: + >>> from tempfile import NamedTemporaryFile + >>> filename = cleanups.enter_context(NamedTemporaryFile()).name + >>> with open(filename, 'w', encoding='utf-8') as fp: ... print("""\ ... From: aperson@example.com - ... To: test@example.com + ... To: ant@example.com ... Subject: testing ... Message-ID: <aardvark> ... ... This is a test message. ... """, file=fp) -However, the mailing list name is always required. +Create a mailing list to inject this message into. - >>> args.filename = filename - >>> command.process(args) - List name is required + >>> mlist = create_list('ant@example.com') + >>> transaction.commit() -Let's provide a list name and try again. -:: +The mailing list's incoming queue is empty. - >>> mlist = create_list('test@example.com') - >>> transaction.commit() >>> from mailman.testing.helpers import get_queue_messages - >>> get_queue_messages('in') [] - >>> args.listname = ['test@example.com'] - >>> command.process(args) -By default, the incoming queue is used. -:: +By default, messages are injected into the incoming queue. + >>> command('mailman inject --filename ' + filename + ' ant@example.com') >>> items = get_queue_messages('in') >>> len(items) 1 >>> print(items[0].msg.as_string()) From: aperson@example.com - To: test@example.com + To: ant@example.com Subject: testing Message-ID: ... Date: ... @@ -92,17 +66,19 @@ By default, the incoming queue is used. <BLANKLINE> <BLANKLINE> +And the message is destined for ant@example.com. + >>> dump_msgdata(items[0].msgdata) _parsemsg : False - listid : test.example.com - original_size: 253 + listid : ant.example.com + original_size: 252 version : 3 But a different queue can be specified on the command line. :: - >>> args.queue = 'virgin' - >>> command.process(args) + >>> command('mailman inject --queue virgin --filename ' + + ... filename + ' ant@example.com') >>> get_queue_messages('in') [] @@ -111,7 +87,7 @@ But a different queue can be specified on the command line. 1 >>> print(items[0].msg.as_string()) From: aperson@example.com - To: test@example.com + To: ant@example.com Subject: testing Message-ID: ... Date: ... @@ -122,8 +98,8 @@ But a different queue can be specified on the command line. >>> dump_msgdata(items[0].msgdata) _parsemsg : False - listid : test.example.com - original_size: 253 + listid : ant.example.com + original_size: 252 version : 3 @@ -133,29 +109,22 @@ Standard input The message text can also be provided on standard input. :: - >>> from io import StringIO - - >>> standard_in = StringIO(str("""\ + >>> stdin = """\ ... From: bperson@example.com - ... To: test@example.com + ... To: ant@example.com ... Subject: another test ... Message-ID: <badger> ... ... This is another test message. - ... """)) - - >>> import sys - >>> sys.stdin = standard_in - >>> args.filename = '-' - >>> args.queue = None + ... """ - >>> command.process(args) + >>> command('mailman inject --filename - ant@example.com', input=stdin) >>> items = get_queue_messages('in') >>> len(items) 1 >>> print(items[0].msg.as_string()) From: bperson@example.com - To: test@example.com + To: ant@example.com Subject: another test Message-ID: ... Date: ... @@ -166,14 +135,10 @@ The message text can also be provided on standard input. >>> dump_msgdata(items[0].msgdata) _parsemsg : False - listid : test.example.com - original_size: 261 + listid : ant.example.com + original_size: 260 version : 3 -.. Clean up. - >>> sys.stdin = sys.__stdin__ - >>> args.filename = filename - Metadata ======== @@ -183,39 +148,14 @@ pairs get added to the message metadata dictionary when the message is injected. :: - >>> args = FakeArgs() - >>> args.filename = filename - >>> args.listname = ['test@example.com'] - >>> args.keywords = ['foo=one', 'bar=two'] - >>> command.process(args) + >>> command('mailman inject --filename ' + filename + + ... ' -m foo=one -m bar=two ant@example.com') >>> items = get_queue_messages('in') >>> dump_msgdata(items[0].msgdata) _parsemsg : False bar : two foo : one - listid : test.example.com - original_size: 253 + listid : ant.example.com + original_size: 252 version : 3 - - -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 - - -.. - # Clean up the tempfile. - >>> os.remove(filename) |
