Пример #1
0
        /**
         * returns true if a contact is myself
         */
        internal static bool ParseFrom(IResource article, string fromValue, out IContact contact)
        {
            if (MIMEParser.ContainsMIMEStrings(fromValue))
            {
                fromValue = ParseTools.ParseMIMEHeader(fromValue);
            }

            fromValue = fromValue.Replace("<", null).Replace(">", null).Replace("\\", null).Replace("//", null);
            string[] parts = fromValue.Split(' ');
            string   eMail = string.Empty;

            foreach (string part in parts)
            {
                if (part.IndexOf('@') >= 0)
                {
                    eMail = part;
                    break;
                }
            }
            string displayName = fromValue;

            if (eMail.Length > 0)
            {
                displayName = displayName.Replace(eMail, null).Trim();
            }
            if (eMail.Length > 0 || displayName.Length > 0)
            {
                IContactManager cm      = Core.ContactManager;
                IResource       oldFrom = article.GetLinkProp(cm.Props.LinkFrom);
                contact = cm.FindOrCreateContact(eMail, displayName);
                cm.LinkContactToResource(cm.Props.LinkFrom, contact.Resource, article, eMail, displayName);
                if (oldFrom != null && contact.Resource != oldFrom)
                {
                    cm.DeleteUnusedContacts(oldFrom.ToResourceList());
                }
                return(contact.IsMyself);
            }
            contact = null;
            return(false);
        }
Пример #2
0
        [Test] public void CreateContactBOWithoutEmailTest()
        {
            IContact contact = _contactManager.FindOrCreateContact(null, "Sergey Zhulin");

            Assert.AreEqual("Sergey", contact.FirstName);
            Assert.AreEqual("Zhulin", contact.LastName);
        }
Пример #3
0
        [Test] public void SimpleFindContactTest()
        {
            string   email   = "*****@*****.**";
            IContact contact = _contactManager.FindOrCreateContact(email, "Sergey Zhulin");

            Assert.AreEqual("Sergey", contact.FirstName);
            Assert.AreEqual("Zhulin", contact.LastName);
            IResourceList accounts = contact.Resource.GetLinksOfType("EmailAccount", "EmailAcct");

            Assert.AreEqual(1, accounts.Count);
            IResource account = accounts[0];

            Assert.AreEqual(email, account.GetPropText("EmailAddress"));
        }