예제 #1
0
        private static AnrManager.NameParsingResult ParseNameBeforeAnr(string name, AnrManager.Options options)
        {
            AnrManager.NameParsingResult result = new AnrManager.NameParsingResult(name);
            Participant participant;

            if (AnrManager.TryParseParticipant(name, options, out participant))
            {
                result.ParsedSuccessfully = true;
                result.RoutingType        = participant.RoutingType;
                result.RoutingAddress     = participant.EmailAddress;
            }
            return(result);
        }
예제 #2
0
        private static void GetNamesByAnrFromContacts(UserContext userContext, AnrManager.NameParsingResult parsingResult, AnrManager.Options options, List <RecipientAddress> addresses)
        {
            if (string.IsNullOrEmpty(parsingResult.Name))
            {
                return;
            }
            if (userContext.TryGetMyDefaultFolderId(DefaultFolderType.Contacts) == null)
            {
                return;
            }
            string ambiguousName = parsingResult.ParsedSuccessfully ? parsingResult.RoutingAddress : parsingResult.Name;

            using (ContactsFolder contactsFolder = ContactsFolder.Bind(userContext.MailboxSession, DefaultFolderType.Contacts))
            {
                if (contactsFolder.IsValidAmbiguousName(ambiguousName))
                {
                    PropertyDefinition[] array;
                    object[][]           results;
                    if (AnrManager.IsMobileNumberInput(parsingResult, options))
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactFindSomeone, options);
                        results = contactsFolder.FindNamesView(new Dictionary <PropertyDefinition, object>
                        {
                            {
                                ContactSchema.MobilePhone,
                                parsingResult.Name
                            }
                        }, AnrManager.nameLimit, null, array);
                    }
                    else if (options.ResolveAgainstAllContacts || options.IsDefaultRoutingType("MOBILE"))
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactFindSomeone, options);
                        results = contactsFolder.FindSomeoneView(ambiguousName, AnrManager.nameLimit, null, array);
                    }
                    else
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactAnr, options);
                        results = contactsFolder.ResolveAmbiguousNameView(ambiguousName, AnrManager.nameLimit, null, array);
                    }
                    AnrManager.AddContacts(userContext, options, array, results, addresses);
                }
            }
        }
예제 #3
0
        private static bool IsMobileAddressExactMatch(AnrManager.NameParsingResult parsingResult, RecipientAddress address)
        {
            if (!parsingResult.ParsedSuccessfully)
            {
                return(false);
            }
            if (!Utilities.IsMobileRoutingType(parsingResult.RoutingType))
            {
                return(false);
            }
            if (!Utilities.IsMobileRoutingType(address.RoutingType))
            {
                return(false);
            }
            E164Number objA = null;
            E164Number objB = null;

            return(E164Number.TryParse(parsingResult.RoutingAddress, out objA) && E164Number.TryParse(address.RoutingAddress, out objB) && object.Equals(objA, objB));
        }
예제 #4
0
 public static void ResolveOneRecipient(string name, UserContext userContext, List <RecipientAddress> addresses, AnrManager.Options options)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (userContext == null)
     {
         throw new ArgumentNullException("userContext");
     }
     if (addresses == null)
     {
         throw new ArgumentNullException("addresses");
     }
     AnrManager.NameParsingResult parsingResult = AnrManager.ParseNameBeforeAnr(name, options);
     if (!options.ResolveOnlyFromAddressBook && userContext.IsFeatureEnabled(Feature.Contacts))
     {
         AnrManager.GetNamesByAnrFromContacts(userContext, parsingResult, options, addresses);
     }
     AnrManager.GetNamesByAnrFromAD(userContext, parsingResult, options, addresses);
     if (AnrManager.IsMobileNumberInput(parsingResult, options) && addresses.Count > 0)
     {
         bool flag = false;
         foreach (RecipientAddress address in addresses)
         {
             if (AnrManager.IsMobileAddressExactMatch(parsingResult, address))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             RecipientAddress recipientAddress = AnrManager.ResolveAnrStringToOneOffEmail(name, options);
             if (recipientAddress != null)
             {
                 addresses.Add(recipientAddress);
             }
         }
     }
     addresses.Sort();
 }
예제 #5
0
 public static RecipientAddress ResolveAnrString(string name, AnrManager.Options options, UserContext userContext)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     if (userContext == null)
     {
         throw new ArgumentNullException("userContext");
     }
     if (Globals.ArePerfCountersEnabled)
     {
         OwaSingleCounters.NamesChecked.Increment();
     }
     AnrManager.NameParsingResult parsingResult = AnrManager.ParseNameBeforeAnr(name, options);
     if (options.ResolveContactsFirst)
     {
         return(AnrManager.ResolveAnrStringFromContacts(userContext, parsingResult, options, () => AnrManager.ResolveAnrStringFromAD(userContext, parsingResult, options, () => AnrManager.ResolveAnrStringToOneOffEmail(name, options))));
     }
     return(AnrManager.ResolveAnrStringFromAD(userContext, parsingResult, options, () => AnrManager.ResolveAnrStringFromContacts(userContext, parsingResult, options, () => AnrManager.ResolveAnrStringToOneOffEmail(name, options))));
 }
예제 #6
0
        private static void GetNamesByAnrFromAD(UserContext userContext, AnrManager.NameParsingResult parsingResult, AnrManager.Options options, List <RecipientAddress> addresses)
        {
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(Culture.GetUserCulture().LCID, true, ConsistencyMode.IgnoreInvalid, true, userContext);

            ADRawEntry[] array = null;
            bool         flag  = parsingResult.ParsedSuccessfully && !Utilities.IsMobileRoutingType(parsingResult.RoutingType);
            string       text  = flag ? string.Format("{0}:{1}", parsingResult.RoutingType, parsingResult.RoutingAddress) : parsingResult.Name;

            if (flag)
            {
                ADRawEntry adrawEntry = recipientSession.FindByProxyAddress(ProxyAddress.Parse(text), AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.AD, options));
                if (adrawEntry != null)
                {
                    if ((bool)adrawEntry[ADRecipientSchema.HiddenFromAddressListsEnabled])
                    {
                        array = new ADRawEntry[0];
                        ExTraceGlobals.CoreTracer.TraceDebug <ADObjectId>(0L, "AnrManager.GetNamesByAnrFromAD: Recipient ignored because it is hiddem from address lists: {0}", adrawEntry.Id);
                    }
                    else
                    {
                        array = new ADRawEntry[]
                        {
                            adrawEntry
                        };
                    }
                }
            }
            if (array == null)
            {
                QueryFilter filter = new AndFilter(new QueryFilter[]
                {
                    new AmbiguousNameResolutionFilter(text),
                    AnrManager.addressListMembershipExists
                });
                array = recipientSession.Find(null, QueryScope.SubTree, filter, null, AnrManager.nameLimit, AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.AD, options));
            }
            AnrManager.AddADRecipients(array, options, addresses);
        }
예제 #7
0
 private static bool IsMobileNumberInput(AnrManager.NameParsingResult parsingResult, AnrManager.Options options)
 {
     return(parsingResult.ParsedSuccessfully && AnrManager.AreNameAndAddressTheSameNumber(options, parsingResult.RoutingType, parsingResult.Name, parsingResult.RoutingAddress));
 }
예제 #8
0
        private static RecipientAddress ResolveAnrStringFromAD(UserContext userContext, AnrManager.NameParsingResult parsingResult, AnrManager.Options options, AnrManager.NextOperation nextOperation)
        {
            List <RecipientAddress> list = new List <RecipientAddress>();

            AnrManager.GetNamesByAnrFromAD(userContext, parsingResult, options, list);
            if (list.Count == 1)
            {
                if (!AnrManager.IsMobileNumberInput(parsingResult, options) || AnrManager.IsMobileAddressExactMatch(parsingResult, list[0]))
                {
                    return(list[0]);
                }
                return(null);
            }
            else
            {
                if (list.Count > 1)
                {
                    return(null);
                }
                if (nextOperation != null)
                {
                    return(nextOperation());
                }
                return(null);
            }
        }