def getNewMessageIds(self, db): """ Returns the remote IDs of any new messages on the server. """ self.updateContacts(db) if not self.smsFile: return [] sql = """ SELECT ROWID FROM message WHERE address IS NOT NULL AND text IS NOT NULL ORDER BY ROWID;""" connection = sqlite3.connect(self.smsFile) remoteIds = sqlite.executeManyToDictionary(connection, sql) remoteIds = [row['ROWID'] for row in remoteIds] storedIds = [int(msg['intRemoteId']) for msg in message.getAllRemoteIds(db, 'iPhone SMS', self.account.id)] self.idsToFetch = [msg for msg in remoteIds if storedIds.count(msg) == 0] connection.close()
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()