Changeset 250
- Timestamp:
- 01/27/09 15:35:40 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r249 r250 327 327 except KeyError, detail: 328 328 if self.DEBUG > 2 : 329 print ' %s not defined, all messages are allowed.' %(keyword)329 print 'TD: %s not defined, all messages are allowed.' %(keyword) 330 330 331 331 return default … … 434 434 435 435 436 def set_owner(self, ticket):437 """438 Select default owner for ticket component439 """440 #### return self.get_config('ticket', 'default_component')441 cursor = self.db.cursor()442 sql = "SELECT owner FROM component WHERE name='%s'" % ticket['component']443 cursor.execute(sql)444 try:445 ticket['owner'] = cursor.fetchone()[0]446 except TypeError, detail:447 ticket['owner'] = None448 449 436 def get_sender_info(self, message): 450 437 """ … … 471 458 # e : email address that the user has set in the settings tab 472 459 # 473 tmp_email_addrs = self.email_addr.lower()474 460 users = [ (u,n,e) for (u, n, e) in self.env.get_known_users(self.db) 475 if e == tmp_email_addr]461 if e and (e.lower() == self.email_addr.lower()) ] 476 462 477 463 if len(users) == 1: 478 464 self.email_from = users[0][0] 465 self.author = users[0][0] 479 466 480 467 def set_reply_fields(self, ticket, message): … … 614 601 creating a new one. 615 602 """ 603 if self.DEBUG: 604 print "TD: ticket_update" 616 605 617 606 if not m['Subject']: … … 677 666 678 667 message_parts = self.get_message_parts(m) 679 message_parts = self.unique_attachment_names(message_parts, t kt)668 message_parts = self.unique_attachment_names(message_parts, ticket_id) 680 669 681 670 if self.EMAIL_HEADER: … … 685 674 686 675 if body_text.strip() or update_fields: 687 tkt.save_changes(self.author, body_text, when) 688 689 tkt['id'] = ticket_id 676 if self.DRY_RUN: 677 print 'DRY_RUN: tkt.save_changes(self.author, comment) ', self.author 678 else: 679 tkt.save_changes(self.author, body_text, when) 680 690 681 691 682 if self.VERSION == 0.9: 692 str = self.attachments(message_parts, t kt, True)693 else: 694 str = self.attachments(message_parts, t kt)683 str = self.attachments(message_parts, ticket_id, True) 684 else: 685 str = self.attachments(message_parts, ticket_id) 695 686 696 687 if self.notification and not spam: 697 self.notify(tkt, False, when)688 self.notify(tkt, ticket_id, False, when) 698 689 699 690 return True … … 755 746 Create a new ticket 756 747 """ 748 if self.DEBUG: 749 print "TD: new_ticket" 750 757 751 tkt = Ticket(self.env) 758 759 752 self.set_ticket_fields(tkt) 760 761 # Some defaults762 #763 #tkt['status'] = 'new'764 #tkt['milestone'] = self.get_config('ticket', 'default_milestone')765 #tkt['priority'] = self.get_config('ticket', 'default_priority')766 #tkt['severity'] = self.get_config('ticket', 'default_severity')767 #tkt['version'] = self.get_config('ticket', 'default_version')768 #tkt['type'] = self.get_config('ticket', 'default_type')769 753 770 754 # Old style setting for component, will be removed … … 780 764 else: 781 765 tkt['summary'] = self.email_to_unicode(msg['Subject']) 782 783 766 784 767 self.set_reply_fields(tkt, msg) … … 809 792 else: 810 793 ticket_id = tkt.insert() 811 812 tkt['id'] = ticket_id 813 794 814 795 changed = False 815 796 comment = '' … … 825 806 %(head, mailto, body_text) 826 807 827 str = self.attachments(message_parts, t kt)808 str = self.attachments(message_parts, ticket_id) 828 809 if str: 829 810 changed = True … … 832 813 if changed: 833 814 if self.DRY_RUN: 834 print 'DRY_RUN: tkt.save_changes(self.author, comment) '815 print 'DRY_RUN: tkt.save_changes(self.author, comment) ', self.author 835 816 else: 836 817 tkt.save_changes(self.author, comment) 837 818 #print tkt.get_changelog(self.db, when) 838 819 839 if self.notification: 840 if self.DRY_RUN: 841 print 'DRY_RUN: self.notify(tkt, True)' 842 else: 843 if not spam: 844 self.notify(tkt, True) 845 #self.notify(tkt, False) 820 if self.notification and not spam: 821 self.notify(tkt, ticket_id, True) 822 #self.notify(ticket_id, False) 846 823 847 824 def parse(self, fp): … … 852 829 if not m: 853 830 if self.DEBUG: 854 print "T his is not a valid email message format"831 print "TD: This is not a valid email message format" 855 832 return 856 833 … … 1103 1080 return message_parts 1104 1081 1105 def unique_attachment_names(self, message_parts, tkt = None):1082 def unique_attachment_names(self, message_parts, tkt_id = None): 1106 1083 renamed_parts = [] 1107 1084 attachment_names = set() … … 1153 1130 filename, ext = os.path.splitext(filename) 1154 1131 1155 while unique_filename in attachment_names or self.attachment_exists(tkt , unique_filename):1132 while unique_filename in attachment_names or self.attachment_exists(tkt_id, unique_filename): 1156 1133 num += 1 1157 1134 unique_filename = "%s-%s%s" % (filename, num, ext) … … 1170 1147 1171 1148 1172 def attachment_exists(self, tkt, filename): 1173 if tkt is None: 1149 def attachment_exists(self, tkt_id, filename): 1150 1151 if self.DEBUG: 1152 print "TD: attachment_exists: Ticket number : %s, Filename : %s" %(tkt_id, filename) 1153 1154 # We have no valid ticket id 1155 # 1156 if not tkt_id: 1174 1157 return False 1175 1158 1176 1159 try: 1177 Attachment(self.env, 'ticket', tkt['id'], filename)1160 att = attachment.Attachment(self.env, 'ticket', tkt_id, filename) 1178 1161 return True 1179 except ResourceNotFound:1162 except attachment.ResourceNotFound: 1180 1163 return False 1181 1164 … … 1203 1186 return body_text 1204 1187 1205 def notify(self, tkt 1188 def notify(self, tkt, id, new=True, modtime=0): 1206 1189 """ 1207 1190 A wrapper for the TRAC notify function. So we can use templates 1208 1191 """ 1192 if self.DRY_RUN: 1193 print 'DRY_RUN: self.notify(tkt, True) ', self.author 1194 return 1209 1195 try: 1210 1196 # create false {abs_}href properties, to trick Notify() … … 1236 1222 1237 1223 except Exception, e: 1238 print 'TD: Failure sending notification on creation of ticket #%s: %s' %( tkt['id'], e)1224 print 'TD: Failure sending notification on creation of ticket #%s: %s' %(id, e) 1239 1225 1240 1226 def html_mailto_link(self, subject, id, body): … … 1262 1248 return str 1263 1249 1264 def attachments(self, message_parts, t icket, update=False):1250 def attachments(self, message_parts, tkt_id, update=False): 1265 1251 ''' 1266 1252 save any attachments as files in the ticket's directory 1267 1253 ''' 1268 1254 if self.DRY_RUN: 1255 print "DRY_RUN: no attachments saved" 1269 1256 return '' 1270 1257 … … 1313 1300 # 1314 1301 fd = open(path, 'rb') 1315 att = attachment.Attachment(self.env, 'ticket', t icket['id'])1302 att = attachment.Attachment(self.env, 'ticket', tkt_id) 1316 1303 1317 1304 # This will break the ticket_update system, the body_text is vaporized
Note: See TracChangeset
for help on using the changeset viewer.