Changeset 100 for emailtotracscript


Ignore:
Timestamp:
07/14/06 11:02:43 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

  • Fixed the unicode/encode problems
Location:
emailtotracscript/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/ChangeLog

    r99 r100  
    1616             mails with fake attachments.
    1717           - It works now for versions higher then 0.8
     18
     19        * Finally understand the unicode/encode functions and hopefully
     20          fixed the errors.
     21          Fixed by: Bas van der Vlies
    1822       
    19232006-07-06
  • emailtotracscript/trunk/debian/changelog

    r99 r100  
     1email2trac (0.7.6-3) stable; urgency=low
     2
     3  * Hopefully now fixed the unicode/encode problems
     4
     5 -- Bas van der Vlies <basv@sara.nl>  Fri, 14 Jul 2006 10:59:25 +0200
     6
    17email2trac (0.7.6-2) stable; urgency=low
    28
  • emailtotracscript/trunk/email2trac.py.in

    r98 r100  
    198198                                        #
    199199                                        temp = unicode(text, 'iso-8859-15')
    200                                        
    201                                 temp =  temp.encode('utf-8')
    202200                        else:
    203201                                temp = string.strip(text)
     
    205203
    206204                        if str:
    207                                 str = u'%s %s' %(str, temp)
     205                                str = '%s %s' %(str, temp)
    208206                        else:
    209                                 str = u'%s' %temp
     207                                str = '%s' %temp
    210208
    211209                str = str.encode('utf-8')
     
    423421
    424422                body_text = self.get_body_text(msg)
    425                 body_text = ('\r\n'.join(body_text.splitlines()))
    426 
    427                 # A patch so that the web-interface will not update the description
    428                 # field of a ticket
    429                 #
    430                 tkt['description'] = u'email2trac:%s\r\n{{{\r\n%s\r\n}}}' \
     423
     424                tkt['description'] = 'email2trac:%s\r\n{{{\r\n%s\r\n}}}' \
    431425                        %(head, body_text)
    432426
     
    444438                #
    445439                if self.MAILTO:
     440                        changed = True
     441                        comment = '\nadded mailto line\n'
    446442                        mailto = self.html_mailto_link(self.to_unicode(msg['subject']), ticket_id, body_text)
    447                         tkt['description'] = u'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
    448                         comment = '\nadded mailto line\n'
    449                         changed = True
     443                        tkt['description'] = 'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
    450444
    451445                n =  self.attachments(msg, tkt)
    452446                if n:
     447                        changed = True
    453448                        comment = '%s\nThis message has %d attachment(s)\n' %(comment, n)
    454                         changed = True
    455449
    456450                if changed:
     
    499493                """
    500494                has_description = 0
     495                encoding = True
    501496                ubody_text = u'\r\n{{{\nNo plain text message\n}}}\r\n'
    502497                for part in msg.walk():
     
    515510
    516511                                # Get contents charset (iso-8859-15 if not defined in mail headers)
    517                                 # UTF-8 encode body_text
    518512                                #
    519                                 charset = part.get_content_charset('iso-8859-15')
     513                                charset = part.get_content_charset()
    520514                                try:
    521515                                        ubody_text = unicode(body_text, charset)
    522                                 except (UnicodeError,LookupError):
     516
     517                                except UnicodeError, detail:
    523518                                        ubody_text = unicode(body_text, 'iso-8859-15')
    524519
     520                                except LookupError, detail:
     521                                        ubody_text = body_text
     522                                        encoding = False
     523
    525524                        elif part.get_content_type() == 'text/html':
    526                                 ubody_text = u'\r\n(see attachment for HTML mail message)\r\n'
     525                                ubody_text = '\r\n(see attachment for HTML mail message)\r\n'
    527526
    528527                        else:
    529                                 ubody_text = u'\r\n(see attachment for message)\r\n'
     528                                ubody_text = '\r\n(see attachment for message)\r\n'
    530529
    531530                        has_description = 1
     
    533532
    534533                if not has_description:
    535                         ubody_text = u'\r\n(see attachment for message)\r\n'
    536 
    537                 return ubody_text.encode('utf-8')
     534                        ubody_text = '\r\n(see attachment for message)\r\n'
     535
     536                # A patch so that the web-interface will not update the description
     537                # field of a ticket
     538                #
     539                ubody_text = ('\r\n'.join(ubody_text.splitlines()))
     540
     541                #  If we can unicode it try to encode it for trac
     542                #  else we a lot of garbage
     543                #
     544                if encoding:
     545                        ubody_text = ubody_text.encode('utf-8')
     546
     547                return ubody_text
    538548
    539549        def notify(self, tkt , new=True, modtime=0):
Note: See TracChangeset for help on using the changeset viewer.