Changeset 96 for emailtotracscript/trunk


Ignore:
Timestamp:
07/13/06 08:23:32 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

-Try to fix some unicode errors, added some debug code

Location:
emailtotracscript/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/debian/changelog

    r92 r96  
     1email2trac (0.7.4-2) stable; urgency=low
     2
     3  * New bug fixes for unicode support
     4
     5 -- root <root@subtrac.sara.nl>  Tue, 11 Jul 2006 14:52:58 +0200
     6
     7email2trac (0.7.4-1) stable; urgency=low
     8
     9  * Unicode bug fixes
     10
     11 -- root <root@subtrac.sara.nl>  Tue, 11 Jul 2006 09:24:00 +0200
     12
    113email2trac (0.7.3-7) stable; urgency=low
    214
  • emailtotracscript/trunk/email2trac.py.in

    r92 r96  
    8888from stat import *
    8989import mimetypes
    90 
    91 # Fix some errors
    92 #import codecs
    93 
     90import syslog
     91import traceback
     92
     93
     94# Some global variables
     95#
    9496trac_default_version = 0.9
     97m = None
     98
    9599
    96100class TicketEmailParser(object):
     
    201205
    202206                        if str:
    203                                 str = '%s %s' %(str, temp)
     207                                str = u'%s %s' %(str, temp)
    204208                        else:
    205                                 str = temp
    206 
     209                                str = u'%s' %temp
     210
     211                str = str.encode('utf-8')
    207212                return str
    208213
     
    306311                        for name,mail in addrs:
    307312                                        try:
    308                                                 ticket['cc'] = '%s,%s' %(ticket['cc'], mail)
     313                                                mail_list = '%s,%s' %(mail_list, mail)
    309314                                        except:
    310                                                 ticket['cc'] = mail
    311 
    312         def save_email_for_debug(self, message):
    313                 msg_file = '/var/tmp/msg.txt'
     315                                                mail_list = mail
     316
     317                        ticket['cc'] = self.to_unicode(mail_list)
     318
     319        def save_email_for_debug(self, message, tempfile=False):
     320                if tempfile:
     321                        import tempfile
     322                        msg_file = tempfile.mktemp('.email2trac')
     323                else:
     324                        msg_file = '/var/tmp/msg.txt'
    314325                print 'TD: saving email to %s' % msg_file
    315326                fx = open(msg_file, 'wb')
     
    382393
    383394                if not msg['Subject']:
    384                         tkt['summary'] = '(geen subject)'
     395                        tkt['summary'] = u'(geen subject)'
    385396                else:
    386397                        tkt['summary'] = self.to_unicode(msg['Subject'])
     
    417428                # field of a ticket
    418429                #
    419                 tkt['description'] = 'email2trac:%s\r\n{{{\r\n%s\r\n}}}' \
     430                tkt['description'] = u'email2trac:%s\r\n{{{\r\n%s\r\n}}}' \
    420431                        %(head, body_text)
    421432
     
    433444                if self.MAILTO:
    434445                        mailto = self.html_mailto_link(self.to_unicode(msg['subject']), ticket_id, body_text)
    435                         tkt['description'] = 'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
     446                        tkt['description'] = u'email2trac:%s%s\r\n{{{\r\n%s\r\n}}}' %(head, mailto, body_text)
    436447                        comment = '\nadded mailto line\n'
    437448                        changed = True
     
    455466
    456467        def parse(self, fp):
     468                global m
     469
    457470                m = email.message_from_file(fp)
    458471                if not m:
     
    485498                """
    486499                has_description = 0
    487                 ubody_text = '\r\n{{{\nNo plain text message\n}}}\r\n'
     500                ubody_text = u'\r\n{{{\nNo plain text message\n}}}\r\n'
    488501                for part in msg.walk():
    489502
     
    505518                                charset = part.get_content_charset('iso-8859-15')
    506519                                try:
    507                                         temp = unicode(body_text, charset)
     520                                        ubody_text = unicode(body_text, charset)
    508521                                except (UnicodeError,LookupError):
    509                                         temp = unicode(body_text, 'iso-8859-15')
    510 
    511                                 ubody_text = temp.encode('utf-8')
     522                                        ubody_text = unicode(body_text, 'iso-8859-15')
    512523
    513524                        elif part.get_content_type() == 'text/html':
    514                                 ubody_text = '\r\n(see attachment for HTML mail message)\r\n'
     525                                ubody_text = u'\r\n(see attachment for HTML mail message)\r\n'
    515526
    516527                        else:
    517                                 ubody_text = '\r\n(see attachment for message)\r\n'
     528                                ubody_text = u'\r\n(see attachment for message)\r\n'
    518529
    519530                        has_description = 1
     
    521532
    522533                if not has_description:
    523                         ubody_text = '\r\n(see attachment for message)\r\n'
    524 
    525                 return ubody_text
     534                        ubody_text = u'\r\n(see attachment for message)\r\n'
     535
     536                return ubody_text.encode('utf-8')
    526537
    527538        def notify(self, tkt , new=True, modtime=0):
     
    793804        #
    794805        except Exception, error:
    795                 import syslog, traceback
     806                if m:
     807                        self.save_email_for_debug(m, True)
    796808
    797809                if ENABLE_SYSLOG:
Note: See TracChangeset for help on using the changeset viewer.