[Tutor] Guess what I found!
Kirk Bailey
deliberatus@my995internet.com
Sat, 08 Dec 2001 16:16:35 -0500
Lookee! A python mail list manager! Free for use!
LOOK OUT FOR WORD WRAP PROBLEMS!!!
---------------------------start quote-----------------------------
#!/bin/python
# MailList is copyright (c) 2000 of Programmed Integration
# You may use this code in any way you see fit, but please
# let use know where it is being used. If you make any changes to
# the source code, please send us a copy so we can incorporate
# the changes in future releases. If you have any other comments
# please feel free to contact us at support@programmedintegration.com
# MailList version 1.0.0 22 August 2000
import sys
sys.path.append('/lib/python1.5') # My ISP requires this to
correctly locate Python Modules
import cgi, re, string # Import all the required
modules
try:
useHead=open("head.txt", "r") # Open the HTML header file
useFoot=open("foot.txt", "r") # Open the HTML footer file
ContentLine="Content-type: text/html" # Standard content type for
HTML files
useform=cgi.FieldStorage() # Assign all variables on web
form to UseForm variable
email= useform["email"].value # Assign from form to local
variables. Proposed email address
email2= useform["email2"].value # ditto, verified email
address
password= useform["password"].value # ditto, proposed password
password2= useform["password2"].value # ditto, verified password
action=useform["action"].value # ditto, action, i.e
subscribe or unsubscribe
try:
optout=useform["optout"].value # ditto, optout clause, yes
or no
except: # I've enclosed this in a
try/except
optout='no' # as if the checkbox is
unchecked, nothing
# was returned. This way
'no' is returned
print ContentLine # Print standard content line
print # Needs a blank line
following
print useHead.read() # Print HTML header
if email!=email2: # Checks to see if two
entered email addresses match
print "Email addresses do not match" # If no match print error
sys.exit(0) # Exit script with error 0
elif password!=password2: # Checks to see if two
entered passwords match
print "Passwords do not match" # If no match print error
sys.exit(0) # Exit script with error 0
useMailList=open("maillist.txt", "r") # Open mailling list
memMailList=useMailList.readlines() # Assign mailing list to
internal list
useMailList.close # Close mailing list
found=0 # Create found variable
counter=0 # Create counter variable
for UseLine in memMailList: # For loop until list end is
reached
if string.find(string.upper(UseLine), string.upper(email))!=-1: #
Checks to see if email is in mailing list
found=1 # If yes, found = true (1)
UseSplit=re.split(',',UseLine) # Create list of found line
and delimit with a comma
break # Exit for loop
counter=counter+1 # If not found incrememnt
count and repeat
if not found: # If email address not found
in mailing list
if action=="unsubscribe": # And if action is
unsubscribe
print "Email address <B>"+email+"</B> does not exist on our
database" # Print error message
else: # Otherwise
lineuse=email+","+password+','+optout+"\n" # Form valid mailing
list entry
memMailList.append(lineuse) # Add to internal list
print "Subscription for <B>"+email+"</B> successful<P>" #Print
success to HTML
print "Many thanks for subscribing. Please be sure to make a
note"
print "of the email address you subscribed with. You will
only"
print "be able to unsubscribe if you use that email address."
else: # Otherwise if email address
not found in mailing list
if action=="unsubscribe": # And if actions is
unsubscribe
if password==UseSplit[1]: # If password is valid
memMailList[counter]='' # Empty internal mailing list
entry
print "Unsubscription for <B>"+email+"</B> successful" #
Print unsubscribe success to HTML
else: # Otherwise if password not
valid
print "Unsubscription for <B>"+email+"</B> unsuccessful.
Password is invalid" # Print unsubscribe unsuccessful to HTML
print "Remember that passwords are case sensitive. i.e.
password is not the same as PassWord"
else: # Otherwise if subscribe
print "Subscription for <B>"+email+"</B> already exists" #
Print subscription already exists to HTML
finally: # Finally
useMailList=open("maillist.txt", "w") # Open Mailing List for
writing
useMailList.writelines(memMailList) # Copy internal mailing list
to file
useMailList.close # Close mailing list
print useFoot.read() # Print HTML footer
useHead.close; # Close HTML header
useFoot.close; # Close HTML footer
------------- ----------------end
quote----------------------------------
This also referrs to a few other files.
1 of 3
-------------------------head.txt---------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Programmed Integration - Mailing List</title>
</head>
<body BGCOLOR="BLACK" text="#FFFFFF" link="#66CCFF" vlink="#66CC99"
alink="#FF6666">
<font face="arial">
<TABLE width=100%>
<TR><TD BGCOLOR="#fe4221" WIDTH=100%><CENTER><b>Mailing
List</b></CENTER></TD></TR>
</TABLE>
<P>
<small>
-----------------------------end---------------------------
2 of 3
----------------------foot.txt-------------------------
</small>
</FONT>
</body>
</html>
-------------------end-----------------------
3 of 3
-------------------maillist.htm---------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Programmed Integration - Delphi</title>
<META http-equiv="content-type" content="text/html; charset=iso-8859-1">
<META NAME="GENERATOR" CONTENT="PI-Premote:
www.programmedintegration.com">
<META NAME="description" content="Bespoke software solutions and
Internet websites. Freeware and commercial software. Free PIPL MP3
player. Delphi and Python computer languages">
<META NAME="keywords" content="delphi, consultancy, programming,
bespoke, web, design, MP3, components">
<META NAME="robots" CONTENT="ALL">
<META NAME="revisit-after" CONTENT="30 days">
</head>
<body BGCOLOR="BLACK" text="#FFFFFF" link="#66CCFF" vlink="#66CC99"
alink="#FF6666">
<font face="arial">
<TABLE width=100%>
<TR><TD BGCOLOR="#fe4221" WIDTH=100%><CENTER><b>Mailing
List</b></CENTER></TD></TR>
</TABLE>
<P>
<small>
Over the period of the year we aim to send out bulletins of what we are
up to and any other news that you might find of interest. If you would
like to subscribe to this list, please fill in your details below. We
apologise for the double verification of email and password, but we find
it prevents a lot of rogue subscriptions. We look forward to having you
on our list.<P>
<CENTER>
<form action="cgibin/maillist.py" method="POST">
Your email address (eg. yourname@mydomain.com):<BR>
<input name="email" type="text" value="" SIZE=40 MAXLENGTH=80><BR>
Please re-enter your email address:<BR>
<input name="email2" type="text" value="" SIZE=40 MAXLENGTH=80><P>
<TABLE>
<TR>
<TD ALIGN=RIGHT><small>Please enter a password: </small></TD>
<TD><input name="password" type="text" value="" SIZE=10
MAXLENGTH=20></TD></TR>
<TR><TD ALIGN=RIGHT><small>Please re-enter your password: </small></TD>
<TD><input name="password2" type="text" value="" SIZE=10
MAXLENGTH=20></TD></TR>
</TABLE>
<P>
Subscribe <input name="action" type="radio" value="subscribe" checked>
UnSubscribe <input name="action" type="radio" value="unsubscribe">
<P ALIGN=LEFT>
Programmed Integration and organisations with whom we have a close
working relationship, may from time to time write to you about specific
services, products and offers which could be of interest. Please
unselect the checkbox if you would prefer not to receive such mailings.
<input type="checkbox" name="optout" value="yes" checked></P>
<P>
<INPUT TYPE="submit" VALUE="Process">
</form>
</CENTER>
</small>
</FONT>
</body>
</html>
--------------------------------end-------------------------------
--
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/