From c0ba368ce575b350fd95ce1d9e876a224e57a7c0 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 3 Aug 2001 07:18:22 +0000 Subject: [PATCH] Implemented correct mail splitting (was taking a shortcut). Added unit tests. Also snips signatures now too. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@204 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 8 +++- README.txt | 2 - roundup/mailgw.py | 47 ++++++++++++++++------ test/__init__.py | 8 +++- test/test_mailsplit.py | 90 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 test/test_mailsplit.py diff --git a/CHANGES.txt b/CHANGES.txt index 938a160..27c6f35 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,10 +1,14 @@ This file contains the changes to the Roundup system over time. The entries are given with the most recent entry first. -2001-08-?? - 0.2.5 -Features: +2001-08-03 - 0.2.5 +Note: + . The bsddb3 module has a bug that renders it non-functional. Users should + select the anydbm or bsddb backend instead. Fixed: + . Python 2.0 does not contain the unittest module. The setup.py module now + checks for unittest before attempting to run the unit tests. 2001-08-03 - 0.2.4 diff --git a/README.txt b/README.txt index e09fbd1..ea90cb8 100644 --- a/README.txt +++ b/README.txt @@ -78,9 +78,7 @@ hyperdb: roundupdb: . split the file storage into multiple dirs? roundup-mailgw: - . do the "sectioning" stuff properly (ie. as it's documented) . errors as attachments - . snip signatures? roundup-server: . check the source file timestamps before reloading cgi_client diff --git a/roundup/mailgw.py b/roundup/mailgw.py index e6d66cf..8c181aa 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -55,7 +55,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.6 2001-08-01 04:24:21 richard Exp $ +$Id: mailgw.py,v 1.7 2001-08-03 07:18:22 richard Exp $ ''' @@ -243,17 +243,7 @@ class MailGW: else: content = message.fp.read() - # extract out the summary from the message - summary = [] - for line in content.split('\n'): - line = line.strip() - if summary and not line: - break - if not line: - summary.append('') - elif line[0] not in '>|': - summary.append(line) - summary = '\n'.join(summary) + summary, content = parseContent(content) # handle the files files = [] @@ -296,8 +286,41 @@ class MailGW: props['nosy'].sort() nodeid = cl.create(**props) +def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), + eol=re.compile(r'[\r\n]+'), signature=re.compile(r'^[>|\s]*[-_]+\s*$')): + ''' The message body is divided into sections by blank lines. + Sections where the second and all subsequent lines begin with a ">" or "|" + character are considered "quoting sections". The first line of the first + non-quoting section becomes the summary of the message. + ''' + sections = blank_line.split(content) + # extract out the summary from the message + summary = '' + l = [] + print sections + for section in sections: + section = section.strip() + if not section: + continue + lines = eol.split(section) + if lines[0] and lines[0][0] in '>|': + continue + if len(lines) > 1 and lines[1] and lines[1][0] in '>|': + continue + if not summary: + summary = lines[0] + l.append(section) + continue + if signature.match(lines[0]): + break + l.append(section) + return summary, '\n'.join(l) + # # $Log: not supported by cvs2svn $ +# Revision 1.6 2001/08/01 04:24:21 richard +# mailgw was assuming certain properties existed on the issues being created. +# # Revision 1.5 2001/07/29 07:01:39 richard # Added vim command to all source so that we don't get no steenkin' tabs :) # diff --git a/test/__init__.py b/test/__init__.py index 7e841b3..5a9df6f 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,8 +1,8 @@ -# $Id: __init__.py,v 1.3 2001-07-29 07:01:39 richard Exp $ +# $Id: __init__.py,v 1.4 2001-08-03 07:18:22 richard Exp $ import unittest -import test_dates, test_schema, test_db, test_multipart +import test_dates, test_schema, test_db, test_multipart, test_mailsplit def go(): suite = unittest.TestSuite(( @@ -10,12 +10,16 @@ def go(): test_schema.suite(), test_db.suite(), test_multipart.suite(), + test_mailsplit.suite(), )) runner = unittest.TextTestRunner() runner.run(suite) # # $Log: not supported by cvs2svn $ +# Revision 1.3 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.2 2001/07/28 06:43:02 richard # Multipart message class has the getPart method now. Added some tests for it. # diff --git a/test/test_mailsplit.py b/test/test_mailsplit.py new file mode 100644 index 0000000..6b178e0 --- /dev/null +++ b/test/test_mailsplit.py @@ -0,0 +1,90 @@ +# $Id: test_mailsplit.py,v 1.1 2001-08-03 07:18:22 richard Exp $ + +import unittest, cStringIO + +from roundup.mailgw import parseContent + +class MailsplitTestCase(unittest.TestCase): + def testPreComment(self): + s = ''' +i will have to think about this later...not a 1.0.4 thing I don't +think...too much thought involved! + +issue_tracker@bizarsoftware.com.au wrote: +> Hey, is there a reason why we can't just leave shop_domain and +> secure_domain blank and user the REQUEST.whatever_the_machine_name_is +> for most users? And then specify that if you're going to have +> secure_domain, you've got to have shop_domain too? +> +> ------- +> nosy: richard, tejay +> ___________________________ +> Roundup issue tracker +> issue_tracker@bizarsoftware.com.au +> http://dirk.adroit/cgi-bin/roundup.cgi/issue_tracker/ + +-- +Terry Kerr (terry@bizarsoftware.com.au) +Bizar Software Pty Ltd (www.bizarsoftware.com.au) +Phone: +61 3 9563 4461 +Fax: +61 3 9563 3856 +ICQ: 79303381 +''' + summary, content = parseContent(s) + print '\n====\n', summary + print '====', content + print '====' + + def testPostComment(self): + s = ''' +issue_tracker@bizarsoftware.com.au wrote: +> Hey, is there a reason why we can't just leave shop_domain and +> secure_domain blank and user the REQUEST.whatever_the_machine_name_is +> for most users? And then specify that if you're going to have +> secure_domain, you've got to have shop_domain too? +> +> ------- +> nosy: richard, tejay +> ___________________________ +> Roundup issue tracker +> issue_tracker@bizarsoftware.com.au +> http://dirk.adroit/cgi-bin/roundup.cgi/issue_tracker/ + +i will have to think about this later...not a 1.0.4 thing I don't +think...too much thought involved! + +-- +Terry Kerr (terry@bizarsoftware.com.au) +Bizar Software Pty Ltd (www.bizarsoftware.com.au) +Phone: +61 3 9563 4461 +Fax: +61 3 9563 3856 +ICQ: 79303381 +''' + summary, content = parseContent(s) + print '\n====\n', summary + print '====', content + print '====' + + def testSimple(self): + s = '''testing''' + summary, content = parseContent(s) + print '\n====\n', summary + print '====', content + print '====' + + def testEmpty(self): + s = '' + summary, content = parseContent(s) + print '\n====\n', summary + print '====', content + print '====' + +def suite(): + return unittest.makeSuite(MailsplitTestCase, 'test') + + +# +# $Log: not supported by cvs2svn $ +# +# +# vim: set filetype=python ts=4 sw=4 et si -- 2.30.2