Mercurial > p > roundup > code
diff roundup/mailgw.py @ 198:eda506860b32
Implemented correct mail splitting (was taking a shortcut).
Added unit tests. Also snips signatures now too.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 03 Aug 2001 07:18:22 +0000 |
| parents | c580555a6508 |
| children | d702ac2ceedb |
line wrap: on
line diff
--- a/roundup/mailgw.py Fri Aug 03 02:51:06 2001 +0000 +++ b/roundup/mailgw.py Fri Aug 03 07:18:22 2001 +0000 @@ -55,7 +55,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.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 @@ 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 @@ 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 :) #
