[Tutor] (no subject)

Kirk Bailey highprimate@howlermonkey.net
Sun, 9 Dec 2001 18:4:53 -0500


Updated cooking.
--------------------new bits-------------------------
#!/usr/local/bin/python
# Tinylist module, Pitchtime unit.
# this handles receiving and sending out postings to a list.

import sys, re, string, rfc822, smtplib

localhost = 'howlermonkey.net'	# make sure you set this to the domain YOU use!!!

pathtostuff = '/www/www.howlermonkey.net/cgi-bin/'	#please edit this to suit your system.
						# note this tells where to start looking.
						# everything is either here, ur under this
						# point in a systematic manner.
					
listname = sys.argv[1]			# we read a command line arguement to determine the list name
						# Arguement 0 is the name of the script run, 1 is the
						# first arguement
						# after that name in the command line, so if this were
						# program FOO,
						# that line would be "|/path/FOO listname"
						# and the arguement here would be 'listname'!
					
message = raw_input.lines()		# Variable 'message' is assigned the entire message
						# which is piped to the program by the alias definition
						# such as:
						# foolist:"|/pathtoprogram/programname foolist"

						# now we must determine the sender and see if they are in
						# the subscriber file!
						# still got to learn more about how this thing handles
						# parsing the incoming message, but smtp and rfc822
						# are dep sorcery on this material.
from = message["From"]

open a.file(pathtostuff + "/lists/" + listname, 'r')						
members = a.readlines()
a.close()

if string.find(members, from):					# IF the sender is in the subscriber, 
		subject = '[' + listname + ']' + subject		# then acept the submission.
		X-Mailing-List = listname + "@" + localhost	# This breaks email loops from forming.
		Reply_to = listname + "@" + localhost		# this sets the reply-to field.
		ftr = b.open(pathtostuff + "/lists/footer,"+ listname,'r')
		footer = ftr.readlines()				# reads the footer into the script
		ftr.close()
		message = message + footer				# and append it to the message.
	else
		listnamemembers = from					# we do this if the posterwas not found!
		message = ""						# clear the unauthorized posting.
		From = "From: tinylist@" + localhost + \n 	# From: tinylist@mydomain.foo !
		Subject = message + "Subject: Unauthorized posting to list" + listname + \n
		Reply_to = message + "Reply-to:postmaster@" + localhost + \n
		message = message + """
		To whom it may concern;
		
		Sorry, but as you are not a current member of """ + listname + """, 
		you may not post to it. Your recent posting has been rejected and destroyed.
		
		Feel free to contact the postmaster if there is any question.
		Any reply to this letter should go directly to the postmaster.
		
		You can also subscribe to this list if you like.
		
		Goodbye.
		
		"""

# ok, if they are not a member, THEY GET THE REPLY SHOWN ABOVE MAILED TO THEM!
# above is a blank line, DO NOT DELETE IT! it defines the end of the if then else structure!
# there is no endif or fi in python. whitespace is rather important here.
# now we send whatever message is to go out to whatever is in the recipient tupple.

for i in listnamemembers :
	helo()
	a.connect()
	a.sendmail(from_addr, to_addr, Subject, reply-to, to, X-Mailing-List, msg)
	a.quit()
	
# make sure this script runs as a TRUSTED USER- and NOT as root!!! Make sure a
# NON-priviliged user can run this script, and make sure it is owned by that identity!
----------------------------------end new bits------------------------------------------


end

In total confusion,
                   Kirk D Bailey

|----------------------------------------------------|
|           Consulting  Agent  Provecateur           |
|    Webmaster, Howlermonkey Email services Co.      |
|   Please visit us at http://www.howlermonkey.net/  |
|----------------------------------------------------|