Ignore:
Timestamp:
12/04/06 12:10:41 (17 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

  • Fixed some unicode problem that crashes trac
File:
1 edited

Legend:

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

    r138 r139  
    182182                        self.STRIP_SIGNATURE = 0
    183183
    184 
    185184        # X-Spam-Score: *** (3.255) BAYES_50,DNS_FROM_AHBL_RHSBL,HTML_
    186185        # Note if Spam_level then '*' are included
     
    198197                return self.get_config('ticket', 'default_component')
    199198
    200         def to_unicode(self, str):
     199        def email_to_unicode(self, message_str):
    201200                """
    202201                Email has 7 bit ASCII code, convert it to unicode with the charset
     
    204203                understands it.
    205204                """
    206                 results =  email.Header.decode_header(str)
     205                results =  email.Header.decode_header(message_str)
    207206                str = None
    208207                for text,format in results:
     
    210209                                try:
    211210                                        temp = unicode(text, format)
    212                                 except (UnicodeError,LookupError):
     211                                except UnicodeError, detail:
    213212                                        # This always works
    214213                                        #
    215214                                        temp = unicode(text, 'iso-8859-15')
     215                                except LookupError, detail:
     216                                        #text = 'ERROR: Could not find charset: %s, please install' %format
     217                                        #temp = unicode(text, 'iso-8859-15')
     218                                        temp = message_str
     219                                       
    216220                        else:
    217221                                temp = string.strip(text)
     
    223227                                str = '%s' %temp
    224228
    225                 str = str.encode('utf-8')
     229                #str = str.encode('utf-8')
    226230                return str
    227231
     
    267271                        str = "%s'''Cc:''' %s [[BR]]" % (str, m['Cc'])
    268272
    269                 #return  self.to_unicode(str)
    270                 return  util.text.to_unicode(str)
     273                return  self.email_to_unicode(str)
    271274
    272275
     
    300303                        self.email_field = users[0]
    301304                else:
    302                         #self.email_field =  self.to_unicode(message['from'])
    303                         self.email_field =  util.text.to_unicode(message['from'])
     305                        self.email_field =  self.email_to_unicode(message['from'])
    304306
    305307        def set_reply_fields(self, ticket, message):
     
    335337
    336338                        if mail_list:
    337                                 #ticket['cc'] = self.to_unicode(mail_list)
    338                                 ticket['cc'] = util.text.to_unicode(mail_list)
     339                                ticket['cc'] = self.email_to_unicode(mail_list)
    339340
    340341        def save_email_for_debug(self, message, tempfile=False):
     
    362363                        return False
    363364                else:
    364                         #subject  = self.to_unicode(m['Subject'])
    365                         subject  = util.text.to_unicode(m['Subject'])
     365                        subject  = self.email_to_unicode(m['Subject'])
    366366
    367367                TICKET_RE = re.compile(r"""
     
    423423                        tkt['summary'] = u'(geen subject)'
    424424                else:
    425                         #tkt['summary'] = self.to_unicode(msg['Subject'])
    426                         tkt['summary'] = util.text.to_unicode(msg['Subject'])
     425                        tkt['summary'] = self.email_to_unicode(msg['Subject'])
    427426
    428427
     
    470469                        changed = True
    471470                        comment = '\nadded mailto line\n'
    472                         #mailto = self.html_mailto_link(self.to_unicode(msg['subject']), ticket_id, body_text)
    473                         mailto = self.html_mailto_link(util.text.to_unicode(msg['subject']), ticket_id, body_text)
    474                         #tkt['description'] = 'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
     471                        mailto = self.html_mailto_link(self.email_to_unicode(msg['subject']), ticket_id, body_text)
    475472                        tkt['description'] = 'email2trac:%s%s\r\n%s' %(head, mailto, body_text)
    476473
     
    569566
    570567                                except LookupError, detail:
    571                                         ubody_text = body_text
    572                                         encoding = False
     568                                        ubody_text = 'ERROR: Could not find charset: %s, please install' %(charset)
    573569
    574570                        elif part.get_content_type() == 'text/html':
     
    632628                        author = self.email_addr
    633629                else:   
    634                         #author = self.to_unicode(self.author)
    635                         author = util.text.to_unicode(self.author)
     630                        author = self.email_to_unicode(self.author)
    636631
    637632                # Must find a fix
     
    681676                                filename = '%s%s' % (filename, ext)
    682677                        else:
    683                                 #filename = self.to_unicode(filename)
    684                                 filename = util.text.to_unicode(filename)
     678                                filename = self.email_to_unicode(filename)
    685679
    686680                        # From the trac code
     
    746740                                if not update:
    747741                                        att.author = self.author
    748                                         #att.description = self.to_unicode('Added by email2trac')
    749                                         att.description = util.text.to_unicode('Added by email2trac')
     742                                        att.description = self.email_to_unicode('Added by email2trac')
    750743
    751744                                att.insert(url_filename, fd, filesize)
     
    877870                        from trac.web.href import Href
    878871                        from trac import util
     872                        #
     873                        # return  util.text.to_unicode(str)
     874                        #
    879875                        # see http://projects.edgewall.com/trac/changeset/2799
    880876                        from trac.ticket.notification import TicketNotifyEmail
Note: See TracChangeset for help on using the changeset viewer.