Code

- detect and break email loops (sf bug 640854)
[roundup.git] / roundup / roundupdb.py
index 65739b0bd9a38135c47c44b1a77e1a53dc9ef0fc..af624eba974697dfd9fd599eee7b98a0cc0ffb8e 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: roundupdb.py,v 1.71 2002-10-08 04:11:13 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.
@@ -26,9 +26,19 @@ import MimeWriter, cStringIO
 import base64, quopri, mimetypes
 # if available, use the 'email' module, otherwise fallback to 'rfc822'
 try :
-    from email.Utils import dump_address_pair as straddr
+    from email.Utils import formataddr as straddr
 except ImportError :
-    from rfc822 import dump_address_pair as straddr
+    # code taken from the email package 2.4.3
+    def straddr(pair, specialsre = re.compile(r'[][\()<>@,:;".]'),
+            escapesre = re.compile(r'[][\()"]')):
+        name, address = pair
+        if name:
+            quotes = ''
+            if specialsre.search(name):
+                quotes = '"'
+            name = escapesre.sub(r'\\\g<0>', name)
+            return '%s%s%s <%s>' % (quotes, name, quotes, address)
+        return address
 
 import hyperdb
 
@@ -229,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')
@@ -291,8 +304,7 @@ class IssueClass:
         # then append a trailing slash if it is missing
         base = self.db.config.TRACKER_WEB 
         if (not isinstance(base , type('')) or
-            not base.startswith('http://') or
-            not base.startswith('https://')):
+            not (base.startswith('http://') or base.startswith('https://'))):
             base = "Configuration Error: TRACKER_WEB isn't a " \
                 "fully-qualified URL"
         elif base[-1] != '/' :