Code

Fix to handle bad form submissions, Links and the magic -1 form value.
[roundup.git] / roundup / roundupdb.py
index 1baf624872ea59fae91186409ab58556b81b20e1..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.66 2002-09-10 03:01:18 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
 
@@ -46,9 +56,11 @@ class MessageSendError(RuntimeError):
     pass
 
 class DetectorError(RuntimeError):
+    ''' Raised by detectors that want to indicate that something's amiss
+    '''
     pass
 
-# XXX deviation from spec - was called ItemClass
+# deviation from spec - was called IssueClass
 class IssueClass:
     """ This class is intended to be mixed-in with a hyperdb backend
         implementation. The backend should provide a mechanism that
@@ -134,7 +146,7 @@ class IssueClass:
             # send the message
             self.send_message(nodeid, msgid, note, sendto)
 
-    # XXX backwards compatibility - don't remove
+    # backwards compatibility - don't remove
     sendmessage = nosymessage
 
     def send_message(self, nodeid, msgid, note, sendto):
@@ -227,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')
@@ -285,16 +300,16 @@ class IssueClass:
     def email_signature(self, nodeid, msgid):
         ''' Add a signature to the e-mail with some useful information
         '''
-
         # simplistic check to see if the url is valid,
         # 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://'):
+        if (not isinstance(base , type('')) or
+            not (base.startswith('http://') or base.startswith('https://'))):
             base = "Configuration Error: TRACKER_WEB isn't a " \
                 "fully-qualified URL"
         elif base[-1] != '/' :
             base += '/'
-        web = base + 'issue'+ nodeid
+        web = base + self.classname + nodeid
 
         # ensure the email address is properly quoted
         email = straddr((self.db.config.TRACKER_NAME,
@@ -357,7 +372,10 @@ class IssueClass:
 
         # determine what changed
         for key in oldvalues.keys():
-            if key in ['files','messages']: continue
+            if key in ['files','messages']:
+                continue
+            if key in ('activity', 'creator', 'creation'):
+                continue
             new_value = cl.get(nodeid, key)
             # the old value might be non existent
             try: