Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 197:c610319d11aa | 198:eda506860b32 |
|---|---|
| 53 set() method to add the message to the item's spool; in the second case we | 53 set() method to add the message to the item's spool; in the second case we |
| 54 are calling the create() method to create a new node). If an auditor raises | 54 are calling the create() method to create a new node). If an auditor raises |
| 55 an exception, the original message is bounced back to the sender with the | 55 an exception, the original message is bounced back to the sender with the |
| 56 explanatory message given in the exception. | 56 explanatory message given in the exception. |
| 57 | 57 |
| 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 $ |
| 59 ''' | 59 ''' |
| 60 | 60 |
| 61 | 61 |
| 62 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri | 62 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri |
| 63 import traceback | 63 import traceback |
| 241 raise ValueError, 'No text/plain part found' | 241 raise ValueError, 'No text/plain part found' |
| 242 | 242 |
| 243 else: | 243 else: |
| 244 content = message.fp.read() | 244 content = message.fp.read() |
| 245 | 245 |
| 246 # extract out the summary from the message | 246 summary, content = parseContent(content) |
| 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) | |
| 257 | 247 |
| 258 # handle the files | 248 # handle the files |
| 259 files = [] | 249 files = [] |
| 260 for (name, type, data) in attachments: | 250 for (name, type, data) in attachments: |
| 261 files.append(self.db.file.create(type=type, name=name, | 251 files.append(self.db.file.create(type=type, name=name, |
| 294 props['nosy'] = recipients[:] | 284 props['nosy'] = recipients[:] |
| 295 props['nosy'].append(author) | 285 props['nosy'].append(author) |
| 296 props['nosy'].sort() | 286 props['nosy'].sort() |
| 297 nodeid = cl.create(**props) | 287 nodeid = cl.create(**props) |
| 298 | 288 |
| 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 | |
| 299 # | 319 # |
| 300 # $Log: not supported by cvs2svn $ | 320 # $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 # | |
| 301 # Revision 1.5 2001/07/29 07:01:39 richard | 324 # Revision 1.5 2001/07/29 07:01:39 richard |
| 302 # Added vim command to all source so that we don't get no steenkin' tabs :) | 325 # Added vim command to all source so that we don't get no steenkin' tabs :) |
| 303 # | 326 # |
| 304 # Revision 1.4 2001/07/28 06:43:02 richard | 327 # Revision 1.4 2001/07/28 06:43:02 richard |
| 305 # Multipart message class has the getPart method now. Added some tests for it. | 328 # Multipart message class has the getPart method now. Added some tests for it. |
