From: richard Date: Thu, 1 Nov 2001 22:04:37 +0000 (+0000) Subject: Started work on supporting a pop3-fetching server X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0fb16b927f803df0e6be67702ffd69e89bcc769f;p=roundup.git Started work on supporting a pop3-fetching server Fixed bugs: . bug #477104 ] HTML tag error in roundup-server . bug #477107 ] HTTP header problem git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@354 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 80dad61..0943d95 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,9 @@ Fixed: . Fixed some URL issues in roundup.cgi, again thanks Juergen Hermann. . bug #475347 ] WindowsError still not caught (patch from Juergen Hermann) . bug #474749 ] indentations lost + . bug #477104 ] HTML tag error in roundup-server + . bug #477107 ] HTTP header problem + 2001-10-23 - 0.3.0 pre 3 Feature: diff --git a/cgi-bin/roundup.cgi b/cgi-bin/roundup.cgi index c8b1030..ad92274 100755 --- a/cgi-bin/roundup.cgi +++ b/cgi-bin/roundup.cgi @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup.cgi,v 1.15 2001-10-29 23:55:44 richard Exp $ +# $Id: roundup.cgi,v 1.16 2001-11-01 22:04:37 richard Exp $ # python version check import sys @@ -59,6 +59,18 @@ except: traceback.print_exc(None, s) print cgi.escape(s.getvalue()), "" +class RequestWrapper: + '''Used to make the CGI server look like a BaseHTTPRequestHandler + ''' + def __init__(self, wfile): + self.wfile = wfile + def send_response(self, code): + self.wfile.write('Status: %s\r\n'%code) + def send_header(self, keyword, value): + self.wfile.write("%s: %s\r\n" % (keyword, value)) + def end_headers(self, keyword, value): + self.wfile.write("\r\n") + def main(out, err): import os, string import roundup.instance @@ -66,26 +78,30 @@ def main(out, err): instance = path[1] os.environ['INSTANCE_NAME'] = instance os.environ['PATH_INFO'] = string.join(path[2:], '/') + request = RequestWrapper(out) if ROUNDUP_INSTANCE_HOMES.has_key(instance): instance_home = ROUNDUP_INSTANCE_HOMES[instance] instance = roundup.instance.open(instance_home) from roundup import cgi_client - client = instance.Client(instance, out, os.environ) + client = instance.Client(instance, request, os.environ) try: client.main() except cgi_client.Unauthorised: - out.write('Content-Type: text/html\n') - out.write('Status: 403\n\n') + request.send_response(403) + request.send_header('Content-Type', 'text/html') + request.end_headers() out.write('Unauthorised') except cgi_client.NotFound: - out.write('Content-Type: text/html\n') - out.write('Status: 404\n\n') + request.send_response(404) + request.send_header('Content-Type', 'text/html') + request.end_headers() out.write('Not found: %s'%client.path) else: import urllib - w = out.write - w("Content-Type: text/html\n\n") - w('Roundup instances index\n') + request.send_response(200) + request.send_header('Content-Type', 'text/html') + w = request.wfile.write + w('Roundup instances index\n') w('

Roundup instances index

    \n') for instance in ROUNDUP_INSTANCE_HOMES.keys(): w('
  1. %s\n'%( @@ -111,6 +127,9 @@ sys.stdout, sys.stderr = out, err # # $Log: not supported by cvs2svn $ +# Revision 1.15 2001/10/29 23:55:44 richard +# Fix to CGI top-level index (thanks Juergen Hermann) +# # Revision 1.14 2001/10/27 00:22:35 richard # Fixed some URL issues in roundup.cgi, again thanks Juergen Hermann. # diff --git a/roundup-mailgw b/roundup-mailgw index 5ab60a6..8e5e775 100755 --- a/roundup-mailgw +++ b/roundup-mailgw @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup-mailgw,v 1.7 2001-08-07 00:24:42 richard Exp $ +# $Id: roundup-mailgw,v 1.8 2001-11-01 22:04:37 richard Exp $ import sys if int(sys.version[0]) < 2: @@ -37,13 +37,16 @@ if not instance_home: import roundup.instance instance = roundup.instance.open(instance_home) -# invokde the mail handler +# invoke the mail handler db = instance.open('admin') handler = instance.MailGW(db) handler.main(sys.stdin) # # $Log: not supported by cvs2svn $ +# Revision 1.7 2001/08/07 00:24:42 richard +# stupid typo +# # Revision 1.6 2001/08/07 00:15:51 richard # Added the copyright/license notice to (nearly) all files at request of # Bizar Software. diff --git a/roundup-server b/roundup-server index c8b83cd..de71d67 100755 --- a/roundup-server +++ b/roundup-server @@ -20,7 +20,7 @@ Based on CGIHTTPServer in the Python library. -$Id: roundup-server,v 1.17 2001-10-29 23:55:44 richard Exp $ +$Id: roundup-server,v 1.18 2001-11-01 22:04:37 richard Exp $ """ import sys @@ -31,7 +31,6 @@ if int(sys.version[0]) < 2: import os, urllib, StringIO, traceback, cgi, binascii, string, getopt, imp import BaseHTTPServer -import SimpleHTTPServer # Roundup modules of use here from roundup import cgitb, cgi_client @@ -63,13 +62,9 @@ ROUNDUP_USER = None # -class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ROUNDUP_INSTANCE_HOMES = ROUNDUP_INSTANCE_HOMES ROUNDUP_USER = ROUNDUP_USER - def send_head(self): - """Version of send_head that support CGI scripts""" - # TODO: actually do the HEAD ... - return self.run_cgi() def run_cgi(self): """ Execute the CGI command. Wrap an innner call in an error @@ -100,12 +95,14 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.wfile.write("\n") sys.stdin = save_stdin + do_GET = do_POST = do_HEAD = send_head = run_cgi + def index(self): ''' Print up an index of the available instances ''' w = self.wfile.write w("Content-Type: text/html\n\n") - w('Roundup instances index\n') + w('Roundup instances index\n') w('

    Roundup instances index

      \n') for instance in self.ROUNDUP_INSTANCE_HOMES.keys(): w('
    1. %s\n'%(urllib.quote(instance), @@ -180,11 +177,9 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.send_response(200, "Script output follows") # do the roundup thang - client = instance.Client(instance, self.wfile, env) + client = instance.Client(instance, self, env) client.main() - do_POST = run_cgi - def usage(message=''): if message: message = 'Error: %s\n'%message print '''%sUsage: @@ -261,6 +256,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.17 2001/10/29 23:55:44 richard +# Fix to CGI top-level index (thanks Juergen Hermann) +# # Revision 1.16 2001/10/27 00:12:21 richard # Fixed roundup-server for windows, thanks Juergen Hermann. # diff --git a/roundup/cgi_client.py b/roundup/cgi_client.py index dbb7fc7..c04321e 100644 --- a/roundup/cgi_client.py +++ b/roundup/cgi_client.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: cgi_client.py,v 1.44 2001-10-28 23:03:08 richard Exp $ +# $Id: cgi_client.py,v 1.45 2001-11-01 22:04:37 richard Exp $ import os, cgi, pprint, StringIO, urlparse, re, traceback, mimetypes import base64, Cookie, time @@ -52,14 +52,13 @@ class Client: ANONYMOUS_ACCESS = 'deny' # one of 'deny', 'allow' ANONYMOUS_REGISTER = 'deny' # one of 'deny', 'allow' - def __init__(self, instance, out, env): + def __init__(self, instance, request, env): self.instance = instance - self.out = out + self.request = request self.env = env self.path = env['PATH_INFO'] self.split_path = self.path.split('/') - self.headers_done = 0 self.form = cgi.FieldStorage(environ=env) self.headers_done = 0 self.debug = 0 @@ -68,11 +67,14 @@ class Client: return self.db.user.lookup(self.user) def header(self, headers={'Content-Type':'text/html'}): + '''Put up the appropriate header. + ''' if not headers.has_key('Content-Type'): headers['Content-Type'] = 'text/html' + self.request.send_response(200) for entry in headers.items(): - self.out.write('%s: %s\n'%entry) - self.out.write('\n') + self.request.send_header(*entry) + self.request.end_headers() self.headers_done = 1 def pagehead(self, title, message=None): @@ -152,7 +154,7 @@ class Client: def write(self, content): if not self.headers_done: self.header() - self.out.write(content) + self.request.wfile.write(content) def index_arg(self, arg): ''' handle the args to index - they might be a list from the form @@ -874,6 +876,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0): # # $Log: not supported by cvs2svn $ +# Revision 1.44 2001/10/28 23:03:08 richard +# Added more useful header to the classic schema. +# # Revision 1.43 2001/10/24 00:01:42 richard # More fixes to lockout logic. # diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 72b636f..b430f05 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -72,7 +72,7 @@ are calling the create() method to create a new node). If an auditor raises an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.27 2001-10-30 11:26:10 richard Exp $ +$Id: mailgw.py,v 1.28 2001-11-01 22:04:37 richard Exp $ ''' @@ -116,14 +116,18 @@ class MailGW: def main(self, fp): ''' fp - the file from which to read the Message. + ''' + self.handle_Message(Message(fp)) + + def handle_Message(self, message): + '''Handle an RFC822 Message - Read a message from fp and then call handle_message() with the - result. This method's job is to make that call and handle any + Hanle the Message object by calling handle_message() and then cope + with any errors raised by handle_message. + This method's job is to make that call and handle any errors in a sane manner. It should be replaced if you wish to handle errors in a different manner. ''' - # ok, figure the subject, author, recipients and content-type - message = Message(fp) m = [] try: self.handle_message(message) @@ -445,6 +449,9 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), # # $Log: not supported by cvs2svn $ +# Revision 1.27 2001/10/30 11:26:10 richard +# Case-insensitive match for ISSUE_TRACKER_EMAIL in address in e-mail. +# # Revision 1.26 2001/10/30 00:54:45 richard # Features: # . #467129 ] Lossage when username=e-mail-address