~mailman-coders/mailman/2.1

1 by
This commit was manufactured by cvs2svn to create branch
1
#! @PYTHON@
2
#
1779 by Mark Sapiro
Bump copyright dates.
3
# Copyright (C) 2002-2018 by the Free Software Foundation, Inc.
1 by
This commit was manufactured by cvs2svn to create branch
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
1025.1.1 by Mark Sapiro
Forced lower case listnames in a few command line tools
9
#
1 by
This commit was manufactured by cvs2svn to create branch
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
1025.1.1 by Mark Sapiro
Forced lower case listnames in a few command line tools
14
#
1 by
This commit was manufactured by cvs2svn to create branch
15
# You should have received a copy of the GNU General Public License
1025.1.1 by Mark Sapiro
Forced lower case listnames in a few command line tools
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
# USA.
1 by
This commit was manufactured by cvs2svn to create branch
19
20
"""Inject a message from a file into Mailman's incoming queue.
21
22
Usage: inject [options] [filename]
23
24
Options:
25
26
    -h / --help
27
        Print this text and exit.
28
29
    -l listname
30
    --listname=listname
31
        The name of the list to inject this message to.  Required.
32
33
    -q queuename
34
    --queue=queuename
35
        The name of the queue to inject the message to.  The queuename must be
36
        one of the directories inside the qfiles directory.  If omitted, the
37
        incoming queue is used.
38
39
filename is the name of the plaintext message file to inject.  If omitted,
40
standard input is used.
41
"""
42
43
import sys
44
import os
45
import getopt
46
47
import paths
48
from Mailman import mm_cfg
49
from Mailman import Utils
50
from Mailman import Post
1619.1.1 by Yasuhito FUTATSUKI at POEM
Importing locale patch for command line utils, from RHEL6 rpm source
51
from Mailman.i18n import C_
1 by
This commit was manufactured by cvs2svn to create branch
52
53
54

55
def usage(code, msg=''):
56
    if code:
57
        fd = sys.stderr
58
    else:
59
        fd = sys.stdout
1619.1.1 by Yasuhito FUTATSUKI at POEM
Importing locale patch for command line utils, from RHEL6 rpm source
60
    print >> fd, C_(__doc__)
1 by
This commit was manufactured by cvs2svn to create branch
61
    if msg:
62
        print >> fd, msg
63
    sys.exit(code)
64
65
66

67
def main():
68
    try:
69
        opts, args = getopt.getopt(
70
            sys.argv[1:], 'hl:q:L',
71
            ['help', 'listname=', 'queue=', 'showqnames'])
72
    except getopt.error, msg:
73
        usage(1, msg)
74
75
    qdir = mm_cfg.INQUEUE_DIR
76
    listname = None
77
78
    for opt, arg in opts:
79
        if opt in ('-h', '--help'):
80
            usage(0)
81
        elif opt in ('-q', '--queue'):
82
            qdir = os.path.join(mm_cfg.QUEUE_DIR, arg)
83
            if not os.path.isdir(qdir):
1619.1.1 by Yasuhito FUTATSUKI at POEM
Importing locale patch for command line utils, from RHEL6 rpm source
84
                usage(1, C_('Bad queue directory: %(qdir)s'))
1 by
This commit was manufactured by cvs2svn to create branch
85
        elif opt in ('-l', '--listname'):
1025.1.1 by Mark Sapiro
Forced lower case listnames in a few command line tools
86
            listname = arg.lower()
1 by
This commit was manufactured by cvs2svn to create branch
87
88
    if listname is None:
1619.1.1 by Yasuhito FUTATSUKI at POEM
Importing locale patch for command line utils, from RHEL6 rpm source
89
        usage(1, C_('A list name is required'))
1 by
This commit was manufactured by cvs2svn to create branch
90
    elif not Utils.list_exists(listname):
1619.1.1 by Yasuhito FUTATSUKI at POEM
Importing locale patch for command line utils, from RHEL6 rpm source
91
        usage(1, C_('No such list: %(listname)s'))
1025.1.1 by Mark Sapiro
Forced lower case listnames in a few command line tools
92
1 by
This commit was manufactured by cvs2svn to create branch
93
    if len(args) == 0:
94
        # Use standard input
95
        msgtext = sys.stdin.read()
96
    elif len(args) == 1:
97
        fp = open(args[0])
98
        msgtext = fp.read()
99
        fp.close()
100
    else:
101
        usage(1)
102
103
    Post.inject(listname, msgtext, qdir=qdir)
104
105
106

107
if __name__ == '__main__':
108
    main()