Example #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
Example #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
Example #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
Example #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
config = {
    "username":     os.environ.get("TEST_USERNAME","*****@*****.**"),
    "password":     os.environ["TEST_PASSWORD"],
}
test.configure(sink=config)
google = test.get_sink().module

#Log in
try:
    google.refresh()
    ok("Logged in", google.loggedIn == True)
except Exception, err:
    ok("Logged in (%s)" % err, False) 

#make a new contact with a random email address (so it doesnt conflict)
contact = Contact.parse_vcf(vcfData % Utils.random_string())[0]
test.do_dataprovider_tests(
        supportsGet=True,
        supportsDelete=True,
        safeLUID=SAFE_CONTACT_ID,
        data=contact,
        name="contact"
        )

#check we get a conflict if we put a contact with a known existing email address
#FIXME: We should actually automatically resolve this conflict...
contact = new_contact(None)
try:
    google.put(contact, False)
    ok("Detected duplicate email", False)
except Exceptions.SynchronizeConflictError:
Example #6
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
Example #7
0
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD
BEGIN:VCARD
VERSION:3.0
FN:STA Travel Canterbury Uni
N:Uni;STA;Travel Canterbury;;
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD"""

c = Contact.Contact()
ok("Created blank contact", len(c.get_vcard_string()) > 0)

c = Contact.Contact(formattedName="Im Cool", givenName="Steve", familyName="Cool")
ok("Created contact", len(c.get_vcard_string()) > 0)

contacts = Contact.parse_vcf(vcfData)
ok("Parsed vcf file (got %s vcards)" % len(contacts), len(contacts) == vcfData.count("BEGIN:VCARD"))

c = contacts[-1]
ok("Got vcard data", len(c.get_vcard_string()) > 0)
ok("Got email addresses", len(c.get_emails()) > 0)
ok("Got name", c.get_name() != None)

#now add email addresses
emails = ("*****@*****.**","baz@f")
numb4 = len(c.get_emails())
c.set_emails(*emails)
numAfta = len(c.get_emails())
ok("Added email addresses", numAfta == (numb4 | len(emails)))

finished()
Example #8
0
 def idevice_contact_to_contact(self, data, **kwargs):
     c = Contact.Contact(vcard=data.get_vcard())
     return c