def add(self):
        """
        Add an address from From: field of a mail. This assumes a single mail file is supplied through stdin. . 
        """

        fromLine = ""
        for l in sys.stdin:
            if l.startswith("From: "):
                fromLine = l
                break
        if fromLine == "":
            print "Not a valid mail file!"
            sys.exit(2)
        #In a line like
        #From: John Doe <*****@*****.**>
        els = fromLine.split()
        #Drop "From: "
        del els[0]
        #get the last element as mail
        mailaddr = els[-1]
        if mailaddr.startswith("<"):
            mailaddr = mailaddr[1:]
        if mailaddr.endswith(">"):
            mailaddr = mailaddr[:-1]
        #and the rest as name
        name = " ".join(els[:-1])
        #save to contacts
        client = ContactsService()
        client.ClientLogin(self.username, self.password)
        new_contact = ContactEntry(title=atom.Title(text=name))
        new_contact.email.append(Email(address=mailaddr, primary='true'))
        contact_entry = client.CreateContact(new_contact)
        print contact_entry
    def fetch(self):
        """
        Actually go out on the wire and fetch the addressbook.

        """
        client = ContactsService()
        client.ClientLogin(self.username, self.password)
        query = ContactsQuery()
        query.max_results = self.max_results
        feed = client.GetContactsFeed(query.ToUri())
        for e in feed.entry:
            for i in e.email:
                if e.title.text:
                    self.addrbk[i.address] = e.title.text
                else:
                    self.addrbk[i.address] = i.address