Ejemplo n.º 1
0
    def getContacts(self, userAccounts):
        self.contactsLoadProgress = 0
        contactAccountsTemp = {}
        nodes = self.xmlRoot.firstChild.childNodes
        for i in range(len(nodes)):
            # check if this action was aborted
            if self.isAborted():
                return None

            node = nodes[i]
            if not isinstance(node, minidom.Element):
                continue

            df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
            date = df.parse(
                node.getElementsByTagName('timestamp')[0].firstChild.toxml())
            name = node.getElementsByTagName('name')
            if len(name) == 0:
                name = ""
            else:
                name = name[0].firstChild.toxml()
            uid = node.getElementsByTagName('from')[0].firstChild.toxml()
            ca = ContactAccount(0, name, uid, "", None, self.protocol)
            if not contactAccountsTemp.has_key(ca):
                contactAccountsTemp[ca] = []
            content = node.getElementsByTagName('body')[0].firstChild.toxml()
            msg = Message(0, None, content, date, True)
            contactAccountsTemp[ca].append(msg)
            self.messagesCount += 1
            self.contactsLoadProgress = i * 100 / len(nodes)

        contacts = []
        for ca in contactAccountsTemp.iterkeys():
            ca.conversations = ConversationHelper.messagesToConversations(
                contactAccountsTemp[ca], ca, userAccounts[0])
            cnt = Contact(0, "", "", ca.name)
            cnt.addContactAccount(ca)
            contacts.append(cnt)
        self.contactsLoadProgress = 100
        return contacts
Ejemplo n.º 2
0
    def getContacts(self, userAccounts):
        self.contactsLoadProgress = 0
        contactAccountsTemp = {}
        sms = re.split('\<sms\>', self.messagesContent)
        pattern = '\<from\>(.*)\s*\[(.*)\]\<\/from\>\s*\<msg\>(.*)\<\/msg\>\s*\<date\>(.*)\<\/date\>'
        prog = re.compile(pattern)
        for i in range(len(sms)):
            # check if this action was aborted
            if self.isAborted():
                return None

            res = prog.search(sms[i])
            if res <> None:
                df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                date = df.parse(res.group(4).strip())
                name = unicode(res.group(1).strip(), 'utf-8')
                if name == None:
                    name = ""
                ca = ContactAccount(0, name,
                                    res.group(2).strip(), "", None,
                                    self.protocol)
                if not contactAccountsTemp.has_key(ca):
                    contactAccountsTemp[ca] = []
                content = unicode(res.group(3).strip(), 'utf-8')
                msg = Message(0, None, content, date, True)
                contactAccountsTemp[ca].append(msg)
                self.messagesCount += 1
            self.contactsLoadProgress = i * 100 / len(sms)

        contacts = []
        for ca in contactAccountsTemp.iterkeys():
            ca.conversations = ConversationHelper.messagesToConversations(
                contactAccountsTemp[ca], ca, userAccounts[0])
            cnt = Contact(0, "", "", ca.name)
            cnt.addContactAccount(ca)
            contacts.append(cnt)
        self.contactsLoadProgress = 100
        return contacts
Ejemplo n.º 3
0
	def getContacts(self, userAccounts):
		self.contactsLoadProgress = 0
		contactAccountsTemp = {}
		nodes = self.xmlRoot.firstChild.childNodes
		for i in range(len(nodes)):
			# check if this action was aborted
			if self.isAborted():
				return None
			
			node = nodes[i]
			if not isinstance(node, minidom.Element):
				continue
			
			df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
			date = df.parse(node.getElementsByTagName('timestamp')[0].firstChild.toxml())
			name = node.getElementsByTagName('name')
			if len(name) == 0:
				name = ""
			else:
				name = name[0].firstChild.toxml()
			uid = node.getElementsByTagName('from')[0].firstChild.toxml()
			ca = ContactAccount(0, name, uid, "", None, self.protocol)
			if not contactAccountsTemp.has_key(ca):
				contactAccountsTemp[ca] = []
			content = node.getElementsByTagName('body')[0].firstChild.toxml()
			msg = Message(0, None, content, date, True)
			contactAccountsTemp[ca].append(msg)
			self.messagesCount += 1
			self.contactsLoadProgress = i * 100 /len(nodes)
		
		contacts = []
		for ca in contactAccountsTemp.iterkeys():
			ca.conversations = ConversationHelper.messagesToConversations(contactAccountsTemp[ca], ca, userAccounts[0])
			cnt = Contact(0, "", "", ca.name)
			cnt.addContactAccount(ca)
			contacts.append(cnt)
		self.contactsLoadProgress = 100
		return contacts