changeset 1321:328d68db2ef8

- detect and break email loops [SF#640854]
author Richard Jones <richard@users.sourceforge.net>
date Tue, 10 Dec 2002 00:23:36 +0000
parents 3758a5af985f
children c0546b95aad1
files CHANGES.txt roundup/mailgw.py roundup/roundupdb.py
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Tue Dec 10 00:11:16 2002 +0000
+++ b/CHANGES.txt	Tue Dec 10 00:23:36 2002 +0000
@@ -16,6 +16,7 @@
 - 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
--- a/roundup/mailgw.py	Tue Dec 10 00:11:16 2002 +0000
+++ b/roundup/mailgw.py	Tue Dec 10 00:23:36 2002 +0000
@@ -73,7 +73,7 @@
 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 MailUsageHelp(Exception):
     pass
 
+class MailLoop(Exception):
+    ''' We've seen this message before... '''
+    pass
+
 class Unauthorized(Exception):
     """ Access denied """
 
@@ -270,8 +274,12 @@
                 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 @@
                 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 @@
         '''
         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 @@
 
         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', '')
 
--- a/roundup/roundupdb.py	Tue Dec 10 00:11:16 2002 +0000
+++ b/roundup/roundupdb.py	Tue Dec 10 00:23:36 2002 +0000
@@ -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 @@
         # 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')

Roundup Issue Tracker: http://roundup-tracker.org/