|
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 $ |
2 | 2 |
|
3 | 3 | __doc__ = """ |
4 | 4 | WWW request handler (also used in the stand-alone server). |
@@ -27,6 +27,11 @@ class Redirect(HTTPException): |
27 | 27 | class NotModified(HTTPException): |
28 | 28 | pass |
29 | 29 |
|
| 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 | + |
30 | 35 | # XXX actually _use_ FormError |
31 | 36 | class FormError(ValueError): |
32 | 37 | ''' An "expected" exception occurred during form parsing. |
@@ -280,9 +285,9 @@ def clean_sessions(self): |
280 | 285 | # remove aged otks |
281 | 286 | otks = self.db.otks |
282 | 287 | for sessid in otks.list(): |
283 | | - interval = now - okts.get(sessid, '__time') |
| 288 | + interval = now - otks.get(sessid, '__time') |
284 | 289 | if interval > week: |
285 | | - otk.destroy(sessid) |
| 290 | + otks.destroy(sessid) |
286 | 291 | sessions.set('last_clean', last_use=time.time()) |
287 | 292 |
|
288 | 293 | def determine_user(self): |
@@ -763,18 +768,25 @@ def sendEmail(self, to, subject, content): |
763 | 768 | content = StringIO.StringIO(content) |
764 | 769 | quopri.encode(content, body, 0) |
765 | 770 |
|
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) |
778 | 790 | return 0 |
779 | 791 | return 1 |
780 | 792 |
|
|
0 commit comments