~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) 1998-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.
9
# 
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.
14
# 
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software 
749 by tkikuchi
FSF office has moved to 51 Franklin Street.
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1 by
This commit was manufactured by cvs2svn to create branch
18
19
"""Accept posts to a list and handle them properly.
20
21
The main advertised address for a list should be filtered to this program,
22
through the mail wrapper.  E.g. for list `test@yourdomain.com', the `test'
23
alias would deliver to this script.
24
25
Stdin is the mail message, and argv[1] is the name of the target mailing list.
26
27
"""
28
29
import sys
30
31
import paths
32
from Mailman import mm_cfg
33
from Mailman import Utils
34
from Mailman.i18n import _
35
from Mailman.Queue.sbcache import get_switchboard
36
from Mailman.Logging.Utils import LogStdErr
37
38
LogStdErr("error", "post")
39
40
41

42
def main():
43
    # TBD: If you've configured your list or aliases so poorly as to get
44
    # either of these first two errors, there's little that can be done to
45
    # save your messages.  They will be lost.  Minimal testing of new lists
46
    # should avoid either of these problems.
47
    try:
48
        listname = sys.argv[1]
49
    except IndexError:
50
        print >> sys.stderr, _('post script got no listname.')
51
        sys.exit(1)
52
    # Make sure the list exists
53
    if not Utils.list_exists(listname):
54
        print >> sys.stderr, _('post script, list not found: %(listname)s')
55
        sys.exit(1)
56
    # Immediately queue the message for the incoming qrunner to process.  The
57
    # advantage to this approach is that messages should never get lost --
58
    # some MTAs have a hard limit to the time a filter prog can run.  Postfix
59
    # is a good example; if the limit is hit, the proc is SIGKILL'd giving us
60
    # no chance to save the message.
61
    inq = get_switchboard(mm_cfg.INQUEUE_DIR)
62
    inq.enqueue(sys.stdin.read(),
63
                listname=listname,
64
                tolist=1, _plaintext=1)
65
66
67

68
if __name__ == '__main__':
69
    main()