Changeset 253 for trunk/email2trac.py.in


Ignore:
Timestamp:
01/28/09 09:25:08 (15 years ago)
Author:
bas
Message:

email2trac.py.in:

  • ticket id is now move to the class variable. Adjusted the functions to new situation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r252 r253  
    146146                self.email_addr = None
    147147                self.email_from = None
     148                self.id = None
    148149
    149150                self.VERSION = version
     
    630631                        # Strip '#'
    631632                        #
    632                         ticket_id = int(nr[1:])
     633                        self.id = int(nr[1:])
    633634
    634635                except AttributeError:
     
    636637                        #
    637638                        nr = result.group('ticketnr')
    638                         ticket_id = int(nr[1:-1])
     639                        self.id = int(nr[1:-1])
    639640
    640641
     
    649650
    650651                try:
    651                         tkt = Ticket(self.env, ticket_id, self.db)
     652                        tkt = Ticket(self.env, self.id, self.db)
    652653                except util.TracError, detail:
     654                        # Not a valid ticket
     655                        self.id = None
    653656                        return False
    654657
     
    666669
    667670                message_parts = self.get_message_parts(m)
    668                 message_parts = self.unique_attachment_names(message_parts, ticket_id)
     671                message_parts = self.unique_attachment_names(message_parts)
    669672
    670673                if self.EMAIL_HEADER:
     
    681684
    682685                if self.VERSION  == 0.9:
    683                         str = self.attachments(message_parts, ticket_id, True)
    684                 else:
    685                         str = self.attachments(message_parts, ticket_id)
     686                        str = self.attachments(message_parts, True)
     687                else:
     688                        str = self.attachments(message_parts)
    686689
    687690                if self.notification and not spam:
    688                         self.notify(tkt, ticket_id, False, when)
     691                        self.notify(tkt, False, when)
    689692
    690693                return True
     
    788791                when = datetime.now(utc)
    789792
    790                 if self.DRY_RUN:
    791                         ticket_id = 'DRY_RUN'
    792                 else:
    793                         ticket_id = tkt.insert()
     793                if not self.DRY_RUN:
     794                        self.id = tkt.insert()
    794795               
    795796                changed = False
     
    801802                        changed = True
    802803                        comment = u'\nadded mailto line\n'
    803                         #mailto = self.html_mailto_link(tkt['summary'], ticket_id, body_text)
    804                         mailto = self.html_mailto_link( m['Subject'], ticket_id, body_text)
     804                        mailto = self.html_mailto_link( m['Subject'], body_text)
     805
    805806                        tkt['description'] = u'%s\r\n%s%s\r\n' \
    806807                                %(head, mailto, body_text)
    807808
    808                 str =  self.attachments(message_parts, ticket_id)
     809                str =  self.attachments(message_parts)
    809810                if str:
    810811                        changed = True
     
    819820
    820821                if self.notification and not spam:
    821                         self.notify(tkt, ticket_id, True)
    822                         #self.notify(ticket_id, False)
     822                        self.notify(tkt, True)
    823823
    824824        def parse(self, fp):
     
    10801080                return message_parts
    10811081               
    1082         def unique_attachment_names(self, message_parts, tkt_id = None):
     1082        def unique_attachment_names(self, message_parts):
    10831083                renamed_parts = []
    10841084                attachment_names = set()
     
    11301130                        filename, ext = os.path.splitext(filename)
    11311131
    1132                         while unique_filename in attachment_names or self.attachment_exists(tkt_id, unique_filename):
     1132                        while unique_filename in attachment_names or self.attachment_exists(unique_filename):
    11331133                                num += 1
    11341134                                unique_filename = "%s-%s%s" % (filename, num, ext)
     
    11471147               
    11481148                       
    1149         def attachment_exists(self, tkt_id, filename):
     1149        def attachment_exists(self, filename):
    11501150
    11511151                if self.DEBUG:
    1152                         print "TD: attachment_exists: Ticket number : %s, Filename : %s" %(tkt_id, filename)
     1152                        print "TD: attachment_exists: Ticket number : %s, Filename : %s" %(self.id, filename)
    11531153
    11541154                # We have no valid ticket id
    11551155                #
    1156                 if not tkt_id:
     1156                if not self.id:
    11571157                        return False
    11581158
    11591159                try:
    1160                         att = attachment.Attachment(self.env, 'ticket', tkt_id, filename)
     1160                        att = attachment.Attachment(self.env, 'ticket', self.id, filename)
    11611161                        return True
    11621162                except attachment.ResourceNotFound:
     
    11861186                return body_text
    11871187
    1188         def notify(self, tkt, id, new=True, modtime=0):
     1188        def notify(self, tkt, new=True, modtime=0):
    11891189                """
    11901190                A wrapper for the TRAC notify function. So we can use templates
     
    12221222
    12231223                except Exception, e:
    1224                         print 'TD: Failure sending notification on creation of ticket #%s: %s' %(id, e)
    1225 
    1226         def html_mailto_link(self, subject, id, body):
     1224                        print 'TD: Failure sending notification on creation of ticket #%s: %s' %(self.id, e)
     1225
     1226        def html_mailto_link(self, subject, body):
     1227                """
     1228                This function returns a HTML mailto tag with the ticket id and author email address
     1229                """
    12271230                if not self.author:
    12281231                        author = self.email_addr
     
    12301233                        author = self.author
    12311234
    1232                 # Must find a fix
    1233                 #
    1234                 #arr = string.split(body, '\n')
    1235                 #arr = map(self.mail_line, arr)
    1236                 #body = string.join(arr, '\n')
    1237                 #body = '%s wrote:\n%s' %(author, body)
    1238 
    1239                 # Temporary fix
     1235                # use urllib to escape the chars
    12401236                #
    12411237                str = 'mailto:%s?Subject=%s&Cc=%s' %(
    12421238                       urllib.quote(self.email_addr),
    1243                            urllib.quote('Re: #%s: %s' %(id, subject)),
     1239                           urllib.quote('Re: #%s: %s' %(self.id, subject)),
    12441240                           urllib.quote(self.MAILTO_CC)
    12451241                           )
     
    12481244                return str
    12491245
    1250         def attachments(self, message_parts, tkt_id, update=False):
     1246        def attachments(self, message_parts, update=False):
    12511247                '''
    12521248                save any attachments as files in the ticket's directory
     
    12571253
    12581254                count = 0
    1259                 first = 0
    1260                 number = 0
    12611255
    12621256                # Get Maxium attachment size
     
    13001294                        #
    13011295                        fd = open(path, 'rb')
    1302                         att = attachment.Attachment(self.env, 'ticket', tkt_id)
     1296                        att = attachment.Attachment(self.env, 'ticket', self.id)
    13031297
    13041298                        # This will break the ticket_update system, the body_text is vaporized
Note: See TracChangeset for help on using the changeset viewer.