#! /usr/bin/env python # # Copyright (C) 1998 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """Accept posts to a list and handle them properly. This script is invoked via the mail wrapper. Stdin is the mail message, and argv[1] is the name of the target mailing list. If there's an argv[2], then this post was gated from news, and thus should not be re-posted to news if the list gates to a newsgroup. """ # Todo: check size of To: list < 100 # Send back why the post was rejected. import sys import paths from Mailman import MailList from Mailman import Message from Mailman import Errors from Mailman.Utils import maketext from Mailman.Logging.Utils import LogStdErr LogStdErr("error", "post") # Only let one program run at once per list. # TODO: This can fail, and should send back an error message when it does. current_list = MailList.MailList(sys.argv[1]) if len(sys.argv) > 2: current_list.tmp_prevent_gate = 1 else: current_list.tmp_prevent_gate = 0 try: prog = current_list.filter_prog if prog: import os, __main__ file = os.path.join(paths.prefix, 'filters', prog) try: execfile(file) text = __main__.mailman_text except: text = sys.stdin.read() else: text = sys.stdin.read() msg = Message.IncomingMessage(text) try: current_list.Post(msg) except Errors.MMNeedApproval, err_msg: if (current_list.dont_respond_to_post_requests or err_msg == Errors.MODERATED_LIST_MSG): # Do not send hold-for-approval notices for moderated messages. current_list.Unlock() sys.exit(0) the_sender = msg.GetSender() subj = msg.getheader('subject') if not subj: subj = '[no subject]' body = maketext( 'postheld.txt', {'list_name': current_list.real_name, 'subject' : subj, 'reason' : err_msg, }) current_list.SendTextToUser( subject = 'Mail sent to %s' % current_list.real_name, recipient = the_sender, text = body) # Let another process run. finally: current_list.Unlock()