// Token: 0x06000172 RID: 370 RVA: 0x0000A128 File Offset: 0x00008328
        private static SmtpAddress GetDiscoveryHolds(DiscoverySearchDataProvider dataProvider, Dictionary <string, MailboxDiscoverySearch> discoveryHolds)
        {
            SmtpAddress       smtpAddress     = SmtpAddress.Empty;
            ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), OrganizationId.ForestWideOrgId, null, false);
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 324, "GetDiscoveryHolds", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\elc\\DiscoveryHoldSynchronizer.cs");

            foreach (MailboxDiscoverySearch mailboxDiscoverySearch in dataProvider.GetAll <MailboxDiscoverySearch>())
            {
                if (mailboxDiscoverySearch.InPlaceHoldEnabled)
                {
                    discoveryHolds.Add(mailboxDiscoverySearch.InPlaceHoldIdentity, mailboxDiscoverySearch);
                    if (smtpAddress == SmtpAddress.Empty)
                    {
                        Result <ADRawEntry>[] first = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDNs(mailboxDiscoverySearch.Sources.ToArray(), new ADPropertyDefinition[]
                        {
                            ADRecipientSchema.RecipientType,
                            ADRecipientSchema.RecipientTypeDetails,
                            ADUserSchema.ArchiveDomain,
                            ADUserSchema.ArchiveGuid,
                            ADRecipientSchema.RawExternalEmailAddress,
                            ADUserSchema.ArchiveStatus
                        });
                        foreach (ADRawEntry adrawEntry in from x in first
                                 select x.Data)
                        {
                            if (adrawEntry != null)
                            {
                                RecipientType        recipientType        = (RecipientType)adrawEntry[ADRecipientSchema.RecipientType];
                                RecipientTypeDetails recipientTypeDetails = (RecipientTypeDetails)adrawEntry[ADRecipientSchema.RecipientTypeDetails];
                                SmtpDomain           smtpDomain           = (SmtpDomain)adrawEntry[ADUserSchema.ArchiveDomain];
                                ArchiveStatusFlags   archiveStatusFlags   = (ArchiveStatusFlags)adrawEntry[ADUserSchema.ArchiveStatus];
                                if (RemoteMailbox.IsRemoteMailbox(recipientTypeDetails))
                                {
                                    smtpAddress = new SmtpAddress(((ProxyAddress)adrawEntry[ADRecipientSchema.RawExternalEmailAddress]).AddressString);
                                }
                                else if (recipientType == RecipientType.UserMailbox && smtpDomain != null && !string.IsNullOrEmpty(smtpDomain.Domain) && (archiveStatusFlags & ArchiveStatusFlags.Active) == ArchiveStatusFlags.Active)
                                {
                                    Guid guid = (Guid)adrawEntry[ADUserSchema.ArchiveGuid];
                                    if (guid != Guid.Empty)
                                    {
                                        smtpAddress = new SmtpAddress(SmtpProxyAddress.EncapsulateExchangeGuid(smtpDomain.Domain, guid));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(smtpAddress);
        }
        public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action)
        {
            if (owaContext == null)
            {
                throw new ArgumentNullException("owaContext");
            }
            applicationElement = ApplicationElement.NotSet;
            type   = string.Empty;
            action = string.Empty;
            state  = string.Empty;
            PreFormActionResponse preFormActionResponse = new PreFormActionResponse();
            HttpContext           httpContext           = owaContext.HttpContext;
            string            queryStringParameter      = Utilities.GetQueryStringParameter(httpContext.Request, "lDn", true);
            IRecipientSession recipientSession          = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, owaContext.UserContext);

            Result <ADRawEntry>[] array = recipientSession.FindByLegacyExchangeDNs(new string[]
            {
                queryStringParameter
            }, ItemReadADObjectPreFormAction.recipientQueryProperties);
            if (array == null || array.Length != 1)
            {
                throw new OwaADObjectNotFoundException();
            }
            ADRawEntry data       = array[0].Data;
            ADObjectId adobjectId = null;

            if (data != null)
            {
                adobjectId = (ADObjectId)data[ADObjectSchema.Id];
            }
            if (adobjectId == null)
            {
                throw new OwaADObjectNotFoundException();
            }
            preFormActionResponse.ApplicationElement = ApplicationElement.Item;
            preFormActionResponse.Action             = string.Empty;
            preFormActionResponse.AddParameter("id", Convert.ToBase64String(adobjectId.ObjectGuid.ToByteArray()));
            if (Utilities.IsADDistributionList((MultiValuedProperty <string>)data[ADObjectSchema.ObjectClass]))
            {
                preFormActionResponse.Type = "ADDistList";
            }
            else
            {
                preFormActionResponse.Type = "AD.RecipientType.User";
            }
            return(preFormActionResponse);
        }
        internal static List <ADRawEntry> FindMailboxesInAD(IRecipientSession recipientSession, string[] legacyExchangeDNs, List <string> notFoundMailboxes)
        {
            List <ADRawEntry> list = new List <ADRawEntry>(legacyExchangeDNs.Length);

            Result <ADRawEntry>[] array = recipientSession.FindByLegacyExchangeDNs(legacyExchangeDNs, MailboxInfo.PropertyDefinitionCollection);
            if (array != null && array.Length > 0)
            {
                Dictionary <string, ADRawEntry> dictionary = new Dictionary <string, ADRawEntry>(array.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    ADRawEntry data = array[i].Data;
                    if (data != null)
                    {
                        string key = (string)data[ADRecipientSchema.LegacyExchangeDN];
                        if (!dictionary.ContainsKey(key))
                        {
                            dictionary.Add(key, data);
                        }
                        foreach (string text in legacyExchangeDNs)
                        {
                            if (!dictionary.ContainsKey(text) && Util.CheckLegacyDnExistInProxyAddresses(text, data))
                            {
                                dictionary.Add(text, data);
                                break;
                            }
                        }
                    }
                }
                foreach (string text2 in legacyExchangeDNs)
                {
                    if (dictionary.ContainsKey(text2))
                    {
                        list.Add(dictionary[text2]);
                    }
                    else
                    {
                        notFoundMailboxes.Add(text2);
                    }
                }
            }
            else
            {
                notFoundMailboxes.AddRange(legacyExchangeDNs);
            }
            return(list);
        }
        // Token: 0x06002E47 RID: 11847 RVA: 0x00108A00 File Offset: 0x00106C00
        private string GetSipUriFromLegacyDn(string legacyDn, string defaultSipUri)
        {
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, base.OwaContext.UserContext);

            Result <ADRawEntry>[] array = recipientSession.FindByLegacyExchangeDNs(new string[]
            {
                legacyDn
            }, InstantMessageEventHandler.recipientQueryProperties);
            if (array == null || array.Length != 1)
            {
                return(defaultSipUri);
            }
            ADRawEntry data = array[0].Data;

            if (data == null)
            {
                return(defaultSipUri);
            }
            return(InstantMessageUtilities.GetSipUri((ProxyAddressCollection)data[ADRecipientSchema.EmailAddresses]));
        }
예제 #5
0
        public static Result <ADRawEntry>[] FindAdResultsByLegacyExchangeDNs(IEnumerator <Participant> recipients, UserContext userContext)
        {
            List <string> list = new List <string>();

            while (recipients.MoveNext())
            {
                Participant participant = recipients.Current;
                if (participant.RoutingType == "EX" && !string.IsNullOrEmpty(participant.EmailAddress))
                {
                    list.Add(participant.EmailAddress);
                }
            }
            if (list.Count > 0)
            {
                string[]          legacyExchangeDNs = list.ToArray();
                IRecipientSession recipientSession  = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext);
                return(recipientSession.FindByLegacyExchangeDNs(legacyExchangeDNs, AdRecipientBatchQuery.recipientQueryProperties));
            }
            return(null);
        }
예제 #6
0
 internal MailboxSearchObject(MailboxDiscoverySearch discoverySearch, OrganizationId orgId)
 {
     if (discoverySearch == null)
     {
         throw new ArgumentNullException("discoverySearch");
     }
     this.discoverySearch = discoverySearch;
     if (orgId != null)
     {
         ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), orgId, null, false);
         IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.PartiallyConsistent, sessionSettings, 791, ".ctor", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxSearchObject.cs");
         if (this.discoverySearch.Sources != null && this.discoverySearch.Sources.Count > 0)
         {
             if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
             {
                 tenantOrRootOrgRecipientSession.SessionSettings.IncludeInactiveMailbox = true;
             }
             Result <ADRawEntry>[] array = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDNs(this.discoverySearch.Sources.ToArray(), null);
             if (array != null && array.Length > 0)
             {
                 this.sourceMailboxes = new MultiValuedProperty <ADObjectId>();
                 for (int i = 0; i < array.Length; i++)
                 {
                     if (array[i].Data != null)
                     {
                         this.sourceMailboxes.Add(array[i].Data.Id);
                     }
                 }
             }
         }
         if (!string.IsNullOrEmpty(this.discoverySearch.Target))
         {
             tenantOrRootOrgRecipientSession.SessionSettings.IncludeInactiveMailbox = false;
             ADRawEntry adrawEntry = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(this.discoverySearch.Target);
             if (adrawEntry != null)
             {
                 this.targetMailbox = adrawEntry.Id;
             }
         }
     }
 }
예제 #7
0
 protected override bool TryGetGroupInfo(IRecipientSession session, string group, out Guid objectGuid, out Microsoft.Exchange.Data.Directory.Recipient.RecipientType recipientType, out int ldapQueries)
 {
     ldapQueries = 0;
     if (!string.IsNullOrEmpty(group))
     {
         Result <ADRawEntry>[] array = session.FindByLegacyExchangeDNs(new string[]
         {
             group
         }, IsMemberOfResolverADAdapter <RoutingAddress> .properties);
         ldapQueries = 1;
         if (array != null && array.Length > 0 && array[0].Data != null)
         {
             ADRawEntry data = array[0].Data;
             objectGuid    = data.Id.ObjectGuid;
             recipientType = (Microsoft.Exchange.Data.Directory.Recipient.RecipientType)data[ADRecipientSchema.RecipientType];
             return(true);
         }
     }
     objectGuid    = Guid.Empty;
     recipientType = Microsoft.Exchange.Data.Directory.Recipient.RecipientType.Invalid;
     return(false);
 }
예제 #8
0
        public static void RemoveInvalidRecipientsFromSmsMessage(MessageItem message)
        {
            Dictionary <RecipientItemType, List <string> > dictionary = null;
            int i = message.Recipients.Count - 1;

            while (i >= 0)
            {
                Participant participant  = message.Recipients[i].Participant;
                string      routingType  = participant.RoutingType;
                string      emailAddress = participant.EmailAddress;
                if (string.Equals(routingType, "SMTP", StringComparison.OrdinalIgnoreCase) && ImceaAddress.IsImceaAddress(emailAddress))
                {
                    Utilities.TryDecodeImceaAddress(participant.EmailAddress, ref routingType, ref emailAddress);
                }
                if (Utilities.IsMobileRoutingType(routingType))
                {
                    if (string.IsNullOrEmpty(Utilities.NormalizePhoneNumber(emailAddress)))
                    {
                        goto IL_D3;
                    }
                }
                else
                {
                    if (string.Equals(routingType, "EX", StringComparison.OrdinalIgnoreCase))
                    {
                        if (dictionary == null)
                        {
                            dictionary = new Dictionary <RecipientItemType, List <string> >(3);
                        }
                        RecipientItemType recipientItemType = message.Recipients[i].RecipientItemType;
                        if (!dictionary.ContainsKey(recipientItemType))
                        {
                            dictionary[recipientItemType] = new List <string>(message.Recipients.Count - 1);
                        }
                        dictionary[recipientItemType].Add(emailAddress);
                        goto IL_D3;
                    }
                    goto IL_D3;
                }
IL_DF:
                i--;
                continue;
IL_D3:
                message.Recipients.RemoveAt(i);
                goto IL_DF;
            }
            if (dictionary == null || dictionary.Count == 0)
            {
                return;
            }
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, UserContextManager.GetUserContext());

            foreach (KeyValuePair <RecipientItemType, List <string> > keyValuePair in dictionary)
            {
                Result <ADRawEntry>[] array = recipientSession.FindByLegacyExchangeDNs(keyValuePair.Value.ToArray(), new PropertyDefinition[]
                {
                    ADRecipientSchema.DisplayName,
                    ADOrgPersonSchema.MobilePhone
                });
                if (array != null && array.Length != 0)
                {
                    foreach (Result <ADRawEntry> result in array)
                    {
                        if (result.Data != null)
                        {
                            string text  = result.Data[ADRecipientSchema.DisplayName] as string;
                            string text2 = Utilities.NormalizePhoneNumber(result.Data[ADOrgPersonSchema.MobilePhone] as string);
                            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
                            {
                                message.Recipients.Add(new Participant(text, text2, "MOBILE"), keyValuePair.Key);
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        private GetGroupResponse GetPDLData()
        {
            GetGroupResponse getGroupResponse = new GetGroupResponse();
            MailboxSession   mailboxIdentityMailboxSession = base.CallContext.SessionCache.GetMailboxIdentityMailboxSession();
            ItemId           sourceId     = this.itemId;
            IdAndSession     idAndSession = null;

            if (this.parentFolderid != null && this.parentFolderid.BaseFolderId != null)
            {
                IdAndSession idAndSession2 = base.GetIdAndSession(this.parentFolderid.BaseFolderId);
                if (idAndSession2 != null && idAndSession2.Session.IsPublicFolderSession)
                {
                    idAndSession = idAndSession2;
                }
            }
            if (IdConverter.EwsIdIsConversationId(this.itemId.Id))
            {
                try
                {
                    Persona persona;
                    if (idAndSession != null)
                    {
                        persona = Persona.LoadFromPersonaId(idAndSession.Session, null, this.itemId, Persona.FullPersonaShape, null, idAndSession.Id);
                    }
                    else
                    {
                        persona = Persona.LoadFromPersonIdWithGalAggregation(mailboxIdentityMailboxSession, IdConverter.EwsIdToPersonId(this.itemId.Id), Persona.FullPersonaShape, null);
                    }
                    if (persona.Attributions.Length > 0)
                    {
                        sourceId = persona.Attributions[0].SourceId;
                        for (int i = 1; i < persona.Attributions.Length; i++)
                        {
                            StoreId storeId = IdConverter.EwsIdToMessageStoreObjectId(persona.Attributions[i].SourceId.Id);
                            using (Item item = Item.Bind(mailboxIdentityMailboxSession, storeId, new PropertyDefinition[]
                            {
                                ContactSchema.PersonId
                            }))
                            {
                                item.OpenAsReadWrite();
                                item[ContactSchema.PersonId] = PersonId.CreateNew();
                                item.Save(SaveMode.NoConflictResolution);
                            }
                        }
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Success");
                    }
                    else
                    {
                        ExTraceGlobals.GetGroupTracer.TraceError((long)this.hashCode, "ItemId is PersonaId but Persona has no linked contacts (attributions array is empty).");
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Skipped");
                    }
                }
                catch (LocalizedException arg)
                {
                    ExTraceGlobals.GetGroupTracer.TraceError <LocalizedException>((long)this.hashCode, "Failed to unlink PDLs: {0}", arg);
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Failed");
                }
            }
            IdAndSession idAndSession3 = base.IdConverter.ConvertItemIdToIdAndSessionReadOnly(sourceId);
            StoreSession storeSession;

            if (idAndSession != null)
            {
                storeSession = idAndSession.Session;
            }
            else
            {
                storeSession = ((idAndSession3.Session as MailboxSession) ?? base.CallContext.SessionCache.GetMailboxIdentityMailboxSession());
            }
            using (DistributionList distributionList = DistributionList.Bind(storeSession, idAndSession3.Id))
            {
                if (distributionList == null)
                {
                    this.WriteDebugTrace("No PDL was found");
                    return(getGroupResponse);
                }
                PersonId personId = (PersonId)distributionList[ContactSchema.PersonId];
                getGroupResponse.PersonaId = IdConverter.PersonaIdFromPersonId(storeSession.MailboxGuid, personId);
                if (!distributionList.GetValueOrDefault <bool>(ItemSchema.ConversationIndexTracking, false))
                {
                    try
                    {
                        distributionList.OpenAsReadWrite();
                        distributionList[ItemSchema.ConversationIndexTracking] = true;
                        distributionList.Save(SaveMode.NoConflictResolution);
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "SetConversationIndexTracking", "Success");
                    }
                    catch (LocalizedException arg2)
                    {
                        ExTraceGlobals.GetGroupTracer.TraceError <LocalizedException>((long)this.hashCode, "Failed to set ConversationIndexTracking on PDL: {0}", arg2);
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "SetConversationIndexTracking", "Failed");
                    }
                }
                if (!this.IsMembersInResultSet)
                {
                    return(getGroupResponse);
                }
                int count = distributionList.Count;
                getGroupResponse.MembersCount = count;
                this.WriteDebugTrace("Total PDL members count is " + count);
                if (this.paging.Offset < 0 || count <= this.paging.Offset)
                {
                    this.WriteDebugTrace(string.Format("Provided offset is out of range - members count is {0}, offset is {1}.", count, this.paging.Offset));
                    return(getGroupResponse);
                }
                distributionList.Sort(this.PDlMembersComparer);
                List <Persona>           list       = new List <Persona>();
                List <string>            list2      = new List <string>();
                Dictionary <string, int> dictionary = new Dictionary <string, int>();
                int num = Math.Min(count, this.paging.Offset + this.paging.MaxRows);
                for (int j = this.paging.Offset; j < num; j++)
                {
                    DistributionListMember distributionListMember = distributionList[j];
                    if (distributionListMember.Participant == null)
                    {
                        if (num < count)
                        {
                            num++;
                        }
                        getGroupResponse.MembersCount--;
                    }
                    else
                    {
                        bool    flag     = false;
                        Persona persona2 = GetGroupCommand.CreatePersonaFromDistributionListMember(mailboxIdentityMailboxSession, distributionListMember, out flag);
                        if (flag)
                        {
                            list2.Add(persona2.EmailAddress.EmailAddress);
                            dictionary.Add(persona2.EmailAddress.EmailAddress, list.Count);
                        }
                        list.Add(persona2);
                    }
                }
                if (list2.Count > 0)
                {
                    IRecipientSession     galscopedADRecipientSession = base.CallContext.ADRecipientSessionContext.GetGALScopedADRecipientSession(base.CallContext.EffectiveCaller.ClientSecurityContext);
                    Result <ADRawEntry>[] array = galscopedADRecipientSession.FindByLegacyExchangeDNs(list2.ToArray(), new PropertyDefinition[]
                    {
                        ADObjectSchema.Id,
                        ADRecipientSchema.DisplayName,
                        ADRecipientSchema.PrimarySmtpAddress,
                        ADRecipientSchema.RecipientType,
                        ADRecipientSchema.RecipientTypeDetails,
                        ADRecipientSchema.LegacyExchangeDN
                    });
                    foreach (Result <ADRawEntry> result in array)
                    {
                        if (result.Data != null)
                        {
                            Persona personaFromADObject = GetGroupCommand.GetPersonaFromADObject(result.Data);
                            string  key = result.Data[ADRecipientSchema.LegacyExchangeDN] as string;
                            int     num2;
                            if (dictionary.ContainsKey(key) && dictionary.TryGetValue(key, out num2) && num2 >= 0)
                            {
                                list[num2] = personaFromADObject;
                            }
                        }
                    }
                }
                list.Sort(this.PersonaComparer);
                Persona[] array3 = new Persona[list.Count];
                list.CopyTo(0, array3, 0, list.Count);
                getGroupResponse.Members = array3;
                this.WriteDebugTrace("PDL members count loaded in the response is " + getGroupResponse.Members.Length);
            }
            return(getGroupResponse);
        }