Skip to content

Commit 4d9ad8f

Browse files
author
Richard Jones
committed
[SF#503204] mailgw needs a default class
- partially done - the setting of additional properties can wait for a better configuration system.
1 parent 94137d2 commit 4d9ad8f

File tree

5 files changed

+124
-16
lines changed

5 files changed

+124
-16
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

44
2002-02-?? - 0.4.1
5+
Feature:
6+
. #503204 ] mailgw needs a default class
7+
- partially done - the setting of additional properties can wait for a
8+
better configuration system.
9+
510
Fixed:
611
. Clean up mail handling, multipart handling.
712
. respect encodings in non multipart messages.
@@ -15,6 +20,7 @@ Fixed:
1520
on the client-side.
1621
. #516883 ] mail interface + ANONYMOUS_REGISTER
1722

23+
1824
2002-01-24 - 0.4.0
1925
Feature:
2026
. much nicer history display (actualy real handling of property types etc)

roundup/mailgw.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.64 2002-02-14 23:46:02 richard Exp $
76+
$Id: mailgw.py,v 1.65 2002-02-15 00:13:38 richard Exp $
7777
'''
7878

7979

@@ -120,7 +120,7 @@ def getPart(self):
120120
return Message(s)
121121

122122
subject_re = re.compile(r'(?P<refwd>\s*\W?\s*(fwd|re|aw)\s*\W?\s*)*'
123-
r'\s*(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])'
123+
r'\s*(\[(?P<classname>[^\d\s]+)(?P<nodeid>\d+)?\])?'
124124
r'\s*(?P<title>[^[]+)?(\[(?P<args>.+?)\])?', re.I)
125125

126126
class MailGW:
@@ -292,6 +292,20 @@ def handle_message(self, message):
292292
raise MailUsageHelp
293293

294294
m = subject_re.match(subject)
295+
296+
# check for well-formed subject line
297+
if m:
298+
# get the classname
299+
classname = m.group('classname')
300+
if classname is None:
301+
# no classname, fallback on the default
302+
if hasattr(self.instance, 'MAIL_DEFAULT_CLASS') and \
303+
self.instance.MAIL_DEFAULT_CLASS:
304+
classname = self.instance.MAIL_DEFAULT_CLASS
305+
else:
306+
# fail
307+
m = None
308+
295309
if not m:
296310
raise MailUsageError, '''
297311
The message you sent to roundup did not contain a properly formed subject
@@ -307,8 +321,7 @@ def handle_message(self, message):
307321
Subject was: "%s"
308322
'''%subject
309323

310-
# get the classname
311-
classname = m.group('classname')
324+
# get the class
312325
try:
313326
cl = self.db.getclass(classname)
314327
except KeyError:
@@ -790,6 +803,9 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
790803

791804
#
792805
# $Log: not supported by cvs2svn $
806+
# Revision 1.64 2002/02/14 23:46:02 richard
807+
# . #516883 ] mail interface + ANONYMOUS_REGISTER
808+
#
793809
# Revision 1.63 2002/02/12 08:08:55 grubert
794810
# . Clean up mail handling, multipart handling.
795811
#

roundup/templates/classic/instance_config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: instance_config.py,v 1.11 2002-02-14 23:46:02 richard Exp $
18+
# $Id: instance_config.py,v 1.12 2002-02-15 00:13:38 richard Exp $
1919

2020
MAIL_DOMAIN=MAILHOST=HTTP_HOST=None
2121
HTTP_PORT=0
@@ -83,8 +83,17 @@
8383
# Where to place the email signature
8484
EMAIL_SIGNATURE_POSITION = 'bottom'
8585

86+
# Default class to use in the mailgw if one isn't supplied in email
87+
# subjects. To disable, comment out the variable below or leave it blank.
88+
# Examples:
89+
MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default
90+
#MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out)
91+
8692
#
8793
# $Log: not supported by cvs2svn $
94+
# Revision 1.11 2002/02/14 23:46:02 richard
95+
# . #516883 ] mail interface + ANONYMOUS_REGISTER
96+
#
8897
# Revision 1.10 2001/11/26 22:55:56 richard
8998
# Feature:
9099
# . Added INSTANCE_NAME to configuration - used in web and email to identify

roundup/templates/extended/instance_config.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: instance_config.py,v 1.11 2002-02-14 23:46:02 richard Exp $
18+
# $Id: instance_config.py,v 1.12 2002-02-15 00:13:38 richard Exp $
1919

2020
MAIL_DOMAIN=MAILHOST=HTTP_HOST=None
2121
HTTP_PORT=0
@@ -69,22 +69,31 @@
6969
FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom'
7070

7171
# Deny or allow anonymous access to the web interface
72-
ANONYMOUS_ACCESS = 'deny'
72+
ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow'
7373

7474
# Deny or allow anonymous users to register through the web interface
75-
ANONYMOUS_REGISTER = 'deny'
75+
ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow'
7676

7777
# Deny or allow anonymous users to register through the mail interface
78-
ANONYMOUS_REGISTER_MAIL = 'deny'
78+
ANONYMOUS_REGISTER_MAIL = 'deny' # either 'deny' or 'allow'
7979

8080
# Send nosy messages to the author of the message
8181
MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no'
8282

8383
# Where to place the email signature
8484
EMAIL_SIGNATURE_POSITION = 'bottom'
8585

86+
# Default class to use in the mailgw if one isn't supplied in email
87+
# subjects. To disable, comment out the variable below or leave it blank.
88+
# Examples:
89+
MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default
90+
#MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out)
91+
8692
#
8793
# $Log: not supported by cvs2svn $
94+
# Revision 1.11 2002/02/14 23:46:02 richard
95+
# . #516883 ] mail interface + ANONYMOUS_REGISTER
96+
#
8897
# Revision 1.10 2001/11/26 22:55:56 richard
8998
# Feature:
9099
# . Added INSTANCE_NAME to configuration - used in web and email to identify

test/test_mailgw.py

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.11 2002-02-14 23:38:12 richard Exp $
11+
# $Id: test_mailgw.py,v 1.12 2002-02-15 00:13:38 richard Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
1414

@@ -53,6 +53,23 @@ def testNewIssue(self):
5353
Message-Id: <dummy_test_message_id>
5454
Subject: [issue] Testing...
5555
56+
This is a test submission of a new issue.
57+
''')
58+
handler = self.instance.MailGW(self.instance, self.db)
59+
handler.main(message)
60+
if os.path.exists(os.environ['SENDMAILDEBUG']):
61+
error = open(os.environ['SENDMAILDEBUG']).read()
62+
self.assertEqual('no error', error)
63+
64+
def testNewIssueNoClass(self):
65+
message = cStringIO.StringIO('''Content-Type: text/plain;
66+
charset="iso-8859-1"
67+
From: Chef <[email protected]
68+
69+
Cc: richard@test
70+
Message-Id: <dummy_test_message_id>
71+
Subject: Testing...
72+
5673
This is a test submission of a new issue.
5774
''')
5875
handler = self.instance.MailGW(self.instance, self.db)
@@ -104,14 +121,14 @@ def testNewIssueAuthMsg(self):
104121
"Roundup issue tracker" <[email protected].>
105122
http://some.useful.url/issue1
106123
___________________________________________________
107-
''')
124+
''', 'Generated message not correct')
108125

109126
# BUG
110127
# def testMultipart(self):
111-
# '''With more than one part'''
112-
# see MultipartEnc tests: but if there is more than one part
113-
# we return a multipart/mixed and the boundary contains
114-
# the ip address of the test machine.
128+
# '''With more than one part'''
129+
# see MultipartEnc tests: but if there is more than one part
130+
# we return a multipart/mixed and the boundary contains
131+
# the ip address of the test machine.
115132

116133
# BUG should test some binary attamchent too.
117134

@@ -200,6 +217,50 @@ def testFollowup2(self):
200217
___________________________________________________
201218
''', 'Generated message not correct')
202219

220+
def testFollowupTitleMatch(self):
221+
self.testNewIssue()
222+
message = cStringIO.StringIO('''Content-Type: text/plain;
223+
charset="iso-8859-1"
224+
From: richard <richard@test>
225+
226+
Message-Id: <followup_dummy_id>
227+
In-Reply-To: <dummy_test_message_id>
228+
Subject: Re: Testing... [assignedto=mary; nosy=john]
229+
230+
This is a followup
231+
''')
232+
handler = self.instance.MailGW(self.instance, self.db)
233+
handler.main(message)
234+
235+
self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
236+
237+
TO: [email protected], mary@test, john@test
238+
Content-Type: text/plain
239+
Subject: [issue1] Testing...
240+
To: [email protected], mary@test, john@test
241+
From: richard <[email protected].>
242+
Reply-To: Roundup issue tracker <[email protected].>
243+
MIME-Version: 1.0
244+
Message-Id: <followup_dummy_id>
245+
In-Reply-To: <dummy_test_message_id>
246+
X-Roundup-Name: Roundup issue tracker
247+
248+
249+
richard <richard@test> added the comment:
250+
251+
This is a followup
252+
253+
254+
----------
255+
assignedto: -> mary
256+
nosy: +mary, john
257+
status: unread -> chatting
258+
___________________________________________________
259+
"Roundup issue tracker" <[email protected].>
260+
http://some.useful.url/issue1
261+
___________________________________________________
262+
''') #, 'Generated message not correct')
263+
203264
def testEnc01(self):
204265
self.testNewIssue()
205266
message = cStringIO.StringIO('''Content-Type: text/plain;
@@ -303,13 +364,20 @@ class ExtMailgwTestCase(MailgwTestCase):
303364

304365
def suite():
305366
l = [unittest.makeSuite(MailgwTestCase, 'test'),
306-
unittest.makeSuite(ExtMailgwTestCase, 'test')
367+
unittest.makeSuite(ExtMailgwTestCase, 'test')
307368
]
308369
return unittest.TestSuite(l)
309370

310371

311372
#
312373
# $Log: not supported by cvs2svn $
374+
# Revision 1.11 2002/02/14 23:38:12 richard
375+
# Fixed the unit tests for the mailgw re: the x-roundup-name header.
376+
# Also made the test runner more user-friendly:
377+
# ./run_tests - detect all tests in test/test_<name>.py and run them
378+
# ./run_tests <name> - run only test/test_<name>.py
379+
# eg ./run_tests mailgw - run the mailgw test from test/test_mailgw.py
380+
#
313381
# Revision 1.10 2002/02/12 08:08:55 grubert
314382
# . Clean up mail handling, multipart handling.
315383
#

0 commit comments

Comments
 (0)