Changeset 253 for trunk/email2trac.py.in
- Timestamp:
- 01/28/09 09:25:08 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r252 r253 146 146 self.email_addr = None 147 147 self.email_from = None 148 self.id = None 148 149 149 150 self.VERSION = version … … 630 631 # Strip '#' 631 632 # 632 ticket_id = int(nr[1:])633 self.id = int(nr[1:]) 633 634 634 635 except AttributeError: … … 636 637 # 637 638 nr = result.group('ticketnr') 638 ticket_id = int(nr[1:-1])639 self.id = int(nr[1:-1]) 639 640 640 641 … … 649 650 650 651 try: 651 tkt = Ticket(self.env, ticket_id, self.db)652 tkt = Ticket(self.env, self.id, self.db) 652 653 except util.TracError, detail: 654 # Not a valid ticket 655 self.id = None 653 656 return False 654 657 … … 666 669 667 670 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) 669 672 670 673 if self.EMAIL_HEADER: … … 681 684 682 685 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) 686 689 687 690 if self.notification and not spam: 688 self.notify(tkt, ticket_id,False, when)691 self.notify(tkt, False, when) 689 692 690 693 return True … … 788 791 when = datetime.now(utc) 789 792 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() 794 795 795 796 changed = False … … 801 802 changed = True 802 803 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 805 806 tkt['description'] = u'%s\r\n%s%s\r\n' \ 806 807 %(head, mailto, body_text) 807 808 808 str = self.attachments(message_parts , ticket_id)809 str = self.attachments(message_parts) 809 810 if str: 810 811 changed = True … … 819 820 820 821 if self.notification and not spam: 821 self.notify(tkt, ticket_id, True) 822 #self.notify(ticket_id, False) 822 self.notify(tkt, True) 823 823 824 824 def parse(self, fp): … … 1080 1080 return message_parts 1081 1081 1082 def unique_attachment_names(self, message_parts , tkt_id = None):1082 def unique_attachment_names(self, message_parts): 1083 1083 renamed_parts = [] 1084 1084 attachment_names = set() … … 1130 1130 filename, ext = os.path.splitext(filename) 1131 1131 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): 1133 1133 num += 1 1134 1134 unique_filename = "%s-%s%s" % (filename, num, ext) … … 1147 1147 1148 1148 1149 def attachment_exists(self, tkt_id,filename):1149 def attachment_exists(self, filename): 1150 1150 1151 1151 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) 1153 1153 1154 1154 # We have no valid ticket id 1155 1155 # 1156 if not tkt_id:1156 if not self.id: 1157 1157 return False 1158 1158 1159 1159 try: 1160 att = attachment.Attachment(self.env, 'ticket', tkt_id, filename)1160 att = attachment.Attachment(self.env, 'ticket', self.id, filename) 1161 1161 return True 1162 1162 except attachment.ResourceNotFound: … … 1186 1186 return body_text 1187 1187 1188 def notify(self, tkt, id,new=True, modtime=0):1188 def notify(self, tkt, new=True, modtime=0): 1189 1189 """ 1190 1190 A wrapper for the TRAC notify function. So we can use templates … … 1222 1222 1223 1223 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 """ 1227 1230 if not self.author: 1228 1231 author = self.email_addr … … 1230 1233 author = self.author 1231 1234 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 1240 1236 # 1241 1237 str = 'mailto:%s?Subject=%s&Cc=%s' %( 1242 1238 urllib.quote(self.email_addr), 1243 urllib.quote('Re: #%s: %s' %( id, subject)),1239 urllib.quote('Re: #%s: %s' %(self.id, subject)), 1244 1240 urllib.quote(self.MAILTO_CC) 1245 1241 ) … … 1248 1244 return str 1249 1245 1250 def attachments(self, message_parts, tkt_id,update=False):1246 def attachments(self, message_parts, update=False): 1251 1247 ''' 1252 1248 save any attachments as files in the ticket's directory … … 1257 1253 1258 1254 count = 0 1259 first = 01260 number = 01261 1255 1262 1256 # Get Maxium attachment size … … 1300 1294 # 1301 1295 fd = open(path, 'rb') 1302 att = attachment.Attachment(self.env, 'ticket', tkt_id)1296 att = attachment.Attachment(self.env, 'ticket', self.id) 1303 1297 1304 1298 # This will break the ticket_update system, the body_text is vaporized
Note: See TracChangeset
for help on using the changeset viewer.