Changeset 153


Ignore:
Timestamp:
04/24/07 08:51:51 (17 years ago)
Author:
bas
Message:

EmailToTracScript?
EmailtoTracScript?:

email2trac.py.in:

  • Code runs again and added check for attachment size
File:
1 edited

Legend:

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

    r152 r153  
    554554
    555555
    556         def wrap_text(str='', width = self.USE_TEXTWRAP, replace_whitespace = False):
     556        def wrap_text(str='', replace_whitespace = False):
    557557                """
    558558                Will break a lines longer then given length into several small lines of size
     
    561561                import textwrap
    562562                LINESEPARATOR = '\n'
    563                 return LINESEPARATOR.join(textwrap.fill(s,width) for s in str.split(LINESEPARATOR))
     563                reformat = ''
     564
     565                for s in str.split(LINESEPARATOR):
     566                        reformat = '%s%s' %(reformat, LINESEPARATOR.join(textwrap.fill(s,self.USE_TEXTWRAP)))
     567
     568                return reformat
    564569
    565570        def get_body_text(self, msg):
     
    697702                #
    698703                max_size = int(self.get_config('attachment', 'max_size'))
    699                 message = ''
     704                status  = ''
    700705
    701706                for part in message.walk():
     
    752757                        fd.close()
    753758
    754                         # get the filesize
     759                        # get the file_size
    755760                        #
    756761                        stats = os.lstat(path)
    757                         filesize = stats[stat.ST_SIZE]
     762                        file_size = stats[stat.ST_SIZE]
    758763
    759764                        # Check if the attachment size is allowed
    760765                        #
    761                         if file_size > max_size:
    762                                 message = '%s\n%sFile %s is larger then allowed attachment size (%d > %d)'
    763                                         %(message, filename, file_size, max_size)
     766                        if (max_size != -1) and (file_size > max_size):
     767                                status = '%s\nFile %s is larger then allowed attachment size (%d > %d)\n\n' \
     768                                        %(status, filename, file_size, max_size)
    764769
    765770                                os.unlink(path)
     
    774779                                try:
    775780                                        cursor.execute('INSERT INTO attachment VALUES("%s","%s","%s",%d,%d,"%s","%s","%s")'
    776                                                 %('ticket', urllib.quote(str(ticket['id'])), filename + '?format=raw', filesize,
     781                                                %('ticket', urllib.quote(str(ticket['id'])), filename + '?format=raw', file_size,
    777782                                                int(time.time()),'', self.author, 'e-mail') )
    778783
     
    796801                                        att.description = self.email_to_unicode('Added by email2trac')
    797802
    798                                 att.insert(url_filename, fd, filesize)
     803                                att.insert(url_filename, fd, file_size)
    799804
    800805                                #except  util.TracError, detail:
     
    809814                # Return how many attachments
    810815                #
    811                 message = 'This message has %d attachment(s)\n%s' %(count, message)
    812                 return message
     816                status = 'This message has %d attachment(s)\n%s' %(count, status)
     817                return status
    813818
    814819
Note: See TracChangeset for help on using the changeset viewer.