Initial Project Commit
[retroconv] / contactsServ.py
diff --git a/contactsServ.py b/contactsServ.py
new file mode 100644 (file)
index 0000000..93e5fa3
--- /dev/null
@@ -0,0 +1,112 @@
+import evolution
+from pygobject import *
+from ctypes import *
+#from wrapper import *
+
+
+ebook = CDLL('libebook-1.2.so.9')
+E_CONTACT_HOMEPAGE_URL = 42
+E_CONTACT_PHOTO = 94
+E_CONTACT_EMAIL = 97
+E_CONTACT_BIRTHDAY_DATE = 107
+
+class address_book:
+               
+       def getContactNameFromPhone(self, phoneNum):
+               
+
+               addresses = evolution.ebook.open_addressbook('default')
+               contacts = addresses.get_all_contacts()
+
+
+                #ai = GList.new(ebook.e_contact_get_attributes(hash(self._contact), E_CONTACT_EMAIL))
+
+               for econtact in contacts:
+                       
+                       try: 
+                               #print econtact.get_name()
+                               phones = econtact.get_property('phone') 
+                               
+                               phones_p=int(str(phones)[13:-1],16)
+                               phoneList = GList.new(phones_p)
+                               
+                               while phoneList.has_next():
+                                       currPhone = string_at(phoneList.next())
+                                       
+                                       if currPhone == phoneNum:
+                                               return econtact.get_name()
+                       except:
+                               continue
+                               
+                               
+                               
+       
+       def populateNames(self, recvLst, sentLst):
+               
+               addresses = evolution.ebook.open_addressbook('default')
+               contacts = addresses.get_all_contacts()
+               
+               listX=[]
+               
+               
+               """"for msg in recvLst:
+                       for contact in contacts:
+                               try:
+                                       phones = contact.get_property('phone')  
+                                       phones_p=int(str(phones)[13:-1],16)
+                               except:
+                                       continue
+                                       
+                               phoneList = GList.new(phones_p)
+                               
+                               while phoneList.has_next():
+                                       currPhone = string_at(phoneList.next())
+                                       if currPhone[-7:] == msg.fromNum[-7:]:
+                                               msg.setSenderName(contact.get_name())
+                                               break
+               """
+               
+               for contact in contacts:
+               
+                       try:
+                               phones = contact.get_property('phone')  
+                               phones_p=int(str(phones)[13:-1],16)
+                               phoneList = GList.new(phones_p)
+                               
+                               
+                               
+                                       
+                               
+                               
+                               
+                               
+                               
+                               while phoneList.has_next():
+                                       currPhone = string_at(phoneList.next())
+                                       for msg in recvLst:
+                                               if currPhone[-7:] == msg.fromNum[-7:]:
+                                                       msg.setSenderName(contact.get_name())
+                                                       photo = contact.get_property('photo')
+                                                       pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
+                                                       
+                                                       if pi.contents.data.uri.startswith("image/"):
+                                                               #data = string_at(pi.contents.data.inlined.data)
+                                                               data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
+                                                               length = pi.contents.data.inlined.length
+                                                               msg.setImageData(data, length)
+                                               
+                                       for msg in sentLst:
+                                               if currPhone[-7:] == msg.toNum[-7:]:
+                                                       msg.setRecName(contact.get_name())
+                                                       photo = contact.get_property('photo')
+                                                       pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
+                                                       
+                                                       if pi.contents.data.uri.startswith("image/"):
+                                                               #data = string_at(pi.contents.data.inlined.data)
+                                                               data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
+                                                               length = pi.contents.data.inlined.length
+                                                               msg.setImageData(data, length)
+                                                               
+                                                       
+                       except:
+                               continue