~ubuntu-branches/ubuntu/hoary/mailman/hoary-security

« back to all changes in this revision

Viewing changes to scripts/post

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-10-11 02:02:43 UTC
  • Revision ID: james.westby@ubuntu.com-20041011020243-ukiishnhlkmsoh21
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- python -*-
 
2
#
 
3
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
 
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 
 
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
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()