summaryrefslogtreecommitdiff
path: root/scripts/post
blob: 964c71a750f80a6c365ed2f0591f8b095d18be01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/local/bin/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."""

__version__ = "$Revision: 547 $"

# Todo: check size of To: list < 100
# Send back why the post was rejected.

import sys

sys.path.append('/home/mailman/mailman/modules')

import maillist, mm_message, mm_err, mm_cfg, mm_utils

try:
    sys.stderr = mm_utils.StampedLogger("error", label = 'post',
                                        manual_reprime=1, nofail=0)
except IOError:
    pass                        # Oh well - SOL on redirect, errors show thru.

# 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])

try:
    prog = current_list.filter_prog
    if prog:
	import os, __main__
	file = os.path.join('/home/mailman/mailman/filters', prog)
	try:
	    execfile(file)
	    text = __main__.mailman_text
	except:
	    text = sys.stdin.read()
    else:
	text = sys.stdin.read()
    msg = mm_message.IncomingMessage(text)

    try:
	current_list.Post(msg)
    except mm_err.MMNeedApproval, err_msg:
	if (current_list.dont_respond_to_post_requests
            or err_msg == mm_err.MODERATED_LIST_MSG
            or err_msg == mm_err.IMPLICIT_DEST_MSG
            or err_msg == mm_err.SUSPICIOUS_HEADER_MSG
            or err_msg == mm_err.FORBIDDEN_SENDER_MSG):
            # Do not send hold-for-approval notices for moderated messages
	    # or potential spam.
	    sys.exit(0)
            
	the_sender = msg.GetSender()
	subj = msg.getheader('subject')
	if not subj:
	    subj = '[no subject]'
	body = '''
Your mail to '%s' with the subject:

%s

Is being held until the list moderator can review it for approval.

The reason it is being held:

        %s

Either the message will get posted to the list, or you will receive 
notification of the moderator's decison.
''' % (current_list.real_name, subj, 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()