Ignore:
Timestamp:
06/30/06 09:55:09 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

  • Fixed description bug
File:
1 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/email2trac.py.in

    r89 r90  
    408408
    409409                body_text = self.get_body_text(msg)
    410                 tkt['description'] = ''
    411 
    412                 # Insert ticket in database with empty description
    413                 #
     410                body_text = ('\r\n'.join(body_text.splitlines()))
     411
     412                # A patch so that the web-interface will not update the description
     413                # field of a ticket
     414                #
     415                tkt['description'] = u'email2trac:%s\r\n{{{\r\n%s\r\n}}}' \
     416                        %(head, body_text)
     417
    414418                when = int(time.time())
    415419                if self.VERSION == 0.8:
    416                         tkt['id'] = tkt.insert(self.db)
    417                 else:
    418                         tkt['id'] = tkt.insert()
     420                        ticket_id = tkt.insert(self.db)
     421                else:
     422                        ticket_id = tkt.insert()
     423
     424                changed = False
     425                comment = ''
     426
     427                # Rewrite the description if we have mailto enabled
     428                #
     429                if self.MAILTO:
     430                        mailto = self.html_mailto_link(self.to_unicode(msg['subject']), ticket_id, body_text)
     431                        tkt['description'] = u'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
     432                        comment = '\nadded mailto line\n'
     433                        changed = True
    419434
    420435                n =  self.attachments(msg, tkt)
    421436                if n:
    422                         attach_str = '\nThis message has %d attachment(s)\n' %(n)
    423                 else:
    424                         attach_str = ''
    425 
    426                 # Always update the description else we get two emails one for the new ticket
    427                 # and for the attachments. It is an ugly hack but with trac you can not add
    428                 # attachments without an ticket id
    429                 #
    430                 mailto = ''
    431                 if self.MAILTO:
    432                         mailto = self.html_mailto_link(self.to_unicode(msg['subject']), tkt['id'], body_text)
    433                         tkt['description'] = '%s%s%s\n{{{\n%s\n}}}\n' %(head, attach_str, mailto, body_text)
    434                         comment = 'Added mailto: link + description'
    435                 else:
    436                         tkt['description'] = '%s%s\n{{{\n%s\n}}}\n' %(head, attach_str, body_text)
    437                         comment = 'Added description'
    438 
    439                 # Save the real description and other changes
    440                 #
    441                 if self.VERSION  == 0.8:
    442                         tkt.save_changes(self.db, self.author, comment, when)
    443                 else:
    444                         tkt.save_changes(self.author, comment, when)
     437                        comment = '%s\nThis message has %d attachment(s)\n' %(comment, n)
     438                        changed = True
     439
     440                if changed:
     441                        if self.VERSION  == 0.8:
     442                                tkt.save_changes(self.db, self.author, comment)
     443                        else:
     444                                tkt.save_changes(self.author, comment)
     445
     446                #print tkt.get_changelog(self.db, when)
    445447
    446448                if self.notification:
    447                         self.notify(tkt, True, when)
     449                        self.notify(tkt, True)
     450                        #self.notify(tkt, False)
    448451
    449452        def parse(self, fp):
     
    478481                """
    479482                has_description = 0
    480                 ubody_text = '\n{{{\nNo plain text message\n}}}\n'
     483                ubody_text = '\r\n{{{\nNo plain text message\n}}}\r\n'
    481484                for part in msg.walk():
    482485
     
    489492                                # Try to decode, if fails then do not decode
    490493                                #
    491                                 body_text = part.get_payload(decode=1)         
     494                                body_text = part.get_payload(decode=1)
    492495                                if not body_text:                       
    493                                         body_text = part.get_payload(decode=0) 
     496                                        body_text = part.get_payload(decode=0)
    494497
    495498                                # Get contents charset (iso-8859-15 if not defined in mail headers)
     
    497500                                #
    498501                                charset = part.get_content_charset('iso-8859-15')
    499 
    500502                                try:
    501503                                        temp = unicode(body_text, charset)
     
    503505                                        temp = unicode(body_text, 'iso-8859-15')
    504506
    505                                 #ubody_text = unicode(body_text, charset).encode('utf-8')
    506507                                ubody_text = temp.encode('utf-8')
    507508
    508509                        elif part.get_content_type() == 'text/html':
    509                                 ubody_text = '\n\n(see attachment for HTML mail message)\n'
    510 
    511                         else:
    512                                 ubody_text = '\n\n(see attachment for message)\n'
     510                                ubody_text = '\r\n(see attachment for HTML mail message)\r\n'
     511
     512                        else:
     513                                ubody_text = '\r\n(see attachment for message)\r\n'
    513514
    514515                        has_description = 1
     
    516517
    517518                if not has_description:
    518                         ubody_text = '\n\n(see attachment for message)\n'
     519                        ubody_text = '\r\n(see attachment for message)\r\n'
    519520
    520521                return ubody_text
     
    563564                           )
    564565
    565                 str = '\n{{{\n#!html\n<a href="%s">Reply to: %s</a>\n}}}\n' %(str, author)
     566                str = '\r\n{{{\r\n#!html\r\n<a href="%s">Reply to: %s</a>\r\n}}}\r\n' %(str, author)
    566567
    567568                return str
Note: See TracChangeset for help on using the changeset viewer.