Changeset 331


Ignore:
Timestamp:
03/23/10 16:57:23 (14 years ago)
Author:
bas
Message:

disabled writing files for Dry-run mode
Debug mode can now handle printing of non-ascii chararacters. We just inform the user that it can not be displayed, see #184

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/debian/changelog

    r329 r331  
    1 email2trac (1.3.0-1) stable; urgency=low
     1email2trac (1.3.0-2) stable; urgency=low
    22
    33  * Added environment variable INSTALL_USER check. If set then use
     
    2020    Fixed by: Bas van der Vlies
    2121
     22  * We do not write any files when dry run mode is enabled.
     23    Fixed by: Bas van der Vlies
     24
     25  * Fixed several issues when DEBUG is enabled with printing no-ascii
     26    characters, see #184
     27    Reported by: hju add jochenkuhl dot de
     28    Fixed by: Bas van der Vlies
     29 
    2230 -- Bas van der Vlies <basv@sara.nl>  Wed, 03 Mar 2010 15:50:35 +0100
    2331
  • trunk/email2trac.py.in

    r330 r331  
    503503                        body_file = os.path.join(self.TMPDIR, 'body.txt')
    504504
    505                 print 'TD: writing body (%s)' % body_file
    506                 fx = open(body_file, 'wb')
     505                if self.DRY_RUN:
     506                        print 'DRY-RUN: not saving body to %s' %(body_file)
     507                        return
     508
     509                print 'TD: writing body to %s' %(body_file)
     510                fx = open(body_file, 'wb')
    507511                if not message_body:
    508                         message_body = '(None)'
     512                                message_body = '(None)'
    509513
    510514                message_body = message_body.encode('utf-8')
     
    525529               
    526530                n = 0
    527                 for part in message_parts:
     531                for item in message_parts:
    528532                        # Skip inline text parts
    529                         if not isinstance(part, tuple):
     533                        if not isinstance(item, tuple):
    530534                                continue
    531535                               
    532                         (original, filename, part) = part
     536                        (original, filename, part) = item
    533537
    534538                        n = n + 1
     
    536540                        print 'TD: part%d: filename: %s' % (n, part.get_filename())
    537541
    538                         part_file = os.path.join(self.TMPDIR, filename)
    539                         #part_file = '/var/tmp/part%d' % n
     542                        part_file = os.path.join(self.TMPDIR, part.get_filename())
    540543                        print 'TD: writing part%d (%s)' % (n,part_file)
     544
     545                        if self.DRY_RUN:
     546                                print 'DRY_RUN: NOT saving attachments'
     547                                continue
     548
    541549                        fx = open(part_file, 'wb')
    542550                        text = part.get_payload(decode=1)
     551
    543552                        if not text:
    544553                                text = '(None)'
     554
    545555                        fx.write(text)
    546556                        fx.close()
     557
    547558                        try:
    548559                                os.chmod(part_file,S_IRWXU|S_IRWXG|S_IRWXO)
     
    559570                        msg_file = os.path.join(self.TMPDIR, 'msg.txt')
    560571
    561                 print 'TD: saving email to %s' % msg_file
    562                 fx = open(msg_file, 'wb')
    563                 fx.write('%s' % message)
    564                 fx.close()
    565                 try:
    566                         os.chmod(msg_file,S_IRWXU|S_IRWXG|S_IRWXO)
    567                 except OSError:
    568                         pass
     572                if self.DRY_RUN:
     573                        print 'DRY_RUN: NOT saving email message to %s' %(msg_file)
     574                else:
     575                        print 'TD: saving email to %s' %(msg_file)
     576
     577                        fx = open(msg_file, 'wb')
     578                        fx.write('%s' % message)
     579                        fx.close()
     580                       
     581                        try:
     582                                os.chmod(msg_file,S_IRWXU|S_IRWXG|S_IRWXO)
     583                        except OSError:
     584                                pass
    569585
    570586                message_parts = self.get_message_parts(message)
     
    10581074                        blog_enabled = True
    10591075
    1060                 print m['Subject']     
    10611076                if not m['Subject']:
    10621077                        subject  = 'No Subject'
     
    13261341                                                print 'TD:               Filename: %s' % part.get_filename()
    13271342                                        except UnicodeEncodeError, detail:
    1328                                                 print 'TD:               Filename: Can not be printed due to non-ascci characters'
     1343                                                print 'TD:               Filename: Can not be printed due to non-ascii characters'
    13291344
    13301345                                ## Convert 7-bit filename to 8 bits value
     
    13411356                attachment_names = set()
    13421357
    1343                 for part in message_parts:
     1358                for item in message_parts:
    13441359                       
    13451360                        ## If not an attachment, leave it alone
    13461361                        #
    1347                         if not isinstance(part, tuple):
    1348                                 renamed_parts.append(part)
     1362                        if not isinstance(item, tuple):
     1363                                renamed_parts.append(item)
    13491364                                continue
    13501365                               
    1351                         (filename, part) = part
     1366                        (filename, part) = item
    13521367
    13531368                        ## If no filename, use a default one
     
    13931408                               
    13941409                        if self.DEBUG:
    1395                                 print 'TD: Attachment with filename %s will be saved as %s' % (filename, unique_filename)
     1410                                try:
     1411                                        print 'TD: Attachment with filename %s will be saved as %s' % (filename, unique_filename)
     1412                                except UnicodeEncodeError, detail:
     1413                                        print 'Filename can not be printed due to non-ascii characters'
    13961414
    13971415                        attachment_names.add(unique_filename)
     
    14081426
    14091427                if self.DEBUG:
    1410                         print "TD: attachment_exists: Ticket number : %s, Filename : %s" %(self.id, filename)
     1428                        s = 'TD: attachment already exists: Ticket id : '
     1429                        try:
     1430                                print "%s%s, Filename : %s" %(s, self.id, filename)
     1431                        except UnicodeEncodeError, detail:
     1432                                print "%s%s, Filename : Can not be printed due to non-ascii characters" %(s, self.id)
    14111433
    14121434                # We have no valid ticket id
Note: See TracChangeset for help on using the changeset viewer.