Ignore:
Timestamp:
02/01/06 08:58:14 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

email2trac.py.in:

  • Fixed an attachment saving bug for version < 0.9
File:
1 edited

Legend:

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

    r46 r48  
    490490                                filename = self.to_unicode(filename)
    491491
    492                         if '/' in filename:
    493                                 filename = os.path.basename(filename)
     492                        # From the trac code
     493                        #
     494                        filename = filename.replace('\\', '/').replace(':', '/')
     495                        filename = os.path.basename(filename)
     496
     497                        # We try to normalize the filename to utf-8 NFC if we can.
     498                        # Files uploaded from OS X might be in NFD.
     499                        #
     500                        if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] >= 3):
     501                                filename = unicodedata.normalize('NFC', unicode(filename, 'utf-8')).encode('utf-8') 
    494502
    495503                        url_filename = urllib.quote(filename)
    496504
    497505                        if self.VERSION > 0.8:
    498                                 tmpfile = '/tmp/email2trac-ticket%sattachment' % str(ticket['id'])
     506                                #tmpfile = '/tmp/email2trac-ticket%sattachment' % str(ticket['id'])
     507                                dir = '/tmp'
    499508                        else:
    500509                                dir = os.path.join(self.env.get_attachments_dir(), 'ticket',
     
    503512                                        mkdir_p(dir, 0755)
    504513
    505                                 tmpfile = os.path.join(dir, url_filename)
    506 
    507                         f = open(tmpfile, 'wb')
     514                                #tmpfile = os.path.join(dir, url_filename)
     515
     516                        path, fd =  util.create_unique_file(os.path.join(dir, url_filename))
     517                        #f = open(tmpfile, 'wb')
    508518                        text = part.get_payload(decode=1)
    509519                        if not text:
    510520                                text = '(None)'
    511                         f.write(text)
     521                        fd.write(text)
     522                        fd.close()
    512523
    513524                        # get the filesize
    514525                        #
    515                         stats = os.lstat(tmpfile)
     526                        #stats = os.lstat(tmpfile)
     527                        stats = os.lstat(path)
    516528                        filesize = stats[stat.ST_SIZE]
    517529
     
    519531                        #
    520532                        if self.VERSION > 0.8:
    521                                 att = attachment.Attachment(self.env,'ticket',ticket['id'])
    522                                 att.insert(url_filename,f,filesize)
    523                                 f.close()
     533                                fd = open(path)
     534                                att = attachment.Attachment(self.env,' ticket', ticket['id'])
     535                                att.insert(url_filename, fd, filesize)
     536                                fd.close()
    524537                        else:
    525538                                cursor = self.db.cursor()
     
    626639                from trac.Notify import TicketNotifyEmail
    627640                from trac.web.href import Href
     641                from trac import util
    628642        else:
    629643                from trac.Environment import Environment
     
    631645                from trac.Notify import TicketNotifyEmail
    632646                from trac.Href import Href
     647                from trac import util
    633648
    634649        env = Environment(settings['project'], create=0)
Note: See TracChangeset for help on using the changeset viewer.