#!/usr/bin/python

PERSON="Richard Kiss"
PERSON_EMAIL="him@richardkiss.com"

import cgi
import os

form = cgi.FieldStorage()

print "Content-type: text/html" # HTML is following
print                           # blank line, end of headers

def emailTheAddress(recipient):
	print '''
<html><head><title>Mail sent</title></head>
<body>The e-mail address for %s has been sent to %s</body></html>''' % (PERSON, recipient)

	# Import smtplib for the actual sending function
	import smtplib

	# Create a text/plain message
	msg = "Subject: E-mail address for %s\nFrom: %s <%s>\nTo: %s\n%s can be reached by sending e-mail to <%s>." % (PERSON, PERSON, PERSON_EMAIL, recipient, PERSON, PERSON_EMAIL)

	# Send the message via our own SMTP server, but don't include the
	# envelope header.
	s = smtplib.SMTP()
	s.connect()
	s.sendmail(PERSON_EMAIL, [recipient, PERSON_EMAIL], msg)
	s.close()

def askForAddress():
	print '''
<html><head><title>E-mail Address Request</title></head>
<body>In an effort to reduce unsolicited e-mail ("spam"), you must enter your e-mail address before %s's e-mail address is revealed.
<p>Enter an e-mail address to which you would like this information delivered.
<form>Enter your e-mail address:
<input type="text" name="email" size="40" maxlength="255">
<input type="submit" name="submit" value="Submit">
</form></body></html>
	''' % PERSON

if form.has_key("email"):
    emailTheAddress(form["email"].value)
else:
    askForAddress()
