From be8f07f41f0c0e3d705a947322880b9ee85d947e Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 10 Dec 2002 00:23:36 +0000 Subject: [PATCH] - detect and break email loops (sf bug 640854) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1395 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 1 + roundup/mailgw.py | 16 +++++++++++++++- roundup/roundupdb.py | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6f7e5db..3e0552d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,7 @@ are given with the most recent entry first. - removed FILTER_POSITION from bundled configs - reverse message listing in issue display (reversion of recent change) - bad entries for multilink editing in cgi don't traceback now (sf bug 640310) +- detect and break email loops (sf bug 640854) 2002-11-07 0.5.2 diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 3f62e41..b7b29a6 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -73,7 +73,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.100 2002-12-10 00:11:15 richard Exp $ +$Id: mailgw.py,v 1.101 2002-12-10 00:23:35 richard Exp $ ''' import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri @@ -92,6 +92,10 @@ class MailUsageError(ValueError): class MailUsageHelp(Exception): pass +class MailLoop(Exception): + ''' We've seen this message before... ''' + pass + class Unauthorized(Exception): """ Access denied """ @@ -270,8 +274,12 @@ class MailGW: m = [''] m.append(str(value)) m = self.bounce_message(message, sendto, m) + except MailLoop: + # XXX we should use a log file here... + return except: # bounce the message back to the sender with the error message + # XXX we should use a log file here... sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL] m = [''] m.append('An unexpected error occurred during the processing') @@ -285,6 +293,7 @@ class MailGW: m = self.bounce_message(message, sendto, m) else: # very bad-looking message - we don't even know who sent it + # XXX we should use a log file here... sendto = [self.instance.config.ADMIN_EMAIL] m = ['Subject: badly formed message from mail gateway'] m.append('') @@ -319,6 +328,7 @@ class MailGW: ''' msg = cStringIO.StringIO() writer = MimeWriter.MimeWriter(msg) + writer.addheader('X-Roundup-Loop', 'hello') writer.addheader('Subject', subject) writer.addheader('From', '%s <%s>'% (self.instance.config.TRACKER_NAME, self.instance.config.TRACKER_EMAIL)) @@ -371,6 +381,10 @@ class MailGW: Parse the message as per the module docstring. ''' + # detect loops + if message.getheader('x-roundup-loop', ''): + raise MailLoop + # handle the subject line subject = message.getheader('subject', '') diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index 8fd9b28..af624eb 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundupdb.py,v 1.73 2002-11-05 22:59:46 richard Exp $ +# $Id: roundupdb.py,v 1.74 2002-12-10 00:23:36 richard Exp $ __doc__ = """ Extending hyperdb with types specific to issue-tracking. @@ -239,6 +239,9 @@ class IssueClass: # add a uniquely Roundup header to help filtering writer.addheader('X-Roundup-Name', self.db.config.TRACKER_NAME) + # avoid email loops + writer.addheader('X-Roundup-Loop', 'hello') + # attach files if message_files: part = writer.startmultipartbody('mixed') -- 2.30.2