Skip to content

Commit f7c4083

Browse files
author
Richard Jones
committed
Started work on supporting a pop3-fetching server
Fixed bugs: . [SF#477104] HTML tag error in roundup-server . [SF#477107] HTTP header problem
1 parent 1052fec commit f7c4083

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Fixed:
1717
. Fixed some URL issues in roundup.cgi, again thanks Juergen Hermann.
1818
. bug #475347 ] WindowsError still not caught (patch from Juergen Hermann)
1919
. bug #474749 ] indentations lost
20+
. bug #477104 ] HTML tag error in roundup-server
21+
. bug #477107 ] HTTP header problem
22+
2023

2124
2001-10-23 - 0.3.0 pre 3
2225
Feature:

cgi-bin/roundup.cgi

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup.cgi,v 1.15 2001-10-29 23:55:44 richard Exp $
19+
# $Id: roundup.cgi,v 1.16 2001-11-01 22:04:37 richard Exp $
2020

2121
# python version check
2222
import sys
@@ -59,33 +59,49 @@ except:
5959
traceback.print_exc(None, s)
6060
print cgi.escape(s.getvalue()), "</pre>"
6161

62+
class RequestWrapper:
63+
'''Used to make the CGI server look like a BaseHTTPRequestHandler
64+
'''
65+
def __init__(self, wfile):
66+
self.wfile = wfile
67+
def send_response(self, code):
68+
self.wfile.write('Status: %s\r\n'%code)
69+
def send_header(self, keyword, value):
70+
self.wfile.write("%s: %s\r\n" % (keyword, value))
71+
def end_headers(self, keyword, value):
72+
self.wfile.write("\r\n")
73+
6274
def main(out, err):
6375
import os, string
6476
import roundup.instance
6577
path = string.split(os.environ.get('PATH_INFO', '/'), '/')
6678
instance = path[1]
6779
os.environ['INSTANCE_NAME'] = instance
6880
os.environ['PATH_INFO'] = string.join(path[2:], '/')
81+
request = RequestWrapper(out)
6982
if ROUNDUP_INSTANCE_HOMES.has_key(instance):
7083
instance_home = ROUNDUP_INSTANCE_HOMES[instance]
7184
instance = roundup.instance.open(instance_home)
7285
from roundup import cgi_client
73-
client = instance.Client(instance, out, os.environ)
86+
client = instance.Client(instance, request, os.environ)
7487
try:
7588
client.main()
7689
except cgi_client.Unauthorised:
77-
out.write('Content-Type: text/html\n')
78-
out.write('Status: 403\n\n')
90+
request.send_response(403)
91+
request.send_header('Content-Type', 'text/html')
92+
request.end_headers()
7993
out.write('Unauthorised')
8094
except cgi_client.NotFound:
81-
out.write('Content-Type: text/html\n')
82-
out.write('Status: 404\n\n')
95+
request.send_response(404)
96+
request.send_header('Content-Type', 'text/html')
97+
request.end_headers()
8398
out.write('Not found: %s'%client.path)
8499
else:
85100
import urllib
86-
w = out.write
87-
w("Content-Type: text/html\n\n")
88-
w('<html><head><title>Roundup instances index</title><head>\n')
101+
request.send_response(200)
102+
request.send_header('Content-Type', 'text/html')
103+
w = request.wfile.write
104+
w('<html><head><title>Roundup instances index</title></head>\n')
89105
w('<body><h1>Roundup instances index</h1><ol>\n')
90106
for instance in ROUNDUP_INSTANCE_HOMES.keys():
91107
w('<li><a href="%s/%s/index">%s</a>\n'%(
@@ -111,6 +127,9 @@ sys.stdout, sys.stderr = out, err
111127

112128
#
113129
# $Log: not supported by cvs2svn $
130+
# Revision 1.15 2001/10/29 23:55:44 richard
131+
# Fix to CGI top-level index (thanks Juergen Hermann)
132+
#
114133
# Revision 1.14 2001/10/27 00:22:35 richard
115134
# Fixed some URL issues in roundup.cgi, again thanks Juergen Hermann.
116135
#

roundup-mailgw

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup-mailgw,v 1.7 2001-08-07 00:24:42 richard Exp $
19+
# $Id: roundup-mailgw,v 1.8 2001-11-01 22:04:37 richard Exp $
2020

2121
import sys
2222
if int(sys.version[0]) < 2:
@@ -37,13 +37,16 @@ if not instance_home:
3737
import roundup.instance
3838
instance = roundup.instance.open(instance_home)
3939

40-
# invokde the mail handler
40+
# invoke the mail handler
4141
db = instance.open('admin')
4242
handler = instance.MailGW(db)
4343
handler.main(sys.stdin)
4444

4545
#
4646
# $Log: not supported by cvs2svn $
47+
# Revision 1.7 2001/08/07 00:24:42 richard
48+
# stupid typo
49+
#
4750
# Revision 1.6 2001/08/07 00:15:51 richard
4851
# Added the copyright/license notice to (nearly) all files at request of
4952
# Bizar Software.

roundup-server

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
Based on CGIHTTPServer in the Python library.
2222
23-
$Id: roundup-server,v 1.17 2001-10-29 23:55:44 richard Exp $
23+
$Id: roundup-server,v 1.18 2001-11-01 22:04:37 richard Exp $
2424
2525
"""
2626
import sys
@@ -31,7 +31,6 @@ if int(sys.version[0]) < 2:
3131

3232
import os, urllib, StringIO, traceback, cgi, binascii, string, getopt, imp
3333
import BaseHTTPServer
34-
import SimpleHTTPServer
3534

3635
# Roundup modules of use here
3736
from roundup import cgitb, cgi_client
@@ -63,13 +62,9 @@ ROUNDUP_USER = None
6362
#
6463

6564

66-
class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
65+
class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
6766
ROUNDUP_INSTANCE_HOMES = ROUNDUP_INSTANCE_HOMES
6867
ROUNDUP_USER = ROUNDUP_USER
69-
def send_head(self):
70-
"""Version of send_head that support CGI scripts"""
71-
# TODO: actually do the HEAD ...
72-
return self.run_cgi()
7368

7469
def run_cgi(self):
7570
""" Execute the CGI command. Wrap an innner call in an error
@@ -100,12 +95,14 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
10095
self.wfile.write("</pre>\n")
10196
sys.stdin = save_stdin
10297

98+
do_GET = do_POST = do_HEAD = send_head = run_cgi
99+
103100
def index(self):
104101
''' Print up an index of the available instances
105102
'''
106103
w = self.wfile.write
107104
w("Content-Type: text/html\n\n")
108-
w('<html><head><title>Roundup instances index</title><head>\n')
105+
w('<html><head><title>Roundup instances index</title></head>\n')
109106
w('<body><h1>Roundup instances index</h1><ol>\n')
110107
for instance in self.ROUNDUP_INSTANCE_HOMES.keys():
111108
w('<li><a href="%s/index">%s</a>\n'%(urllib.quote(instance),
@@ -180,11 +177,9 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
180177
self.send_response(200, "Script output follows")
181178

182179
# do the roundup thang
183-
client = instance.Client(instance, self.wfile, env)
180+
client = instance.Client(instance, self, env)
184181
client.main()
185182

186-
do_POST = run_cgi
187-
188183
def usage(message=''):
189184
if message: message = 'Error: %s\n'%message
190185
print '''%sUsage:
@@ -261,6 +256,9 @@ if __name__ == '__main__':
261256

262257
#
263258
# $Log: not supported by cvs2svn $
259+
# Revision 1.17 2001/10/29 23:55:44 richard
260+
# Fix to CGI top-level index (thanks Juergen Hermann)
261+
#
264262
# Revision 1.16 2001/10/27 00:12:21 richard
265263
# Fixed roundup-server for windows, thanks Juergen Hermann.
266264
#

roundup/cgi_client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.44 2001-10-28 23:03:08 richard Exp $
18+
# $Id: cgi_client.py,v 1.45 2001-11-01 22:04:37 richard Exp $
1919

2020
import os, cgi, pprint, StringIO, urlparse, re, traceback, mimetypes
2121
import base64, Cookie, time
@@ -52,14 +52,13 @@ class Client:
5252
ANONYMOUS_ACCESS = 'deny' # one of 'deny', 'allow'
5353
ANONYMOUS_REGISTER = 'deny' # one of 'deny', 'allow'
5454

55-
def __init__(self, instance, out, env):
55+
def __init__(self, instance, request, env):
5656
self.instance = instance
57-
self.out = out
57+
self.request = request
5858
self.env = env
5959
self.path = env['PATH_INFO']
6060
self.split_path = self.path.split('/')
6161

62-
self.headers_done = 0
6362
self.form = cgi.FieldStorage(environ=env)
6463
self.headers_done = 0
6564
self.debug = 0
@@ -68,11 +67,14 @@ def getuid(self):
6867
return self.db.user.lookup(self.user)
6968

7069
def header(self, headers={'Content-Type':'text/html'}):
70+
'''Put up the appropriate header.
71+
'''
7172
if not headers.has_key('Content-Type'):
7273
headers['Content-Type'] = 'text/html'
74+
self.request.send_response(200)
7375
for entry in headers.items():
74-
self.out.write('%s: %s\n'%entry)
75-
self.out.write('\n')
76+
self.request.send_header(*entry)
77+
self.request.end_headers()
7678
self.headers_done = 1
7779

7880
def pagehead(self, title, message=None):
@@ -152,7 +154,7 @@ def pagefoot(self):
152154
def write(self, content):
153155
if not self.headers_done:
154156
self.header()
155-
self.out.write(content)
157+
self.request.wfile.write(content)
156158

157159
def index_arg(self, arg):
158160
''' handle the args to index - they might be a list from the form
@@ -874,6 +876,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
874876

875877
#
876878
# $Log: not supported by cvs2svn $
879+
# Revision 1.44 2001/10/28 23:03:08 richard
880+
# Added more useful header to the classic schema.
881+
#
877882
# Revision 1.43 2001/10/24 00:01:42 richard
878883
# More fixes to lockout logic.
879884
#

roundup/mailgw.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class node. Any parts of other types are each stored in separate files
7272
an exception, the original message is bounced back to the sender with the
7373
explanatory message given in the exception.
7474
75-
$Id: mailgw.py,v 1.27 2001-10-30 11:26:10 richard Exp $
75+
$Id: mailgw.py,v 1.28 2001-11-01 22:04:37 richard Exp $
7676
'''
7777

7878

@@ -116,14 +116,18 @@ def __init__(self, db):
116116

117117
def main(self, fp):
118118
''' fp - the file from which to read the Message.
119+
'''
120+
self.handle_Message(Message(fp))
121+
122+
def handle_Message(self, message):
123+
'''Handle an RFC822 Message
119124
120-
Read a message from fp and then call handle_message() with the
121-
result. This method's job is to make that call and handle any
125+
Hanle the Message object by calling handle_message() and then cope
126+
with any errors raised by handle_message.
127+
This method's job is to make that call and handle any
122128
errors in a sane manner. It should be replaced if you wish to
123129
handle errors in a different manner.
124130
'''
125-
# ok, figure the subject, author, recipients and content-type
126-
message = Message(fp)
127131
m = []
128132
try:
129133
self.handle_message(message)
@@ -445,6 +449,9 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
445449

446450
#
447451
# $Log: not supported by cvs2svn $
452+
# Revision 1.27 2001/10/30 11:26:10 richard
453+
# Case-insensitive match for ISSUE_TRACKER_EMAIL in address in e-mail.
454+
#
448455
# Revision 1.26 2001/10/30 00:54:45 richard
449456
# Features:
450457
# . #467129 ] Lossage when username=e-mail-address

0 commit comments

Comments
 (0)