[Tutor] TinyList post time module update.

Kirk Bailey deliberatus@my995internet.com
Sat, 15 Dec 2001 20:40:40 -0500


Here is the latest spasam.

Anyone want to subscribe to a list for this project?

mailto:minorfish@howlermonkey.net?Subject=subscribe%20listtalk

=================================================================================================================
#!/usr/local/bin/python
# Tinylist MLM Pitchtime module.
# COPYRIGHT 2002 Kirk D Bailey

# And made available under the GNU GPL.
###################################################################################
# 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.     #
# Also, the GNU GPL may be viewed online at
http://www.gnu.org/licenses/gpl.html  #
###################################################################################
#
#   "The tyrant's foe, the people's friend, a free press." -Dr Benjamin
Franklin.
#
##################################################################
# Python can be studied and aquired at http://www.python.org/ !!!
##################################################################
#
# This module only handles receiving and sending out postings to a list.
# management of membership is handled by the favored command module
# - TLwebcommand, TLemailcommand, or both.
#
# we now import some functions from assorted libraries.

import sys, re, string, rfc822, smtplib, os.path

# someday we will collect each needed function
# and create a module just of those and distribute it
# with tinylist.

# make sure you set this to YOUR domain!
localhost = 'mydomain.foo'

# next line declares the path to stuff. DEFINE IT for *YOUR* server!
path = '/www/www.howlermonkey.net/cgi-bin'
# to the cgi-bin for your web dir,
# with no trailing '/'!
# note this tells TL where to start looking.
# everything is either here, or under this
# point in '/lists/' dir, mostly in '/lists/'.
                                        
# we read a command line arguement to determine the list name
listname = sys.argv[1]
# Arguement 0 is the name of the script run, 1 is the
# first arguement after that name in the command line,
# so this tells us the name of the email identity being addressed-
listname!

                                        
# variable 'incoming' receives the entire incoming message
# which is piped to the script on <stdin> which this reads by the alias
# such as:
#         foolist:"|/pathtoprogram/programname foolist"

#incoming = raw_input.lines()
#I commented this out for the moment to see if this is better

# this block will contain the rfc822 decoding code when we get it
finished.
# Using rfc822.py, we digest the message and make parts available to the
program.
#message = rfc822.message(incoming)
incoming = rfc822.Message(sys.stdin)
pass
pass
pass
# end of dummycode. Hereafter we act as if it is decoded.
# The information is in the dictionary 'message', each item keyed with
the header's
# name. The BODY of that dictionary is in the string 'msg'. So are any
attachments.

sender = Message.getAddr("From")                        # we must dig
out the 'from: ' field contents
# 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.

# Strip whitespace chars off every element in the list passed to this
function.
def gangstrip(str):                                     # ok, everybody
STRIP!
        index = 0                                       # initiate
counter=0
        while index<len(str):                           # define loopp
terination
                str[index]=string.strip(str[index])     # and strip each
element.
                index=index+1                           # increase the
index pointer

# ok, let's read that membership file. it is named (listname) with no
name extension.
a.open(path + "/lists/" + listname,
'r')                                                
members = a.readlines()                                 # read all of it
in.
a.close()                                               # and close the
file

# then we look to see if that FROM exists in the membership.
# clean it up;
gangstrip(members)      # strip all leading and trailing whitespace
                                # from each element in the list
'members'.

# then we look to see if the sender is a member of the list:
if sender in members :  # IF the sender is in the subscriber file, 
        subject = '[' + listname + ']' + subject        # then accept
the submission.
        if os.path.exists(path + "/lists/" +listname +".replyto"):      
                Reply_to = "Reply-to: " + listname + "@" + localhost +
CRLF # set the  optional
        else:                                           # Reply-to:
field.
                Reply_to = ""                           # if not, this
string
                                                        # is NULL.


        XLoop = "X-Loop: " + listname + "@" + localhost # This breaks
email 
                                                        # loops from
forming
        # need to add something to detect these to STOP such posts!
        if os.path.exists(path + "/lists/" + listname + ".footer"):    
# if there is a 
                                                                       
# footer, read it!

                ftr = open(path + "/lists/" + listname + ".footer",'r')
# read the footer
                                                                       
# file
                footer = ftr.readlines()                               
# into 'footer'
                                                                       
# 
                ftr.close()                                            
# close that file,
                msg = msg + footer + CRLF                              
# and append it to 
                                                                       
# the message. 

        if os.path.exists(path + "/lists/"+listname+".random"):        
# if this list has a random 
                                                                       
# rotation file,
                f1=open("./lists/"+listname+".random",'r')             
# Open the random footer
                                                                       
# rotation file
                randomline=gangstrip(f1.readlines())                   
# load the contents of the
                                                                       
# rotation
                f1.close()                                             
# then close the file
                msg = msg + randomline + CRLF                          
# and add the random element
                                                                       
# to the footer.
                        
# this end processing for an acceptable posting. Next block handles
process for
# REJECTED postings.
                        
else:                                                           # BUT IF
THEY ARE NOT...
        listnamemembers = sender                                # put
poster address as the
                                                                #
recipient in list
                                                                #
'listnamemembers'
        msg = ""                                                # and
clear the mesage.
        From_addr = "From: tinylist@" + localhost + CRLF       
#From:tinylist@mydomain.foo!
        Subject = "Subject: Unauthorized posting to list: " + listname +
CRLF # Setsubject
        Reply_to = "Reply-to: postmaster@" + localhost + CRLF   # replys
go to thePostmaster
        XLoop = "X-Loop: postmaster@" + localhost               # This
breaks email
                                                                # loops
from
                                                                #
forming
        msg = """
                
                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.
                
                """

# ABOVE IS 1 BLANK LINE, DO NOT DELETE IT!
# BTW, that was the end of the ELSE clause from way above.
# 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 list.
server = smtplib.SMTP('localhost')      # setup for a smtp run.
# helo(localhost)                       # open a connection to the smtp
server,
                                        # possibly not needed
                                        # so it is commented out. If all
else fails,
                                        # use it.
server.connect()                        # and log in to the thing 170
                                        # as the identity this script
runs as.
for to_addr in listnamemembers :        # for each address in the list
listnamemembers,
        server.sendmail(from_addr, to_addr, Subject, reply-to, XLoop,
msg)
                                        # send envlope and msg!

                                        # don't delete the above line!
server.quit()                           # then close the connection.

# make sure this script runs as a TRUSTED USER-
# 180and NOT as root!!! You set that up in the Sendmail
# Config file (sendmail.cf).
# Make sure that a NON-priviliged user OWNS
# this script, and that it runs as that identity!
#
# The TinyList community hangs out at www.tinylist.org
# and is a pretty informal bunch of digiteratti. Come visit!
#
# We have lists there, which only seems right somehow.
# they are:
# tinylist-users - discussion for all aspects of using190 
#                  tinylist; somewhat technical.

# tinylist-chat - for all intrested in tl, lists, python,
#                 email: a broad charter! 
# tinylist-devlopers - discussion of new versions, features, 
#                      and bugchasing.
# evil-humor - sick, raunchy, crusty, cynical, depraved, 
#               deprived humor? OVER HERE!
# Fnord.
---------------------------------------------------------------------------------------------------
200


-- 
Respectfully,
             -Kirk D Bailey (C)2001
              Addme! icq #27840081
end


Within the sweep of his sword, Each man is an Ubar.

http://www.howlermonkey.net/
http://www.sacredelectron.org/