From 3f437461163e75cf41f8eaabdabfbfd6a1f57291 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 15 Feb 2002 00:13:38 +0000 Subject: [PATCH] . #503204 ] mailgw needs a default class - partially done - the setting of additional properties can wait for a better configuration system. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@628 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 6 ++ roundup/mailgw.py | 24 +++++- roundup/templates/classic/instance_config.py | 11 ++- roundup/templates/extended/instance_config.py | 17 +++- test/test_mailgw.py | 82 +++++++++++++++++-- 5 files changed, 124 insertions(+), 16 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6a7ba22..8f5716e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,11 @@ This file contains the changes to the Roundup system over time. The entries 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 @@ Fixed: 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) diff --git a/roundup/mailgw.py b/roundup/mailgw.py index b3bda14..3898051 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.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 @@ class Message(mimetools.Message): return Message(s) subject_re = re.compile(r'(?P\s*\W?\s*(fwd|re|aw)\s*\W?\s*)*' - r'\s*(\[(?P[^\d\s]+)(?P\d+)?\])' + r'\s*(\[(?P[^\d\s]+)(?P\d+)?\])?' r'\s*(?P[^[]+)?(\[(?P<args>.+?)\])?', re.I) class MailGW: @@ -292,6 +292,20 @@ class MailGW: 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 @@ line. The subject must contain a class name or designator to indicate the 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 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), # # $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. # diff --git a/roundup/templates/classic/instance_config.py b/roundup/templates/classic/instance_config.py index e36d1bb..0fe747d 100644 --- a/roundup/templates/classic/instance_config.py +++ b/roundup/templates/classic/instance_config.py @@ -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 @@ MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' # 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 diff --git a/roundup/templates/extended/instance_config.py b/roundup/templates/extended/instance_config.py index f3ddcd1..89f3268 100644 --- a/roundup/templates/extended/instance_config.py +++ b/roundup/templates/extended/instance_config.py @@ -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 @@ LOG = os.path.join(INSTANCE_HOME, 'roundup.log') 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 @@ MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' # 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 diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 58dda70..f877a1d 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -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 @@ -53,6 +53,23 @@ Cc: richard@test Message-Id: <dummy_test_message_id> Subject: [issue] 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 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) @@ -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 @@ http://some.useful.url/issue1 ___________________________________________________ ''', '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 @@ class ExtMailgwTestCase(MailgwTestCase): 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. # -- 2.30.2