Ejemplo n.º 1
0
        public int GetMaxAllowedMailboxes(IRecipientSession recipientSession, SearchType searchType)
        {
            int result = (int)SearchUtils.GetDiscoveryMaxMailboxes(recipientSession);

            if (searchType == SearchType.Preview)
            {
                result = (int)SearchUtils.GetDiscoveryMaxMailboxesForPreviewSearch(recipientSession);
            }
            if (searchType == SearchType.Statistics)
            {
                result = (int)SearchUtils.GetDiscoveryMaxMailboxesForStatsSearch(recipientSession);
            }
            return(result);
        }
Ejemplo n.º 2
0
        internal static MultiValuedProperty <string> ConvertSourceMailboxesCollection(IEnumerable <RecipientIdParameter> recipientIds, bool inplaceHoldEnabled, Func <RecipientIdParameter, ADRecipient> recipientGetter, IRecipientSession recipientSession, Task.TaskErrorLoggingDelegate writeErrorDelegate, Action <LocalizedString> writeWarningDelegate, Func <LocalizedString, bool> shouldContinueDelegate)
        {
            MultiValuedProperty <string> results = null;

            if (recipientIds != null)
            {
                RecipientType[] source = new RecipientType[]
                {
                    RecipientType.UserMailbox,
                    RecipientType.Group,
                    RecipientType.MailUniversalDistributionGroup,
                    RecipientType.MailUniversalSecurityGroup,
                    RecipientType.MailNonUniversalGroup,
                    RecipientType.DynamicDistributionGroup
                };
                bool flag = false;
                foreach (RecipientIdParameter arg in recipientIds)
                {
                    if (results == null)
                    {
                        results = new MultiValuedProperty <string>();
                    }
                    ADRecipient       adrecipient     = recipientGetter(arg);
                    string            text            = null;
                    ADSessionSettings sessionSettings = adrecipient.OrganizationId.ToADSessionSettings();
                    if (Utils.IsPublicFolderMailbox(adrecipient))
                    {
                        writeErrorDelegate(new MailboxSearchTaskException(Strings.ErrorInvalidRecipientTypeDetails(adrecipient.ToString())), ErrorCategory.InvalidArgument, null);
                    }
                    else if (Utils.IsValidMailboxType(adrecipient))
                    {
                        if (adrecipient.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012) && !RemoteMailbox.IsRemoteMailbox(adrecipient.RecipientTypeDetails) && ExchangePrincipal.FromADUser(sessionSettings, (ADUser)adrecipient, RemotingOptions.AllowCrossSite).MailboxInfo.Location.ServerVersion < Server.E15MinVersion)
                        {
                            writeErrorDelegate(new MailboxSearchTaskException(Strings.SourceMailboxMustBeE15OrLater(adrecipient.DisplayName)), ErrorCategory.InvalidArgument, null);
                        }
                        text = adrecipient.LegacyExchangeDN;
                    }
                    else if (source.Contains(adrecipient.RecipientType))
                    {
                        if (inplaceHoldEnabled)
                        {
                            if (!flag)
                            {
                                if (shouldContinueDelegate(Strings.ShouldContinueToExpandGroupsForHold))
                                {
                                    flag = true;
                                }
                                else
                                {
                                    writeErrorDelegate(new MailboxSearchTaskException(Strings.GroupsIsNotAllowedForHold(adrecipient.DisplayName)), ErrorCategory.InvalidArgument, null);
                                }
                            }
                            bool invalidTypeSkipped                   = false;
                            bool oldVersionMailboxSkipped             = false;
                            ADRecipientExpansion adrecipientExpansion = new ADRecipientExpansion(new PropertyDefinition[]
                            {
                                ADRecipientSchema.LegacyExchangeDN,
                                ADRecipientSchema.RecipientTypeDetailsValue,
                                ADObjectSchema.ExchangeVersion
                            }, adrecipient.OrganizationId);
                            adrecipientExpansion.Expand(adrecipient, delegate(ADRawEntry expandedRecipient, ExpansionType expansionType, ADRawEntry parent, ExpansionType parentType)
                            {
                                if (expansionType == ExpansionType.GroupMembership)
                                {
                                    return(ExpansionControl.Continue);
                                }
                                if (Utils.IsValidMailboxType(expandedRecipient))
                                {
                                    ExchangeObjectVersion exchangeObjectVersion = (ExchangeObjectVersion)expandedRecipient[ADObjectSchema.ExchangeVersion];
                                    string text2 = (string)expandedRecipient[ADRecipientSchema.LegacyExchangeDN];
                                    if (!oldVersionMailboxSkipped && exchangeObjectVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012) && !RemoteMailbox.IsRemoteMailbox((RecipientTypeDetails)expandedRecipient[ADRecipientSchema.RecipientTypeDetails]) && ExchangePrincipal.FromLegacyDN(sessionSettings, text2).MailboxInfo.Location.ServerVersion < Server.E15MinVersion)
                                    {
                                        oldVersionMailboxSkipped = true;
                                        writeWarningDelegate(Strings.OldVersionMailboxSkipped);
                                    }
                                    if (!results.Contains(text2))
                                    {
                                        results.Add(text2);
                                    }
                                }
                                else if (!invalidTypeSkipped)
                                {
                                    invalidTypeSkipped = true;
                                    writeWarningDelegate(Strings.SkippingInvalidTypeInGroupExpansion);
                                }
                                return(ExpansionControl.Skip);
                            }, delegate(ExpansionFailure failure, ADRawEntry expandedRecipient, ExpansionType expansionType, ADRawEntry parent, ExpansionType parentType)
                            {
                                TaskLogger.Trace("Skipping invalid AD entry {0} because of failure: {1}", new object[]
                                {
                                    expandedRecipient,
                                    failure
                                });
                                return(ExpansionControl.Skip);
                            });
                        }
                        else
                        {
                            text = adrecipient.LegacyExchangeDN;
                        }
                    }
                    else
                    {
                        writeErrorDelegate(new MailboxSearchTaskException(Strings.ErrorInvalidRecipientType(adrecipient.ToString(), adrecipient.RecipientType.ToString())), ErrorCategory.InvalidArgument, null);
                    }
                    if (text != null && !results.Contains(text))
                    {
                        results.Add(text);
                    }
                    if (results.Count > Utils.MaxNumberOfMailboxesInSingleHold)
                    {
                        writeErrorDelegate(new MailboxSearchTaskException(Strings.ErrorTooManyMailboxesInSingleHold(Utils.MaxNumberOfMailboxesInSingleHold)), ErrorCategory.InvalidArgument, null);
                    }
                }
                if (results != null)
                {
                    uint discoveryMaxMailboxes = SearchUtils.GetDiscoveryMaxMailboxes(recipientSession);
                    if ((long)results.Count > (long)((ulong)discoveryMaxMailboxes) && !shouldContinueDelegate(Strings.ShouldContinueMoreMailboxesThanMaxSearch(results.Count, discoveryMaxMailboxes)))
                    {
                        writeErrorDelegate(new MailboxSearchTaskException(Strings.ErrorTaskCancelledBecauseMoreMailboxesThanSearchSupported), ErrorCategory.InvalidArgument, null);
                    }
                }
            }
            return(results);
        }