Changeset 77 for emailtotracscript/trunk/email2trac.py.in
- Timestamp:
- 05/26/06 14:57:10 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emailtotracscript/trunk/email2trac.py.in
r76 r77 341 341 body_text = '{{{\n%s\n}}}' %body_text 342 342 343 # Get current time 344 # 345 when = int(time.time()) 346 343 347 if self.VERSION == 0.8: 344 tkt.save_changes(self.db, self.author, body_text) 345 else: 346 # def save_changes(self, author, comment, when=0, self.db=None): 347 tkt.save_changes(self.author, body_text) 348 348 tkt.save_changes(self.db, self.author, body_text, when) 349 else: 350 tkt.save_changes(self.author, body_text, when) 349 351 350 352 self.attachments(m, tkt) 353 351 354 if self.notification: 352 self.notify(tkt, False )355 self.notify(tkt, False, when) 353 356 354 357 return True 355 358 356 359 357 def parse(self, fp): 358 msg = email.message_from_file(fp) 359 if not msg: 360 return 361 362 if self.DEBUG > 1: # save the entire e-mail message text 363 self.save_email_for_debug(msg) 364 self.debug_attachments(msg) 365 366 self.db = self.env.get_db_cnx() 367 self.get_author_emailaddrs(msg) 368 369 if self.get_config('notification', 'smtp_enabled') in ['true']: 370 self.notification = 1 371 else: 372 self.notification = 0 373 374 # Must we update existing tickets 375 # 376 if self.TICKET_UPDATE > 0: 377 if self.ticket_update(msg): 378 return True 379 360 def new(self, msg): 361 """ 362 Create a new ticket 363 """ 380 364 tkt = Ticket(self.env) 381 365 tkt['status'] = 'new' … … 419 403 420 404 body_text = self.get_body_text(msg) 421 tkt['description'] = '\n{{{\n%s\n}}}\n' %(body_text) 422 423 # Insert ticket in database 424 # 405 tkt['description'] = '' 406 407 # Insert ticket in database with empty description 408 # 409 when = int(time.time()) 425 410 if self.VERSION == 0.8: 426 411 tkt['id'] = tkt.insert(self.db) … … 428 413 tkt['id'] = tkt.insert() 429 414 430 # Else we do no have a ticket id for the subject line 415 n = self.attachments(msg, tkt) 416 if n: 417 attach_str = '\nThis message has %d attachment(s)\n' %(n) 418 else: 419 attach_str = '' 420 421 # Always update the description else we get two emails one for the new ticket 422 # and for the attachments. It is an ugly hack but with trac you can not add 423 # attachments without an ticket id 431 424 # 432 425 mailto = '' 433 426 if self.MAILTO: 434 427 mailto = self.html_mailto_link(self.to_unicode(msg['subject']), tkt['id'], body_text) 435 tkt['description'] = '%s%s\n{{{\n%s\n}}}\n' %(head, mailto, body_text) 436 tkt.save_changes(self.db, self.author, "") 437 438 self.attachments(msg, tkt) 428 tkt['description'] = '%s%s%s\n{{{\n%s\n}}}\n' %(head, attach_str, mailto, body_text) 429 comment = 'Added mailto: link + description' 430 else: 431 tkt['description'] = '%s%s\n{{{\n%s\n}}}\n' %(head, attach_str, body_text) 432 comment = 'Added description' 433 434 # Save the real description and other changes 435 # 436 if self.VERSION == 0.8: 437 tkt.save_changes(self.db, self.author, comment, when) 438 else: 439 tkt.save_changes(self.author, comment, when) 440 439 441 if self.notification: 440 self.notify(tkt) 442 self.notify(tkt, True, when) 443 444 def parse(self, fp): 445 m = email.message_from_file(fp) 446 if not m: 447 return 448 449 if self.DEBUG > 1: # save the entire e-mail message text 450 self.save_email_for_debug(m) 451 self.debug_attachments(m) 452 453 self.db = self.env.get_db_cnx() 454 self.get_author_emailaddrs(m) 455 456 if self.get_config('notification', 'smtp_enabled') in ['true']: 457 self.notification = 1 458 else: 459 self.notification = 0 460 461 # Must we update existing tickets 462 # 463 if self.TICKET_UPDATE > 0: 464 if self.ticket_update(m): 465 return True 466 467 self.new(m) 441 468 442 469 def get_body_text(self, msg): … … 481 508 return ubody_text 482 509 483 def notify(self, tkt , new=True ):510 def notify(self, tkt , new=True, modtime=0): 484 511 try: 485 512 # create false {abs_}href properties, to trick Notify() … … 492 519 tn.template_name = self.notify_template; 493 520 494 tn.notify(tkt, new )521 tn.notify(tkt, new, modtime) 495 522 496 523 except Exception, e: … … 530 557 531 558 count = 0 532 first = 0 559 first = 0 560 number = 0 533 561 for part in message.walk(): 534 562 if part.get_content_maintype() == 'multipart': # multipart/* is just a container … … 541 569 542 570 filename = part.get_filename() 571 count = count + 1 543 572 if not filename: 544 count = count+ 1545 filename = 'part%04d' % count573 number = number + 1 574 filename = 'part%04d' % number 546 575 547 576 ext = mimetypes.guess_extension(part.get_content_type()) … … 607 636 att.insert(url_filename, fd, filesize) 608 637 fd.close() 638 639 # Return how many attachments 640 # 641 return count 609 642 610 643
Note: See TracChangeset
for help on using the changeset viewer.