Exemplo n.º 1
0
        private string GetEmailForName(string name)
        {
#if ENABLE_EVO_SHARP
            if (name == null || name == "")
            {
                return(null);
            }

            Evolution.Book addressbook = null;


            // If we've previously failed to open the
            // addressbook, don't keep trying.
            if (ebook_failed)
            {
                return(null);
            }

            // We keep a little cache so we don't have to query
            // the addressbook too often.
            if (buddy_emails.Contains(name))
            {
                string str = (string)buddy_emails[name];
                return(str != "" ? str : null);
            }

            // Connect to the Evolution addressbook.
            try {
                addressbook = Evolution.Book.NewSystemAddressbook();
                addressbook.Open(true);
            } catch (Exception e) {
                Console.WriteLine("\nCould not open Evolution addressbook:\n" + e);
                ebook_failed = true;
                return(null);
            }

            // Do a search.
            string qstr =
                String.Format("(is \"full_name\" \"{0}\")", name);

            Evolution.BookQuery  query   = Evolution.BookQuery.FromString(qstr);
            Evolution.Contact [] matches = addressbook.GetContacts(query);
            foreach (Evolution.Contact c in matches)
            {
                Console.WriteLine("FIXME: querying the evolution addressbook instead of using Lucene, this is slow and dumb");
                Console.WriteLine("Got match: {0} {1}", c.FullName, c.Email1);
                if (c.Email1 != null)
                {
                    buddy_emails[name] = c.Email1;
                    return(c.Email1);
                }
            }
            buddy_emails[name] = "";
#endif

            return(null);
        }
Exemplo n.º 2
0
        private void GetImNames(string who)
        {
            if (who == null || who == "")
            {
                return;
            }

            Evolution.Book addressbook = null;

            if (ebook_failed)
            {
                return;
            }

            try {
                addressbook = Evolution.Book.NewSystemAddressbook();
                addressbook.Open(true);
            } catch (Exception e) {
                Console.WriteLine("\nCould not open Evolution addressbook:\n" + e);
                ebook_failed = true;
                return;
            }

            string email = GetEmail(who);

            System.Console.WriteLine("Looking for im name for {0}",
                                     email);
            System.Console.WriteLine("FIXME: This query is using the Evolution addressbook instead of querying Beagle directly.  This is slow, dumb, etc.");

            string qstr =
                String.Format("(is \"email\" \"{0}\")", email);

            Evolution.BookQuery query = Evolution.BookQuery.FromString(qstr);

            if (query == null)
            {
                return;
            }

            Evolution.Contact[] matches = addressbook.GetContacts(query);
            foreach (Evolution.Contact c in matches)
            {
                if (c.ImAim.Length > 0)
                {
                    aim_name = c.ImAim[0];
                }
                if (c.ImIcq.Length > 0)
                {
                    icq_name = c.ImIcq[0];
                }
                if (c.ImJabber.Length > 0)
                {
                    jabber_name = c.ImJabber[0];
                }
                if (c.ImMsn.Length > 0)
                {
                    msn_name = c.ImMsn[0];
                }
                if (c.ImYahoo.Length > 0)
                {
                    yahoo_name = c.ImYahoo[0];
                }
                if (c.ImGroupwise.Length > 0)
                {
                    groupwise_name = c.ImGroupwise[0];
                }
            }
        }