Changeset 555
- Timestamp:
- 08/12/11 16:33:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r554 r555 400 400 ########## DEBUG functions ########################################################### 401 401 402 def debug_body(self, message_body, temp orary_file=False):403 if temporary_file:404 (fd, body_file) = tempfile.mkstemp('.body_email2trac')405 fx = os.fdopen(fd, 'wb')406 else: 407 body_file = os.path.join(self.parameters.tmpdir, 'body.txt')408 402 def debug_body(self, message_body, temp_file): 403 """ 404 """ 405 self.logger.debug('function debug_body:') 406 407 body_file = "%s.body" %(temp_file) 408 fx = open(body_file, 'wb') 409 409 410 410 if self.parameters.dry_run: 411 print 'DRY-RUN: not saving body to %s' %(body_file)411 self.logger.debug('DRY-RUN: not saving body to %s' %(body_file)) 412 412 return 413 413 414 print 'writing body to %s' %(body_file)414 self.logger.debug('writing body to %s' %(body_file)) 415 415 if not message_body: 416 416 message_body = '(None)' … … 425 425 pass 426 426 427 def debug_attachments(self, message_parts ):427 def debug_attachments(self, message_parts, temp_file): 428 428 """ 429 429 """ … … 439 439 440 440 (original, filename, part) = item 441 self.logger.debug('\t part%d: Content-Type: %s' % (n, part.get_content_type()) ) 442 443 dummy_filename, ext = os.path.splitext(filename) 441 444 442 445 n = n + 1 443 print 'part%d: Content-Type: %s' % (n, part.get_content_type()) 444 445 s = 'part%d: filename: %s' %(n, filename) 446 part_name = 'part%d%s' %(n, ext) 447 part_file = "%s.%s" %(temp_file, part_name) 448 449 s = 'writing %s: filename: %s' %(part_file, filename) 446 450 self.print_unicode(s) 447 448 ## Forbidden chars 449 # 450 filename = filename.replace('\\', '_') 451 filename = filename.replace('/', '_') 452 filename = filename + '.att_email2trac' 453 454 part_file = os.path.join(self.parameters.tmpdir, filename) 455 s = 'writing part%d (%s)' % (n,part_file) 456 self.print_unicode(s) 451 452 ## Forbidden chars, just write part files instead of names 453 # 454 #filename = filename.replace('\\', '_') 455 #filename = filename.replace('/', '_') 456 #filename = filename + '.att_email2trac' 457 # part_file = os.path.join(self.parameters.tmpdir, filename) 458 #part_file = util.text.unicode_quote(part_file) 459 #self.print_unicode(part_file) 457 460 458 461 if self.parameters.dry_run: 459 462 print 'DRY_RUN: NOT saving attachments' 460 463 continue 461 462 # trac error with long filenames support463 #part_file = util.text.unicode_quote(part_file)464 #part_file = repr(part_file)465 464 466 465 fx = open(part_file, 'wb') … … 481 480 482 481 if self.parameters.dry_run: 483 print 'DRY_RUN: NOT saving email message'482 self.logger.debug('DRY_RUN: NOT saving email message') 484 483 return 485 484 486 485 if create_tempfile: 487 (fd, msg_file) = tempfile.mkstemp('.%s.email2trac' %project_name)486 (fd, tmp_file) = tempfile.mkstemp('.%s.email2trac' %project_name) 488 487 fx = os.fdopen(fd, 'wb') 489 488 else: 490 msg_file = os.path.join(self.parameters.tmpdir, 'msg.%s.email2trac' %project_name)491 fx = open( msg_file, 'wb')492 493 494 print 'saving email to %s' %(msg_file)489 tmp_file = os.path.join(self.parameters.tmpdir, 'msg.%s.email2trac' %project_name) 490 fx = open(tmp_file, 'wb') 491 492 493 self.logger.debug('saving email to %s' %(tmp_file)) 495 494 fx.write('%s' % message) 496 495 fx.close() 497 496 498 497 try: 499 os.chmod( msg_file,S_IRWXU|S_IRWXG|S_IRWXO)498 os.chmod(tmp_file, S_IRWXU|S_IRWXG|S_IRWXO) 500 499 except OSError: 501 500 pass … … 504 503 message_parts = self.unique_attachment_names(message_parts) 505 504 body_text = self.get_body_text(message_parts) 506 self.debug_body(body_text, True)507 self.debug_attachments(message_parts )505 self.debug_body(body_text, tmp_file) 506 self.debug_attachments(message_parts, tmp_file) 508 507 509 508 ########## Conversion functions ########################################################### … … 1246 1245 1247 1246 if self.parameters.dry_run: 1248 print "DRY_RUN: no attachments attached to tickets"1247 self.logger.debug("DRY_RUN: no attachments attached to tickets") 1249 1248 return '' 1250 1249
Note: See TracChangeset
for help on using the changeset viewer.