Skip to content

Commit 329d912

Browse files
author
Richard Jones
committed
fixed rego email bugs [SF#699809]
1 parent 60a268c commit 329d912

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

roundup/cgi/client.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.106 2003-03-17 04:46:20 richard Exp $
1+
# $Id: client.py,v 1.107 2003-03-18 00:24:35 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -27,6 +27,11 @@ class Redirect(HTTPException):
2727
class NotModified(HTTPException):
2828
pass
2929

30+
# set to indicate to roundup not to actually _send_ email
31+
# this var must contain a file to write the mail to
32+
SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
33+
34+
3035
# XXX actually _use_ FormError
3136
class FormError(ValueError):
3237
''' An "expected" exception occurred during form parsing.
@@ -280,9 +285,9 @@ def clean_sessions(self):
280285
# remove aged otks
281286
otks = self.db.otks
282287
for sessid in otks.list():
283-
interval = now - okts.get(sessid, '__time')
288+
interval = now - otks.get(sessid, '__time')
284289
if interval > week:
285-
otk.destroy(sessid)
290+
otks.destroy(sessid)
286291
sessions.set('last_clean', last_use=time.time())
287292

288293
def determine_user(self):
@@ -763,18 +768,25 @@ def sendEmail(self, to, subject, content):
763768
content = StringIO.StringIO(content)
764769
quopri.encode(content, body, 0)
765770

766-
# now try to send the message
767-
try:
768-
# send the message as admin so bounces are sent there
769-
# instead of to roundup
770-
smtp = smtplib.SMTP(self.db.config.MAILHOST)
771-
smtp.sendmail(self.db.config.ADMIN_EMAIL, [to], message.getvalue())
772-
except socket.error, value:
773-
self.error_message.append("Error: couldn't send email: "
774-
"mailhost %s"%value)
775-
return 0
776-
except smtplib.SMTPException, value:
777-
self.error_message.append("Error: couldn't send email: %s"%value)
771+
if SENDMAILDEBUG:
772+
# don't send - just write to a file
773+
open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%(
774+
self.db.config.ADMIN_EMAIL,
775+
', '.join(to),message.getvalue()))
776+
else:
777+
# now try to send the message
778+
try:
779+
# send the message as admin so bounces are sent there
780+
# instead of to roundup
781+
smtp = smtplib.SMTP(self.db.config.MAILHOST)
782+
smtp.sendmail(self.db.config.ADMIN_EMAIL, [to],
783+
message.getvalue())
784+
except socket.error, value:
785+
self.error_message.append("Error: couldn't send email: "
786+
"mailhost %s"%value)
787+
return 0
788+
except smtplib.SMTPException, msg:
789+
self.error_message.append("Error: couldn't send email: %s"%msg)
778790
return 0
779791
return 1
780792

0 commit comments

Comments
 (0)