1 #!/usr/bin/env python2.4
9 print "Content-type: text/html"
12 from dispatch_email import *
14 cgilog = logging.getLogger("cgi")
15 cgilog.addHandler(logging_handler())
16 cgilog.setLevel(logging.DEBUG)
18 PATH_INFO = os.environ.get("PATH_INFO", "")
19 cgilog.debug("Request %s", PATH_INFO)
21 def validate_email(email):
22 """validate email address
23 - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65215
25 EMAIL_RE = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
26 if not(len(email) > 7 and re.match(EMAIL_RE, email)):
27 raise UserError, "Not a valid email address"
30 print "<title>dailyzen</title>"
31 print '<link rel="stylesheet" type="text/css" href="http://nearfar.org/paste.css" />'
33 print "<h3 style='text-align: center'>%s</h3>" % msg
34 print "<p style='text-align: center'>Return to <a href='%s'>dailyzen</></p>" % WWW_URL
37 if PATH_INFO == "/subscribe":
38 form = cgi.FieldStorage()
40 email = form["email"].value
46 if email.endswith("@example.com"):
47 raise UserError, "I need YOUR email"
51 page_done("To verify your email address, please follow the link sent to you by email.")
53 elif PATH_INFO.startswith("/verify"):
54 args = PATH_INFO[ len("/verify/") : ]
55 email, id = args.split(",")
56 validate_user(email, id)
57 page_done("You are now subscribed. Welcome. :)")
59 elif PATH_INFO.startswith("/unsubscribe"):
60 args = PATH_INFO[ len("/unsubscribe/") : ]
61 email, id = args.split(",")
62 delete_user(email, id)
63 page_done("You are unsubscribed. See ya again.")
65 elif PATH_INFO == "/send_to_all":
66 user_agent = os.environ.get("HTTP_USER_AGENT")
67 cgilog.info("/send_to_all requested by agent: [%s]", user_agent)
68 if user_agent.startswith("WEBCRON"):
72 cgilog.warn("/send_to_all NOT requested by webcron, but [%s]", user_agent)
76 raise UserError, "Invalid request: %s" % PATH_INFO
79 cgilog.error("UserError: %s", e)
80 page_done("Error: %s" % e)