[Tutor] further ignorant babbling
Tue, 11 Dec 2001 02:03:01 -0500
Well, I just don't know when to quit. Further progress in the script,
and a minor refinement in the sending of the messages, still sends each
one in it's own envlope, but this way it only opens the connection once,
and closes it once, saving a little time.
And it set's the X-Mail-Loop header to prevent mail loops. Not only with
the list traffic, but in the reject reply, so we don't get into a sort
of autoreply war- important concept, that.
-------------------begin cheezy programming--------------------------
# 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
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 # 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
# 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()
if string.find(members, from): # IF the sender is in the subscriber,
subject = '[' + listname + ']' + subject # then acept the submission.
Reply_to = listname + "@" + localhost # this sets the reply-to field.
X-Loop = "X-Loop: " + listname + "@" + localhost # This breaks email
loops from form
ftr = b.open(pathtostuff + "/lists/" + listname + ".footer",'r') #
read the footer
footer = ftr.readlines() # reads the footer into the variable
ftr.close() # close that file,
message = message + footer # and append it to the message.
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.
# there cannot be comments in those line above this one,
# or they would be part of the string!
# ok, if they are not a member, THEY GET THE REPLY SHOWN ABOVE MAILED TO
# above is a blank line, DO NOT DELETE IT! *IMPORTANT!*
# 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
helo() # open a connection to the smtp server,
a.connect() # and log in to the thing as the identity this script
for i in listnamemembers : # for each address in the list
a.sendmail(from_addr, to_addr, Subject, reply-to, to, X-Loop, msg)
#send a envlope!
a.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!
-----------------------end aged cheeze------------------------------
As for path and naming conventions, I am leaning to using a
"./lists/listname.filetype" approach, to reduce the creation of dir's.
formulating filenames is apparently pretty simple stuf in python, so
let's keep simple simple.
For some reason, I keep thinking of FORTH. Only thing I ever saw that's
more easily extensible than python. EVERYTHING is an extension of forth!
There are no actual forth programs other than forth itself. There are
only new words in it's vocabulary.
Here is helloworld in forth:
:helloworld ."Hello world!" ;
If you type that in a computer running forth, it is now part of the
language, compiled as soon as it registered the CR from the keyboard. It
is now compiled into the dictionary. When you issue a command, it
interpets it, looking it up in the dictionary of runtime addresses.
Factoring is very important in forth, to get it's wonderful power of
compactness. programs in forth are on average only 1/2.5 the size of the
same thing in assembly.
No, I am not kidding.
Stack oriented, threaded, FORTH is writen top down, composed and
compiled bottom up, is a interpeting compiling language with Reverse
Polish Notation, is stack oriented, and includes all existant and not
yet existant assembly languages as subsets of the language, along with
the kitchen sink and BIG RED STRAPS.
Leo Brodie wrote that it is best for beginning programmers to learn
FORTH, as experienced ones tend to experience stress trauma from it's
odd and unique nature. It is usually used for controllers and other
imbedded computers, and also in many workstations, as it lets a minimum
of electronics be VERY smart, so a lot of unix workstations run small
cpu's nd a flavor of forth, making a tiny thing mildly smart, with a
minimum of silicon.
END OF RANT
-Kirk D Bailey (C)2001
Addme! icq #27840081
Within the sweep of his sword, Each man is an Ubar.