Example #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
Example #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
Example #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
Example #4
0
    def getContacts(self, userAccounts):
        buddiesxml = self.element.find("Buddies")
        contactslist = []
        for buddy in buddiesxml:
            if buddy:
                name = buddy.find("Display").text
                fname = ""
                if buddy.find("FirstName").text != name and buddy.find(
                        "FirstName").text != None:
                    fname = buddy.find("FirstName").text
                lname = ""
                if buddy.find("LastName").text != name and buddy.find(
                        "LastName").text != None:
                    lname = buddy.find("LastName").text
                c = Contact(0, fname, lname, name)
                self.buddies[buddy.attrib["uuid"]] = c
            else:
                c = Contact(0, "", "", "")
                self.buddies[buddy.attrib["uuid"]] = c

        contactsxml = self.element.find("Contacts")
        for contact in contactsxml:
            if self.accounts[contact.find("Account").text][0] in userAccounts:
                if contact.find("Buddy").text == None:
                    c = Contact(0, "", "", contact.find("Id").text)
                else:
                    c = self.buddies[contact.find("Buddy").text]
                if not c in contactslist:
                    contactslist.append(c)
                ca = ContactAccount(
                    0, "",
                    contact.find("Id").text, "", c, self.accounts[contact.find(
                        "Account").text][0].getProtocol())
                c.addContactAccount(ca)
                self.contacts[contact.attrib["uuid"]] = ca

        connection = DriverManager.getConnection("jdbc:sqlite:" + self.dbFile)
        stmt = connection.createStatement()

        chatsxml = self.element.find("Chats")
        df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
        for chat in chatsxml:
            #print self.accounts[chat.find("Account").text]
            if chat.find("Account") != None and self.accounts[chat.find(
                    "Account").text][0] in userAccounts:
                #self.chats[chat.attrib["uuid"]] = (self.accounts[chat.find("Account").text], self.accounts[chat.find("Contact").text])
                #chatlist.append((self.accounts[chat.find("Account").text], self.accounts[chat.find("Contact").text]))
                rs = stmt.executeQuery(
                    "SELECT * FROM kadu_messages WHERE chat='" +
                    chat.attrib["uuid"] + "' ORDER BY send_time")
                #conv = Conversation(0, Date(), "", 0, self.contacts[chat.find("Contact").text], self.accounts[chat.find("Account").text][0])
                #self.contacts[chat.find("Contact").text].addConversation(conv)
                #print self.contacts[chat.find("Contact").text], self.contacts[chat.find("Contact").text].getConversations().size()
                #print "Chat ", chat.attrib["uuid"]
                msgs = []
                #length = 0
                #fmsg = ""
                #date = None
                #enddate = None
                while rs.next():
                    if rs.getString("attributes")[-1] == "0":
                        recv = 1
                    else:
                        recv = 0
                    msgs.append(
                        Message(0, None, rs.getString("content"),
                                df.parse(rs.getString("send_time")), recv))
                    #conv.addMessage(msg)
                    #length += 1
                    self.messagesCount += 1
                    #if fmsg=="":
                    #	fmsg=rs.getString("content")
                    #if date == None:
                    #	date = df.parse(rs.getString("send_time"))
                    #enddate = df.parse(rs.getString("send_time"))
                    #print "\tROW = ", chat, sender, time, content, out
                #conv.setLength(length)
                #conv.setTime(date)
                #conv.setEndTime(enddate)
                #conv.setTitle(fmsg)
                #print self.contacts[chat.find("Contact").text]
                #print self.accounts[chat.find("Account").text][0]
                if len(msgs) > 0:
                    self.contacts[chat.find("Contact").text].setConversations(
                        ConversationHelper.messagesToConversations(
                            msgs, self.contacts[chat.find("Contact").text],
                            self.accounts[chat.find("Account").text][0]))
        self.contactsLoadProgress = 100
        return contactslist
Example #5
0
    def getContacts(self, userAccounts):
        buddiesxml = self.element.find("Buddies")
        contactslist = []
        for buddy in buddiesxml:
            if buddy:
                name = buddy.find("Display").text
                fname = ""
                if buddy.find("FirstName").text != name and buddy.find("FirstName").text != None:
                    fname = buddy.find("FirstName").text
                lname = ""
                if buddy.find("LastName").text != name and buddy.find("LastName").text != None:
                    lname = buddy.find("LastName").text
                c = Contact(0, fname, lname, name)
                self.buddies[buddy.attrib["uuid"]] = c
            else:
                c = Contact(0, "", "", "")
                self.buddies[buddy.attrib["uuid"]] = c

        contactsxml = self.element.find("Contacts")
        for contact in contactsxml:
            if self.accounts[contact.find("Account").text][0] in userAccounts:
                if contact.find("Buddy").text == None:
                    c = Contact(0, "", "", contact.find("Id").text)
                else:
                    c = self.buddies[contact.find("Buddy").text]
                if not c in contactslist:
                    contactslist.append(c)
                ca = ContactAccount(
                    0, "", contact.find("Id").text, "", c, self.accounts[contact.find("Account").text][0].getProtocol()
                )
                c.addContactAccount(ca)
                self.contacts[contact.attrib["uuid"]] = ca

        connection = DriverManager.getConnection("jdbc:sqlite:" + self.dbFile)
        stmt = connection.createStatement()

        chatsxml = self.element.find("Chats")
        df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
        for chat in chatsxml:
            # print self.accounts[chat.find("Account").text]
            if chat.find("Account") != None and self.accounts[chat.find("Account").text][0] in userAccounts:
                # self.chats[chat.attrib["uuid"]] = (self.accounts[chat.find("Account").text], self.accounts[chat.find("Contact").text])
                # chatlist.append((self.accounts[chat.find("Account").text], self.accounts[chat.find("Contact").text]))
                rs = stmt.executeQuery(
                    "SELECT * FROM kadu_messages WHERE chat='" + chat.attrib["uuid"] + "' ORDER BY send_time"
                )
                # conv = Conversation(0, Date(), "", 0, self.contacts[chat.find("Contact").text], self.accounts[chat.find("Account").text][0])
                # self.contacts[chat.find("Contact").text].addConversation(conv)
                # print self.contacts[chat.find("Contact").text], self.contacts[chat.find("Contact").text].getConversations().size()
                # print "Chat ", chat.attrib["uuid"]
                msgs = []
                # length = 0
                # fmsg = ""
                # date = None
                # enddate = None
                while rs.next():
                    if rs.getString("attributes")[-1] == "0":
                        recv = 1
                    else:
                        recv = 0
                    msgs.append(Message(0, None, rs.getString("content"), df.parse(rs.getString("send_time")), recv))
                    # conv.addMessage(msg)
                    # length += 1
                    self.messagesCount += 1
                    # if fmsg=="":
                    # 	fmsg=rs.getString("content")
                    # if date == None:
                    # 	date = df.parse(rs.getString("send_time"))
                    # enddate = df.parse(rs.getString("send_time"))
                    # print "\tROW = ", chat, sender, time, content, out
                    # conv.setLength(length)
                    # conv.setTime(date)
                    # conv.setEndTime(enddate)
                    # conv.setTitle(fmsg)
                    # print self.contacts[chat.find("Contact").text]
                    # print self.accounts[chat.find("Account").text][0]
                if len(msgs) > 0:
                    self.contacts[chat.find("Contact").text].setConversations(
                        ConversationHelper.messagesToConversations(
                            msgs, self.contacts[chat.find("Contact").text], self.accounts[chat.find("Account").text][0]
                        )
                    )
        self.contactsLoadProgress = 100
        return contactslist
Example #6
0
	def getContacts(self, userAccounts):
		self.contactsLoadProgress = 0
		vmsg = False
		vcard = False
		vbody = False
		msg = None
		contactAccount = None
		messages = {}
		contactAccounts = {}
		for line in self.file:
			line = line.replace('\x00', '').strip()
			if 'BEGIN:' in line:
				vsection = line.split('BEGIN:')[1]
				if vsection == 'VMSG':
					self.contactsLoadProgress = 50
					self.messagesCount += 1
					vmsg = True
					msg = Message()
					msg.message = ''
				elif vsection == 'VCARD':
					vcard = True
					if not vmsg:
						contactAccount = ContactAccount()
						contactAccount.name = ''
				elif vsection == 'VBODY':
					vbody = True
			elif 'END:' in line:
				vsection = line.split('END:')[1]
				if vsection == 'VMSG':
					vmsg = False
					messages[contactAccount].append(msg)
					msg = None
					contactAccount = None
				elif vsection == 'VCARD':
					vcard = False
					if not vmsg:
						contactAccounts[contactAccount.uid] = contactAccount
						messages[contactAccount] = []
						contactAccount = None
				elif vsection == 'VBODY':
					vbody = False
			elif vmsg:
				if line.startswith('X-IRMC-BOX'):
					if 'INBOX' in line:
						msg.setReceived(1)
					else:
						msg.setReceived(0)
				elif vcard and line.startswith('TEL:') and line[4:] <> '':
					if line[4:] in contactAccounts.keys():
						contactAccount = contactAccounts[line[4:]]
					else:
						contactAccount = ContactAccount(0, '', line[4:], '', None, self.protocol)
						if not contactAccount in contactAccounts:
							contactAccounts[contactAccount.uid] = contactAccount
							messages[contactAccount] = []
				elif vbody:
					if line.startswith('Date:'):
						df = SimpleDateFormat("yyyy.M.dd HH:mm:ss") # 30.1.2009 17:32:26
						timestamp = df.parse(line[5:])
						msg.time = timestamp
					else:
						msg.message = line
			elif vcard:
				if line.startswith('N:'):
					contactAccount.name = line[2:].replace('\\;', ' ')
				elif line.startswith('TEL'):
					contactAccount.uid = line.split(':')[1]
					contactAccount.protocol = self.protocol
		self.file.close()

		contacts = []
		for ca in contactAccounts.values():
			if ca in messages.keys() and len(messages[ca]) > 0:
				ca.conversations = ConversationHelper.messagesToConversations(messages[ca], ca, userAccounts[0])
			elif Config.getBoolean('import.omit_contacts_without_conversations') or ca.uid == None or ca.uid == '':
				continue
			names = ca.name.split(';')
			name = ''
			if len(names) > 1:
				names[0] = names[0].strip()
				names[1] = names[1].strip()
				if names[0] == '' and names[1] == '':
					name = ca.uid
				else:
					if names[1] == '':
						name = names[0]
						names[0] = ''
					elif names[1] <> '' and names[0] == '':
						name = names[1]
						names[1] = ''
					
				cnt = Contact(0, names[1], names[0], name)
			else:
				if names[0] == '' or names[0] == None:
					names[0] = ca.uid
				cnt = Contact(0, '', '', names[0])
			cnt.addContactAccount(ca)
			contacts.append(cnt)
		self.contactsLoadProgress = 100
		return contacts
Example #7
0
    def getContacts(self, userAccounts):
        self.contactsLoadProgress = 0
        vmsg = False
        vcard = False
        vbody = False
        msg = None
        contactAccount = None
        messages = {}
        contactAccounts = {}
        for line in self.file:
            line = line.replace('\x00', '').strip()
            if 'BEGIN:' in line:
                vsection = line.split('BEGIN:')[1]
                if vsection == 'VMSG':
                    self.contactsLoadProgress = 50
                    self.messagesCount += 1
                    vmsg = True
                    msg = Message()
                    msg.message = ''
                elif vsection == 'VCARD':
                    vcard = True
                    if not vmsg:
                        contactAccount = ContactAccount()
                        contactAccount.name = ''
                elif vsection == 'VBODY':
                    vbody = True
            elif 'END:' in line:
                vsection = line.split('END:')[1]
                if vsection == 'VMSG':
                    vmsg = False
                    messages[contactAccount].append(msg)
                    msg = None
                    contactAccount = None
                elif vsection == 'VCARD':
                    vcard = False
                    if not vmsg:
                        contactAccounts[contactAccount.uid] = contactAccount
                        messages[contactAccount] = []
                        contactAccount = None
                elif vsection == 'VBODY':
                    vbody = False
            elif vmsg:
                if line.startswith('X-IRMC-BOX'):
                    if 'INBOX' in line:
                        msg.setReceived(1)
                    else:
                        msg.setReceived(0)
                elif vcard and line.startswith('TEL:') and line[4:] <> '':
                    if line[4:] in contactAccounts.keys():
                        contactAccount = contactAccounts[line[4:]]
                    else:
                        contactAccount = ContactAccount(
                            0, '', line[4:], '', None, self.protocol)
                        if not contactAccount in contactAccounts:
                            contactAccounts[
                                contactAccount.uid] = contactAccount
                            messages[contactAccount] = []
                elif vbody:
                    if line.startswith('Date:'):
                        df = SimpleDateFormat(
                            "yyyy.M.dd HH:mm:ss")  # 30.1.2009 17:32:26
                        timestamp = df.parse(line[5:])
                        msg.time = timestamp
                    else:
                        msg.message = line
            elif vcard:
                if line.startswith('N:'):
                    contactAccount.name = line[2:].replace('\\;', ' ')
                elif line.startswith('TEL'):
                    contactAccount.uid = line.split(':')[1]
                    contactAccount.protocol = self.protocol
        self.file.close()

        contacts = []
        for ca in contactAccounts.values():
            if ca in messages.keys() and len(messages[ca]) > 0:
                ca.conversations = ConversationHelper.messagesToConversations(
                    messages[ca], ca, userAccounts[0])
            elif Config.getBoolean('import.omit_contacts_without_conversations'
                                   ) or ca.uid == None or ca.uid == '':
                continue
            names = ca.name.split(';')
            name = ''
            if len(names) > 1:
                names[0] = names[0].strip()
                names[1] = names[1].strip()
                if names[0] == '' and names[1] == '':
                    name = ca.uid
                else:
                    if names[1] == '':
                        name = names[0]
                        names[0] = ''
                    elif names[1] <> '' and names[0] == '':
                        name = names[1]
                        names[1] = ''

                cnt = Contact(0, names[1], names[0], name)
            else:
                if names[0] == '' or names[0] == None:
                    names[0] = ca.uid
                cnt = Contact(0, '', '', names[0])
            cnt.addContactAccount(ca)
            contacts.append(cnt)
        self.contactsLoadProgress = 100
        return contacts