def updateContacts(self, db): if not self.contactFile: return connection = sqlite3.connect(self.contactFile) sql = """ SELECT p.ROWID, p.First, p.Last, mv.property, mv.value FROM ABPerson p INNER JOIN ABMultiValue mv ON mv.record_id = p.ROWID WHERE mv.property IN (3, 4) -- Phone, Email ORDER BY p.ROWID""" contacts = sqlite.executeManyToDictionary(connection, sql) addedContacts = {} for person in contacts: address = person['value'] rowId = person['ROWID'] if person['property'] == 3: addressType = 'phone' address = address.replace(' ', '') address = address.replace('(', '').replace(')', '') address = address.replace('-', '') address = self.internationalizeNumber(address, self.account.defaultCountry) elif person['property'] == 4: addressType = 'email' if rowId in addedContacts: newId = contact.addAddressToExistingContact(db, addedContacts[rowId], addressType, address) addedContacts[rowId] = newId else: contactId = contact.createContact(db, person['First'], person['Last'], addressType, address) addedContacts[rowId] = contactId connection.close()
def _processAdiumLog(self, db, path, id): file = open(path, 'r') line = file.read() file.close() # Line breaks confuse things later on. line = line.replace('<br />', '<br />') writeFile = open(path + '_temp', 'w') writeFile.write(line) writeFile.close() xml = etree.parse(path + '_temp') root = xml.getroot() username = '' service = '' for name, value in root.items(): if name == 'account': username = value if name == 'service': service = value accountId, ourContactId = account.createIMAccount(db, service, username) storedConversation = False storedContacts = {} for child in root.getchildren(): if child.tag.endswith('message'): alias = None if 'alias' in child.attrib: alias = child.attrib['alias'] address = child.attrib['sender'] if address not in storedContacts: contactId = contact.addEmptyContact(db, 'IM', address, alias) if address.find('@') > 0: # Crude test for email contactId = contact.addAddressToExistingContact(db, contactId, 'email', address, alias) storedContacts[address] = contactId else: contactId = storedContacts[address] sentTime = datetime(*time.strptime(child.attrib['time'][:19], '%Y-%m-%dT%H:%M:%S')[0:6]) wrapper = child.getchildren()[0] node = wrapper.getchildren()[0] if node.text: text = node.text.replace('<br />', '\n') if not storedConversation: messageId = message.store(db, accountId, sentTime, ourContactId, text + u'...', [ourContactId], 'IM') imConversation.store(db, messageId, id) storedConversation = True if contactId != ourContactId: message.addRecipient(db, messageId, contactId) imConversation.addEntry(db, messageId, sentTime, contactId, text) os.remove(path + '_temp')