Changeset 348


Ignore:
Timestamp:
04/12/10 18:04:24 (14 years ago)
Author:
bas
Message:

email2trac.py.in:

  • added some code that will replace the / and \ chars for attachments filenames with _. These chars are forbidden for Unix/Windows? environments. Alse when something goes wrong with an attachment. The error is displayed in the changelog of the ticket, see #196
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r347 r348  
    112010-XX-XX
     2  * Re-enabled some code that normalized the filenames for attachment
    23
    34
  • trunk/email2trac.py.in

    r347 r348  
    505505                        n = n + 1
    506506                        print 'TD: part%d: Content-Type: %s' % (n, part.get_content_type())
    507                         print 'TD: part%d: filename: %s' % (n, part.get_filename())
    508 
    509                         part_file = os.path.join(self.TMPDIR, part.get_filename())
     507                        print 'TD: part%d: filename: %s' % (n, filename)
     508
     509                        ## Forbidden chars
     510                        #
     511                        filename = filename.replace('\\', '_')
     512                        filename = filename.replace('/', '_')
     513       
     514
     515                        part_file = os.path.join(self.TMPDIR, filename)
    510516                        print 'TD: writing part%d (%s)' % (n,part_file)
    511517
     
    800806                body_text = self.body_text(message_parts)
    801807
     808                if self.VERSION  == 0.9:
     809                        error_with_attachments = self.attach_attachments(message_parts, True)
     810                else:
     811                        error_with_attachments = self.attach_attachments(message_parts)
     812
    802813                if body_text.strip() or update_fields or self.properties:
    803814                        if self.DRY_RUN:
    804815                                print 'DRY_RUN: tkt.save_changes(self.author, body_text, ticket_change_number) ', self.author, cnum
    805816                        else:
     817                                if error_with_attachments:
     818                                        body_text = '%s\\%s' %(error_with_attachments, body_text)
     819                               
    806820                                tkt.save_changes(self.author, body_text, when, None, str(cnum))
    807821                       
    808822
    809                 if self.VERSION  == 0.9:
    810                         error_with_attachments = self.attach_attachments(message_parts, True)
    811                 else:
    812                         error_with_attachments = self.attach_attachments(message_parts)
     823                #if self.VERSION  == 0.9:
     824                #       error_with_attachments = self.attach_attachments(message_parts, True)
     825                #else:
     826                #       error_with_attachments = self.attach_attachments(message_parts)
    813827
    814828                if self.notification and not spam:
     
    10471061                                att.description = self.email_to_unicode('Added by email2trac')
    10481062
    1049                         att.insert(filename, fd, file_size)
    1050 
    1051                         #except  util.TracError, detail:
    1052                         #       print detail
     1063                        try:
     1064                                att.insert(filename, fd, file_size)
     1065                        except OSError, detail:
     1066                                status = '%s\nFilename %s could not be saved, problem: %s' %(status, filename, detail)
    10531067
    10541068                        # Remove the created temporary filename
     
    14861500                                filename = '%s%s' % (filename, ext)
    14871501
    1488                         ## Discard relative paths in attachment names
    1489                         #
    1490                         filename = filename.replace('\\', '/').replace(':', '/')
    1491                         filename = os.path.basename(filename)
     1502                        ## Discard relative paths for windows/unix in attachment names
     1503                        #
     1504                        #filename = filename.replace('\\', '/').replace(':', '/')
     1505                        filename = filename.replace('\\', '_')
     1506                        filename = filename.replace('/', '_')
    14921507
    14931508                        #
     
    14961511                        # Check python version and then try it
    14971512                        #
    1498                         if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] >= 3):
    1499                                 try:
    1500                                         filename = unicodedata.normalize('NFC', unicode(filename, 'utf-8')).encode('utf-8') 
    1501                                 except TypeError:
    1502                                         pass
     1513                        #if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] >= 3):
     1514                        #       try:
     1515                        #               filename = unicodedata.normalize('NFC', unicode(filename, 'utf-8')).encode('utf-8') 
     1516                        #       except TypeError:
     1517                        #               pass
    15031518
    15041519                        # Make the filename unique for this ticket
Note: See TracChangeset for help on using the changeset viewer.