Changeset 353


Ignore:
Timestamp:
04/15/10 12:01:22 (14 years ago)
Author:
bas
Message:

email2trac.py.in:

  • Added patch to update ticket based on subject, see #188
  • must be approved. It can not handle Re: [project name]: <subject>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r352 r353  
    198198                        self.TICKET_UPDATE = 0
    199199
     200                if parameters.has_key('ticket_update_by_subject'):
     201                        self.TICKET_UPDATE_BY_SUBJECT = int(parameters['ticket_update_by_subject'])
     202                else:
     203                        self.TICKET_UPDATE_BY_SUBJECT = 0
     204
    200205                if parameters.has_key('drop_spam'):
    201206                        self.DROP_SPAM = int(parameters['drop_spam'])
     
    12201225                                self.new_ticket(m, subject[:result.start('new_fields')], spam_msg, result.group('new_fields'))
    12211226
    1222                 # Create ticket
    1223                 #
    1224                 else:
    1225                         self.new_ticket(m, subject, spam_msg)
     1227                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.
     1234                                re_regex = re.compile(r'^(RE|AW|VS|SV):\s*(.*)', re.IGNORECASE)
     1235                                result = re_regex.search(subject)
     1236                                print result
     1237
     1238                                if result:
     1239                                        # This is a reply
     1240                                        orig_subject = result.group(2)
     1241                                        print orig_subject
     1242                                        cursor = self.db.cursor()
     1243
     1244                                        summaries = [orig_subject, '%%: %s' % orig_subject]
     1245
     1246                                        # hard-code the time to 30 days for now. Can easily be
     1247                                        # made configurable
     1248                                        lookback = int(time.mktime(time.gmtime())) - 2592000
     1249
     1250                                        matched_id = 0
     1251                                        for summary in summaries:
     1252                                                if self.DEBUG:
     1253                                                        print 'TD: Looking for summary matching: "%s"' % summary
     1254                                                sql = """SELECT id FROM ticket
     1255                                                                                  WHERE changetime >= %s
     1256                                                                                        AND summary LIKE %s
     1257                                                                                        ORDER BY changetime DESC"""
     1258                                                cursor.execute(sql, [lookback, summary.strip()])
     1259
     1260                                                for row in cursor:
     1261                                                        (matched_id,) = row
     1262                                                        if self.DEBUG:
     1263                                                                print 'TD: Found matching ticket id: %d' % matched_id
     1264                                                        break
     1265
     1266                                                if matched_id:
     1267                                                        break
     1268
     1269                                        if matched_id:
     1270                                                # Change the id to string, as expected by ticket_update
     1271                                                matched_id = '#%d:' % matched_id
     1272                                                self.ticket_update(m, matched_id, spam_msg)
     1273                                                return
     1274
     1275                                # Not a reply or no matches found, create a new ticket
     1276                                self.new_ticket(m, subject, spam_msg)
     1277
     1278                        else:
     1279                                # No update by subject, so just create a new ticket
     1280                                self.new_ticket(m, subject, spam_msg)
    12261281
    12271282########## BODY TEXT functions  ###########################################################
Note: See TracChangeset for help on using the changeset viewer.