Exemplo n.º 1
0
 def text_to_contact(self, text, **kwargs):
     c = None
     try:
         c = Contact.Contact()
         c.set_from_vcard_string(text.get_string())
     except:
         c = None
         log.warn("Error converting text to contact")
     return c
Exemplo n.º 2
0
 def file_to_contact(self, f, **kwargs):
     c = None
     if f.get_mimetype().split('/')[0] == "text":
         try:
             c = Contact.Contact()
             c.set_from_vcard_string(f.get_contents_as_text())
         except:
             c = None
             log.warn("Error converting file to contact")
     return c
Exemplo n.º 3
0
 def _get_object(self, LUID):
     """
     Retrieve a specific contact object from evolution
     """
     obj = self.book.get_contact(LUID)
     contact = Contact.Contact()
     contact.set_from_vcard_string(obj.get_vcard_string())
     contact.set_UID(obj.get_uid())
     contact.set_mtime(datetime.datetime.fromtimestamp(obj.get_modified()))
     return contact
Exemplo n.º 4
0
    def get(self, LUID):
        DataProvider.TwoWay.get(self, LUID)
        fullpath = os.path.join(self.dataDir, LUID)
        f = File.File(URI=fullpath)

        contact = Contact.Contact()
        contact.set_from_vcard_string(f.get_contents_as_text())
        contact.set_open_URI(fullpath)
        contact.set_mtime(f.get_mtime())
        contact.set_UID(LUID)
        return contact
Exemplo n.º 5
0
    def _blob_to_data(self, uid, blob):
        parser = xml.dom.minidom.parseString(blob)
        root = parser.getElementsByTagName("contact")[0]

        c = Contact.Contact()
        c.set_UID(uid)

        def S(node):
            if node and node[0].childNodes:
                return node[0].firstChild.wholeText
            return ""

        for node in root.childNodes:
            if node.nodeName == "FileAs":
                pass
            elif node.nodeName == "FormattedName":
                try:
                    c.vcard.fn
                except:
                    c.vcard.add('fn')
                c.vcard.fn.value = S(node.getElementsByTagName('Content'))
            elif node.nodeName == "Name":
                family = S(node.getElementsByTagName('LastName'))
                given = S(node.getElementsByTagName('FirstName'))
                try:
                    c.vcard.n
                except:
                    c.vcard.add('n')
                c.vcard.n.value = vobject.vcard.Name(family=family,
                                                     given=given)
            elif node.nodeName == "Nickname":
                pass
            elif node.nodeName == "EMail":
                email = c.vcard.add('email')
                email.value = S(node.getElementsByTagName('Content'))
                email.type_param = 'INTERNET'
            elif node.nodeName == "Photo":
                pass
            elif node.nodeName == "Categories":
                pass
            elif node.nodeName == "Assistant":
                pass
            elif node.nodeName == "Manager":
                pass
            elif node.nodeName == "Organization":
                pass
            elif node.nodeName == "Spouse":
                pass
            elif node.nodeName == "Telephone":
                tel = c.vcard.add('tel')
                tel.value = S(node.getElementsByTagName('Content'))
                for type_param in node.getElementsByTagName('Type'):
                    tel.params.setdefault('TYPE', []).append(S([type_param]))
            elif node.nodeName == "Title":
                pass
            elif node.nodeName == "Url":
                pass
            elif node.nodeName == "Uid":
                pass
            elif node.nodeName == "Revision":
                pass
            else:
                log.warning("Unhandled node: %s" % node.nodeName)

        return c
Exemplo n.º 6
0
 def idevice_contact_to_contact(self, data, **kwargs):
     c = Contact.Contact(vcard=data.get_vcard())
     return c