Exemple #1
0
        /// <summary>
        /// Get contact details from address and name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="address">The address.</param>
        /// <returns>
        /// The <see cref="ContactDetails" />.
        /// </returns>
        internal ContactDetails GetContactDetails(string name, string address)
        {
            ContactDetails res = null;

            if (address == null)
            {
                res = this.GetContactDetails(name);
            }

            if ((res != null) || string.IsNullOrWhiteSpace(address))
            {
                return(res ?? this.GetContactDetails("unknown"));
            }

            string key = address.ToLowerInvariant();

            if (!this.ContactDetailsAddressLookup.ContainsKey(key))
            {
                this.ContactDetailsAddressLookup[key] = new ContactDetails {
                    Email = address, Name = Uncertain <string> .FromProb(name, 0.2)
                };

                if (!string.IsNullOrEmpty(name))
                {
                    this.ContactDetailsNameLookup[NormalizeName(name)] = this.ContactDetailsAddressLookup[key];
                }
            }

            res = this.ContactDetailsAddressLookup[key];

            return(res ?? this.GetContactDetails("unknown"));
        }
Exemple #2
0
        /// <summary>
        /// Get contact details from item address and name.
        /// </summary>
        /// <param name="conversation">The conversation.</param>
        /// <param name="name">The name.</param>
        /// <param name="address">The address.</param>
        /// <returns>
        /// The <see cref="ContactDetails" />.
        /// </returns>
        internal ContactDetails GetContactDetails(Conversation conversation, string name, string address)
        {
            if (address != null)
            {
                address = address.Trim('<', '>', '\'', '\"');
            }

            var contactDetails = this.GetContactDetails(name, address);

            if (string.IsNullOrEmpty(name))
            {
                if (!string.IsNullOrWhiteSpace(address))
                {
                    contactDetails.Name = Uncertain <string> .FromProb(address, 0.1);
                }
            }
            else
            {
                string s = name.Trim('<', '>', '\'', '\"');
                if (s.EndsWith("(" + address + ")"))
                {
                    if (address != null)
                    {
                        s = s.Substring(0, s.Length - (address.Length + 2));
                    }

                    s = s.TrimEnd();
                }

                int k = s.IndexOf('@');
                if (k != -1)
                {
                    if (contactDetails.Name.Probability <= 0.5)
                    {
                        // don't want to overwrite a name that is more certain with a name truncated from an email address
                        contactDetails.Name = Uncertain <string> .FromProb(s.Substring(0, k).Replace('.', ' '), 0.5);
                    }
                }
                else
                {
                    if (contactDetails.Name.Probability <= 1.0)
                    {
                        contactDetails.Name = Uncertain <string> .FromProb(s, 1.0); // a name that didn't have an @
                    }
                }
            }

            return(contactDetails);
        }
Exemple #3
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Uncertain <T>))
            {
                return(false);
            }

            Uncertain <T> unc = (Uncertain <T>)obj;

            if (ReferenceEquals(this.Value, null))
            {
                return(ReferenceEquals(unc.Value, null));
            }

            return(this.Value.Equals(unc.Value));
        }
Exemple #4
0
        /// <summary>
        /// Get contact details from name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>
        /// The <see cref="ContactDetails" />.
        /// </returns>
        internal ContactDetails GetContactDetails(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            string name2 = NormalizeName(name);

            if (!this.ContactDetailsNameLookup.ContainsKey(name2))
            {
                this.ContactDetailsNameLookup[name2] = new ContactDetails
                {
                    Name = Uncertain <string> .FromProb(name, 0.2)
                };
            }

            return(this.ContactDetailsNameLookup[name2]);
        }