Changeset 356
- Timestamp:
- 04/15/10 15:18:09 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r354 r356 887 887 888 888 889 def ticket_update_by_subject(self, subject): 890 """ 891 This list of Re: prefixes is probably incomplete. Taken from 892 wikipedia. Here is how the subject is matched 893 - Re: <subject> 894 - Re: (<Mail list label>:)+ <subject> 895 896 So we must have the last column 897 """ 898 if self.VERBOSE: 899 print "VB: ticket_update_by_subject()" 900 901 matched_id = None 902 if self.TICKET_UPDATE and self.TICKET_UPDATE_BY_SUBJECT: 903 904 SUBJECT_RE = re.compile(r'^(RE|AW|VS|SV):(.*:)*\s*(.*)', re.IGNORECASE) 905 result = SUBJECT_RE.search(subject) 906 907 if result: 908 # This is a reply 909 orig_subject = result.group(3) 910 911 if self.DEBUG: 912 print 'TD: subject search string: %s' %(orig_subject) 913 914 cursor = self.db.cursor() 915 summaries = [orig_subject, '%%: %s' % orig_subject] 916 917 # hard-code the time to 30 days for now. Can easily be 918 # made configurable 919 lookback = int(time.mktime(time.gmtime())) - 2592000 920 921 for summary in summaries: 922 if self.DEBUG: 923 print 'TD: Looking for summary matching: "%s"' % summary 924 sql = """SELECT id FROM ticket 925 WHERE changetime >= %s AND summary LIKE %s 926 ORDER BY changetime DESC""" 927 cursor.execute(sql, [lookback, summary.strip()]) 928 929 for row in cursor: 930 (matched_id,) = row 931 if self.DEBUG: 932 print 'TD: Found matching ticket id: %d' % matched_id 933 break 934 935 if matched_id: 936 matched_id = '#%d:' % matched_id 937 return matched_id 938 939 return matched_id 940 889 941 890 942 def new_ticket(self, msg, subject, spam, set_fields = None): … … 892 944 Create a new ticket 893 945 """ 894 if self. DEBUG:895 print " TD: new_ticket"946 if self.VERBOSE: 947 print "VB: function new_ticket()" 896 948 897 949 tkt = Ticket(self.env) … … 1123 1175 1124 1176 def parse(self, fp): 1177 """ 1178 """ 1179 if self.VERBOSE: 1180 print "VB: main function parse()" 1125 1181 global m 1126 1182 … … 1226 1282 1227 1283 else: 1228 if self.TICKET_UPDATE and self.TICKET_UPDATE_BY_SUBJECT: 1229 if self.DEBUG: 1230 print 'TD: Will try to figure out ticket by subject' 1231 1232 # This list of Re: prefixes is probably incomplete. Taken from 1233 # wikipedia. Here is how the subject is matched 1234 # Re: <subject> 1235 # Re: (<Mail list label>:)+ <subject> 1236 # 1237 # So we must have column 3 1238 1239 1240 SUBJECT_RE = re.compile(r'^(RE|AW|VS|SV):(.*:)*\s*(.*)', re.IGNORECASE) 1241 result = SUBJECT_RE.search(subject) 1242 1243 if result: 1244 # This is a reply 1245 orig_subject = result.group(3) 1246 if self.DEBUG: 1247 print 'TD: subject search string: %s' %(orig_subject) 1248 1249 cursor = self.db.cursor() 1250 1251 summaries = [orig_subject, '%%: %s' % orig_subject] 1252 1253 # hard-code the time to 30 days for now. Can easily be 1254 # made configurable 1255 lookback = int(time.mktime(time.gmtime())) - 2592000 1256 1257 matched_id = 0 1258 for summary in summaries: 1259 if self.DEBUG: 1260 print 'TD: Looking for summary matching: "%s"' % summary 1261 sql = """SELECT id FROM ticket 1262 WHERE changetime >= %s 1263 AND summary LIKE %s 1264 ORDER BY changetime DESC""" 1265 cursor.execute(sql, [lookback, summary.strip()]) 1266 1267 for row in cursor: 1268 (matched_id,) = row 1269 if self.DEBUG: 1270 print 'TD: Found matching ticket id: %d' % matched_id 1271 break 1272 1273 if matched_id: 1274 break 1275 1276 if matched_id: 1277 # Change the id to string, as expected by ticket_update 1278 matched_id = '#%d:' % matched_id 1279 self.ticket_update(m, matched_id, spam_msg) 1280 return 1281 1282 # Not a reply or no matches found, create a new ticket 1283 self.new_ticket(m, subject, spam_msg) 1284 1284 result = self.ticket_update_by_subject(subject) 1285 if result: 1286 self.ticket_update(m, result, spam_msg) 1285 1287 else: 1286 1288 # No update by subject, so just create a new ticket 1287 1289 self.new_ticket(m, subject, spam_msg) 1290 1288 1291 1289 1292 ########## BODY TEXT functions ########################################################### … … 1872 1875 tktparser.save_email_for_debug(m, True) 1873 1876 1877 1874 1878 sys.exit(1) 1875 1879 # EOB
Note: See TracChangeset
for help on using the changeset viewer.