changeset 616:08abec25b2c6

[SF#503204] mailgw needs a default class - partially done - the setting of additional properties can wait for a better configuration system.
author Richard Jones <richard@users.sourceforge.net>
date Fri, 15 Feb 2002 00:13:38 +0000
parents 7c2c4840db6a
children edd210915e64
files CHANGES.txt roundup/mailgw.py roundup/templates/classic/instance_config.py roundup/templates/extended/instance_config.py test/test_mailgw.py
diffstat 5 files changed, 124 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Thu Feb 14 23:46:02 2002 +0000
+++ b/CHANGES.txt	Fri Feb 15 00:13:38 2002 +0000
@@ -2,6 +2,11 @@
 are given with the most recent entry first.
 
 2002-02-?? - 0.4.1
+Feature:
+ . #503204 ] mailgw needs a default class
+   - partially done - the setting of additional properties can wait for a
+     better configuration system.
+
 Fixed:
  . Clean up mail handling, multipart handling.
  . respect encodings in non multipart messages.
@@ -15,6 +20,7 @@
    on the client-side.
  . #516883 ] mail interface + ANONYMOUS_REGISTER
 
+
 2002-01-24 - 0.4.0
 Feature:
  . much nicer history display (actualy real handling of property types etc)
--- a/roundup/mailgw.py	Thu Feb 14 23:46:02 2002 +0000
+++ b/roundup/mailgw.py	Fri Feb 15 00:13:38 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.64 2002-02-14 23:46:02 richard Exp $
+$Id: mailgw.py,v 1.65 2002-02-15 00:13:38 richard Exp $
 '''
 
 
@@ -120,7 +120,7 @@
         return Message(s)
 
 subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fwd|re|aw)\s*\W?\s*)*'
-    r'\s*(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])'
+    r'\s*(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])?'
     r'\s*(?P<title>[^[]+)?(\[(?P<args>.+?)\])?', re.I)
 
 class MailGW:
@@ -292,6 +292,20 @@
             raise MailUsageHelp
 
         m = subject_re.match(subject)
+
+        # check for well-formed subject line
+        if m:
+            # get the classname
+            classname = m.group('classname')
+            if classname is None:
+                # no classname, fallback on the default
+                if hasattr(self.instance, 'MAIL_DEFAULT_CLASS') and \
+                        self.instance.MAIL_DEFAULT_CLASS:
+                    classname = self.instance.MAIL_DEFAULT_CLASS
+                else:
+                    # fail
+                    m = None
+
         if not m:
             raise MailUsageError, '''
 The message you sent to roundup did not contain a properly formed subject
@@ -307,8 +321,7 @@
 Subject was: "%s"
 '''%subject
 
-        # get the classname
-        classname = m.group('classname')
+        # get the class
         try:
             cl = self.db.getclass(classname)
         except KeyError:
@@ -790,6 +803,9 @@
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.64  2002/02/14 23:46:02  richard
+# . #516883 ] mail interface + ANONYMOUS_REGISTER
+#
 # Revision 1.63  2002/02/12 08:08:55  grubert
 #  . Clean up mail handling, multipart handling.
 #
--- a/roundup/templates/classic/instance_config.py	Thu Feb 14 23:46:02 2002 +0000
+++ b/roundup/templates/classic/instance_config.py	Fri Feb 15 00:13:38 2002 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: instance_config.py,v 1.11 2002-02-14 23:46:02 richard Exp $
+# $Id: instance_config.py,v 1.12 2002-02-15 00:13:38 richard Exp $
 
 MAIL_DOMAIN=MAILHOST=HTTP_HOST=None
 HTTP_PORT=0
@@ -83,8 +83,17 @@
 # Where to place the email signature
 EMAIL_SIGNATURE_POSITION = 'bottom'
 
+# Default class to use in the mailgw if one isn't supplied in email
+# subjects. To disable, comment out the variable below or leave it blank.
+# Examples:
+MAIL_DEFAULT_CLASS = 'issue'   # use "issue" class by default
+#MAIL_DEFAULT_CLASS = ''        # disable (or just comment the var out)
+
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.11  2002/02/14 23:46:02  richard
+# . #516883 ] mail interface + ANONYMOUS_REGISTER
+#
 # Revision 1.10  2001/11/26 22:55:56  richard
 # Feature:
 #  . Added INSTANCE_NAME to configuration - used in web and email to identify
--- a/roundup/templates/extended/instance_config.py	Thu Feb 14 23:46:02 2002 +0000
+++ b/roundup/templates/extended/instance_config.py	Fri Feb 15 00:13:38 2002 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: instance_config.py,v 1.11 2002-02-14 23:46:02 richard Exp $
+# $Id: instance_config.py,v 1.12 2002-02-15 00:13:38 richard Exp $
 
 MAIL_DOMAIN=MAILHOST=HTTP_HOST=None
 HTTP_PORT=0
@@ -69,13 +69,13 @@
 FILTER_POSITION = 'bottom'      # one of 'top', 'bottom', 'top and bottom'
 
 # Deny or allow anonymous access to the web interface
-ANONYMOUS_ACCESS = 'deny'
+ANONYMOUS_ACCESS = 'deny'       # either 'deny' or 'allow'
 
 # Deny or allow anonymous users to register through the web interface
-ANONYMOUS_REGISTER = 'deny'
+ANONYMOUS_REGISTER = 'deny'     # either 'deny' or 'allow'
 
 # Deny or allow anonymous users to register through the mail interface
-ANONYMOUS_REGISTER_MAIL = 'deny'
+ANONYMOUS_REGISTER_MAIL = 'deny'     # either 'deny' or 'allow'
 
 # Send nosy messages to the author of the message
 MESSAGES_TO_AUTHOR = 'no'       # either 'yes' or 'no'
@@ -83,8 +83,17 @@
 # Where to place the email signature
 EMAIL_SIGNATURE_POSITION = 'bottom'
 
+# Default class to use in the mailgw if one isn't supplied in email
+# subjects. To disable, comment out the variable below or leave it blank.
+# Examples:
+MAIL_DEFAULT_CLASS = 'issue'   # use "issue" class by default
+#MAIL_DEFAULT_CLASS = ''        # disable (or just comment the var out)
+
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.11  2002/02/14 23:46:02  richard
+# . #516883 ] mail interface + ANONYMOUS_REGISTER
+#
 # Revision 1.10  2001/11/26 22:55:56  richard
 # Feature:
 #  . Added INSTANCE_NAME to configuration - used in web and email to identify
--- a/test/test_mailgw.py	Thu Feb 14 23:46:02 2002 +0000
+++ b/test/test_mailgw.py	Fri Feb 15 00:13:38 2002 +0000
@@ -8,7 +8,7 @@
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
-# $Id: test_mailgw.py,v 1.11 2002-02-14 23:38:12 richard Exp $
+# $Id: test_mailgw.py,v 1.12 2002-02-15 00:13:38 richard Exp $
 
 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
 
@@ -61,6 +61,23 @@
             error = open(os.environ['SENDMAILDEBUG']).read()
             self.assertEqual('no error', error)
 
+    def testNewIssueNoClass(self):
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork
+To: issue_tracker@fill.me.in.
+Cc: richard@test
+Message-Id: <dummy_test_message_id>
+Subject: Testing...
+
+This is a test submission of a new issue.
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.main(message)
+        if os.path.exists(os.environ['SENDMAILDEBUG']):
+            error = open(os.environ['SENDMAILDEBUG']).read()
+            self.assertEqual('no error', error)
+
     def testNewIssueAuthMsg(self):
         message = cStringIO.StringIO('''Content-Type: text/plain;
   charset="iso-8859-1"
@@ -104,14 +121,14 @@
 "Roundup issue tracker" <issue_tracker@fill.me.in.>
 http://some.useful.url/issue1
 ___________________________________________________
-''')
+''', 'Generated message not correct')
 
     # BUG
     # def testMultipart(self):
-    # 	'''With more than one part'''
-    #	see MultipartEnc tests: but if there is more than one part
-    #	we return a multipart/mixed and the boundary contains
-    #	the ip address of the test machine. 
+    #         '''With more than one part'''
+    #        see MultipartEnc tests: but if there is more than one part
+    #        we return a multipart/mixed and the boundary contains
+    #        the ip address of the test machine. 
 
     # BUG should test some binary attamchent too.
 
@@ -200,6 +217,50 @@
 ___________________________________________________
 ''', 'Generated message not correct')
 
+    def testFollowupTitleMatch(self):
+        self.testNewIssue()
+        message = cStringIO.StringIO('''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@fill.me.in.
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: Re: Testing... [assignedto=mary; nosy=john]
+
+This is a followup
+''')
+        handler = self.instance.MailGW(self.instance, self.db)
+        handler.main(message)
+
+        self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
+'''FROM: roundup-admin@fill.me.in.
+TO: chef@bork.bork.bork, mary@test, john@test
+Content-Type: text/plain
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork, mary@test, john@test
+From: richard <issue_tracker@fill.me.in.>
+Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+
+
+richard <richard@test> added the comment:
+
+This is a followup
+
+
+----------
+assignedto:  -> mary
+nosy: +mary, john
+status: unread -> chatting
+___________________________________________________
+"Roundup issue tracker" <issue_tracker@fill.me.in.>
+http://some.useful.url/issue1
+___________________________________________________
+''') #, 'Generated message not correct')
+
     def testEnc01(self):
         self.testNewIssue()
         message = cStringIO.StringIO('''Content-Type: text/plain;
@@ -303,13 +364,20 @@
 
 def suite():
     l = [unittest.makeSuite(MailgwTestCase, 'test'),
-        unittest.makeSuite(ExtMailgwTestCase, 'test')
+         unittest.makeSuite(ExtMailgwTestCase, 'test')
     ]
     return unittest.TestSuite(l)
 
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.11  2002/02/14 23:38:12  richard
+# Fixed the unit tests for the mailgw re: the x-roundup-name header.
+# Also made the test runner more user-friendly:
+#   ./run_tests            - detect all tests in test/test_<name>.py and run them
+#   ./run_tests <name>     - run only test/test_<name>.py
+# eg ./run_tests mailgw    - run the mailgw test from test/test_mailgw.py
+#
 # Revision 1.10  2002/02/12 08:08:55  grubert
 #  . Clean up mail handling, multipart handling.
 #

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