[Tutor] latest state of the fart
Thu, 13 Dec 2001 13:01:04 -0500
Ok, this is the latest state of the art snapshot of the tinylist script.
Note that now the thing OPTIONALLY reads in the footer and random files
IF they exist, and ignores that feature if they do not.
This can be a useful feature, simply turning on and off functions by the
presence or absence of a file.
BUT I STILL NEED SOMEONE TO ADVISE ME RE rfc822 module!
# Tinylist module, Pitchtime unit.
# this handles receiving and sending out postings to a list.
import sys, re, string, rfc822, smtplib, os.path
localhost = 'howlermonkey.net' # make sure you set this to the domain
# next line declares the path to stuff. DEFINE IT
pathtostuff = '/www/www.howlermonkey.net/cgi-bin/' # to the cgi-bin for
your web dir with
# a trailing '/' as this example shows!
# note this tells where to start looking.
# everything is either here, or under this
# point in '/lists' dir.
listname = sys.argv # 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
# 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 deep sorcery on this material.
from = message["From"] # we must dig out the 'from: ' field and read
# Note we already know who it is TO - 'listname' !
# Remember, the mail ssytem fed it here with a command
# line arguement, after sorting it out to a known identity,
# so the list's defining alias contains that info.
def gangstrip(str): # ok, everybody STRIP! STR is a list variable
index = 0 # We want to strip off all leading and
while index<len(str) # trailing whitespace characters
str[index]=string.strip(str[index]) # in each element in the list.
open a.file(pathtostuff + "/lists/" + listname, 'r')
members = a.readlines() # we build a list of all the members of the
a.close() # and close the file
# then we look to see if that FROM exists in the membership.
gangstrip(members) # strip all leading and trailing whitespace
# from each element in the list 'members'.
if from in members : # IF the sender is in the subscriber file,
subject = '[' + listname + ']' + subject # then acept the
Reply_to = listname + "@" + localhost # this sets the reply-to
X-Loop = "X-Loop: " + listname + "@" + localhost # This breaks email
loops from forming
if os.path.exists("./lists/"+listname): #if there is a footer file,
ftr = b.open(pathtostuff + "/lists/" + listname + ".footer",'r') #
read the footer file
footer = ftr.readlines() # reads the footer into the variable
ftr.close() # close that file,
message = message + footer + CRLF # and append it to the message.
f1=open("./lists/"+listname+".random",'r') # Open the random footer
randomline=gangstrip(f1.readlines()) # load the contents of the
f1.close() #and close the file
message = message + randomline + CRLF # add the random element to the
else # BUT IF THEY ARE NOT SUBSCRIBED...
listnamemembers = from # put their addres as the only recipient
message = "" # clear the mesage.
From = "From: tinylist@" + localhost + \n # From:
Subject = "Subject: Unauthorized posting to list" + listname + \n
Reply_to = "Reply-to:postmaster@" + localhost + \n # no comments
X-Loop = "X-Loop: postmaster@" + localhost # This breaks email loops
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
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.
# ABOVE IS 1 BLANK LINE, DO NOT DELETE IT!
# there cannot be comments in those line # # above
this one, or they would be part
# of the triplequoted string!
# ok, if they are not a member, THEY GET
# THE REPLY SHOWN ABOVE MAILED TO THEM!
# (Maybe we could read a stock answer from a file?)
# there is no endif or fi in python.
# whitespace and tabulation therefore
# is rather important here.
# now we send whatever message is to go out to
# whatever is in the recipient tupple.
server = smtplib.SMTP('localhost') # setup for a smtp run.
# helo(localhost) # open a connection to the smtp server, possibly
# so it is commented out. If all else fails, use it.
server.connect() # and log in to the thing as the identity this
script runs as.
for to_addr in listnamemembers : # for each address in the list
server.sendmail(from_addr, to_addr, Subject, reply-to, to, X-Loop, msg)
# send a envlope and msg!
server.quit() # then close the connection.
# make sure this script runs as a TRUSTED USER-
# and NOT as root!!! Make sure that a
# NON-priviliged user can run this script,
# and make sure it is owned by that identity!
# this list is devloped by THE OLD FART and a fine bunch of
# dingleberrys at www.tinylist.org where you can hop on the
# bandwagon at your convience.
# We have lists there, which onlyu seems right somehow.
# tinylist-users - discussion for all aspects of using tinylist;
# tinylist-chat - for all intrested in tl, lists, python, email: a
# tinylist-devlopers - discussion of new versions, features,
# evil-humnor - sick, raunchy, crusty, cynical, depraved, deprived
humor? OVER HERE!
-Kirk D Bailey (C)2001
Addme! icq #27840081
Within the sweep of his sword, Each man is an Ubar.