Skip to content

Commit 763a9c4

Browse files
author
Richard Jones
committed
Implemented correct mail splitting (was taking a shortcut).
Added unit tests. Also snips signatures now too.
1 parent 345b677 commit 763a9c4

File tree

5 files changed

+137
-18
lines changed

5 files changed

+137
-18
lines changed

CHANGES.txt

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

4-
2001-08-?? - 0.2.5
5-
Features:
4+
2001-08-03 - 0.2.5
5+
Note:
6+
. The bsddb3 module has a bug that renders it non-functional. Users should
7+
select the anydbm or bsddb backend instead.
68

79
Fixed:
10+
. Python 2.0 does not contain the unittest module. The setup.py module now
11+
checks for unittest before attempting to run the unit tests.
812

913

1014
2001-08-03 - 0.2.4

README.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ hyperdb:
7878
roundupdb:
7979
. split the file storage into multiple dirs?
8080
roundup-mailgw:
81-
. do the "sectioning" stuff properly (ie. as it's documented)
8281
. errors as attachments
83-
. snip signatures?
8482
roundup-server:
8583
. check the source file timestamps before reloading
8684
cgi_client

roundup/mailgw.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class node. Any parts of other types are each stored in separate files
5555
an exception, the original message is bounced back to the sender with the
5656
explanatory message given in the exception.
5757
58-
$Id: mailgw.py,v 1.6 2001-08-01 04:24:21 richard Exp $
58+
$Id: mailgw.py,v 1.7 2001-08-03 07:18:22 richard Exp $
5959
'''
6060

6161

@@ -243,17 +243,7 @@ def handle_message(self, message):
243243
else:
244244
content = message.fp.read()
245245

246-
# extract out the summary from the message
247-
summary = []
248-
for line in content.split('\n'):
249-
line = line.strip()
250-
if summary and not line:
251-
break
252-
if not line:
253-
summary.append('')
254-
elif line[0] not in '>|':
255-
summary.append(line)
256-
summary = '\n'.join(summary)
246+
summary, content = parseContent(content)
257247

258248
# handle the files
259249
files = []
@@ -296,8 +286,41 @@ def handle_message(self, message):
296286
props['nosy'].sort()
297287
nodeid = cl.create(**props)
298288

289+
def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
290+
eol=re.compile(r'[\r\n]+'), signature=re.compile(r'^[>|\s]*[-_]+\s*$')):
291+
''' The message body is divided into sections by blank lines.
292+
Sections where the second and all subsequent lines begin with a ">" or "|"
293+
character are considered "quoting sections". The first line of the first
294+
non-quoting section becomes the summary of the message.
295+
'''
296+
sections = blank_line.split(content)
297+
# extract out the summary from the message
298+
summary = ''
299+
l = []
300+
print sections
301+
for section in sections:
302+
section = section.strip()
303+
if not section:
304+
continue
305+
lines = eol.split(section)
306+
if lines[0] and lines[0][0] in '>|':
307+
continue
308+
if len(lines) > 1 and lines[1] and lines[1][0] in '>|':
309+
continue
310+
if not summary:
311+
summary = lines[0]
312+
l.append(section)
313+
continue
314+
if signature.match(lines[0]):
315+
break
316+
l.append(section)
317+
return summary, '\n'.join(l)
318+
299319
#
300320
# $Log: not supported by cvs2svn $
321+
# Revision 1.6 2001/08/01 04:24:21 richard
322+
# mailgw was assuming certain properties existed on the issues being created.
323+
#
301324
# Revision 1.5 2001/07/29 07:01:39 richard
302325
# Added vim command to all source so that we don't get no steenkin' tabs :)
303326
#

test/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
# $Id: __init__.py,v 1.3 2001-07-29 07:01:39 richard Exp $
1+
# $Id: __init__.py,v 1.4 2001-08-03 07:18:22 richard Exp $
22

33
import unittest
44

5-
import test_dates, test_schema, test_db, test_multipart
5+
import test_dates, test_schema, test_db, test_multipart, test_mailsplit
66

77
def go():
88
suite = unittest.TestSuite((
99
test_dates.suite(),
1010
test_schema.suite(),
1111
test_db.suite(),
1212
test_multipart.suite(),
13+
test_mailsplit.suite(),
1314
))
1415
runner = unittest.TextTestRunner()
1516
runner.run(suite)
1617

1718
#
1819
# $Log: not supported by cvs2svn $
20+
# Revision 1.3 2001/07/29 07:01:39 richard
21+
# Added vim command to all source so that we don't get no steenkin' tabs :)
22+
#
1923
# Revision 1.2 2001/07/28 06:43:02 richard
2024
# Multipart message class has the getPart method now. Added some tests for it.
2125
#

test/test_mailsplit.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# $Id: test_mailsplit.py,v 1.1 2001-08-03 07:18:22 richard Exp $
2+
3+
import unittest, cStringIO
4+
5+
from roundup.mailgw import parseContent
6+
7+
class MailsplitTestCase(unittest.TestCase):
8+
def testPreComment(self):
9+
s = '''
10+
i will have to think about this later...not a 1.0.4 thing I don't
11+
think...too much thought involved!
12+
13+
14+
> Hey, is there a reason why we can't just leave shop_domain and
15+
> secure_domain blank and user the REQUEST.whatever_the_machine_name_is
16+
> for most users? And then specify that if you're going to have
17+
> secure_domain, you've got to have shop_domain too?
18+
>
19+
> -------
20+
> nosy: richard, tejay
21+
> ___________________________
22+
> Roundup issue tracker
23+
24+
> http://dirk.adroit/cgi-bin/roundup.cgi/issue_tracker/
25+
26+
--
27+
Terry Kerr ([email protected])
28+
Bizar Software Pty Ltd (www.bizarsoftware.com.au)
29+
Phone: +61 3 9563 4461
30+
Fax: +61 3 9563 3856
31+
ICQ: 79303381
32+
'''
33+
summary, content = parseContent(s)
34+
print '\n====\n', summary
35+
print '====', content
36+
print '===='
37+
38+
def testPostComment(self):
39+
s = '''
40+
41+
> Hey, is there a reason why we can't just leave shop_domain and
42+
> secure_domain blank and user the REQUEST.whatever_the_machine_name_is
43+
> for most users? And then specify that if you're going to have
44+
> secure_domain, you've got to have shop_domain too?
45+
>
46+
> -------
47+
> nosy: richard, tejay
48+
> ___________________________
49+
> Roundup issue tracker
50+
51+
> http://dirk.adroit/cgi-bin/roundup.cgi/issue_tracker/
52+
53+
i will have to think about this later...not a 1.0.4 thing I don't
54+
think...too much thought involved!
55+
56+
--
57+
Terry Kerr ([email protected])
58+
Bizar Software Pty Ltd (www.bizarsoftware.com.au)
59+
Phone: +61 3 9563 4461
60+
Fax: +61 3 9563 3856
61+
ICQ: 79303381
62+
'''
63+
summary, content = parseContent(s)
64+
print '\n====\n', summary
65+
print '====', content
66+
print '===='
67+
68+
def testSimple(self):
69+
s = '''testing'''
70+
summary, content = parseContent(s)
71+
print '\n====\n', summary
72+
print '====', content
73+
print '===='
74+
75+
def testEmpty(self):
76+
s = ''
77+
summary, content = parseContent(s)
78+
print '\n====\n', summary
79+
print '====', content
80+
print '===='
81+
82+
def suite():
83+
return unittest.makeSuite(MailsplitTestCase, 'test')
84+
85+
86+
#
87+
# $Log: not supported by cvs2svn $
88+
#
89+
#
90+
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)