private ExpansionControl OnRecipient(ADRawEntry recipient, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType)
            {
                bool flag = CertificateManager.IsADDistributionList((RecipientType)recipient[ADRecipientSchema.RecipientType]);

                if (flag && (bool)recipient[ADGroupSchema.HiddenGroupMembershipEnabled])
                {
                    this.certificates.Clear();
                    this.size = 0;
                    return(ExpansionControl.Terminate);
                }
                if (!flag && !this.previouslySeen.Contains(recipient.Identity.ToString()))
                {
                    this.size++;
                    this.previouslySeen.Add(recipient.Identity.ToString());
                    X509Certificate2 adrecipientCert = this.manager.GetADRecipientCert(recipient);
                    if (adrecipientCert != null)
                    {
                        this.certificates.Add(adrecipientCert);
                    }
                }
                if (this.size > GlobalSettings.MaxSMimeADDistributionListExpansion)
                {
                    this.size = 0;
                    this.certificates.Clear();
                    return(ExpansionControl.Terminate);
                }
                return(ExpansionControl.Continue);
            }
        private void GetDirectoryCerts(List <RecipientAddress> addressList, AmbiguousRecipientToResolve recipient)
        {
            List <string> list = new List <string>(addressList.Count);

            foreach (RecipientAddress recipientAddress in addressList)
            {
                list.Add(recipientAddress.RoutingAddress);
            }
            Result <ADRawEntry>[] array = this.RecipientSession.FindByLegacyExchangeDNs(list.ToArray(), CertificateManager.adrecipientProperties);
            if (Command.CurrentCommand != null)
            {
                Command.CurrentCommand.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, this.recipientSession.LastUsedDc);
            }
            for (int i = 0; i < array.Length; i++)
            {
                Result <ADRawEntry> result = array[i];
                if (result.Data != null)
                {
                    ResolvedRecipient resolvedRecipient = recipient.ResolvedTo[addressList[i].Index];
                    if (CertificateManager.IsADDistributionList((RecipientType)result.Data[ADRecipientSchema.RecipientType]))
                    {
                        CertificateManager.ADDistributionListExpansion addistributionListExpansion = new CertificateManager.ADDistributionListExpansion(this, new ADRecipientExpansion(CertificateManager.adrecipientProperties, this.organizationId));
                        addistributionListExpansion.Expand(result.Data);
                        resolvedRecipient.CertificateRecipientCount += addistributionListExpansion.Size;
                        resolvedRecipient.CertificateCount          += addistributionListExpansion.Certificates.Count;
                        if (!resolvedRecipient.GlobalCertLimitWasHit && resolvedRecipient.Certificates.Count + addistributionListExpansion.Certificates.Count <= this.certificateSlotsLeft)
                        {
                            resolvedRecipient.Certificates.AddRange(addistributionListExpansion.Certificates.ToArray());
                            this.certificateSlotsLeft -= addistributionListExpansion.Certificates.Count;
                        }
                        else
                        {
                            resolvedRecipient.GlobalCertLimitWasHit = true;
                            this.certificateSlotsLeft += resolvedRecipient.Certificates.Count;
                            resolvedRecipient.Certificates.Clear();
                        }
                    }
                    else
                    {
                        resolvedRecipient.CertificateRecipientCount++;
                        X509Certificate2 adrecipientCert = this.GetADRecipientCert(result.Data);
                        if (adrecipientCert != null)
                        {
                            resolvedRecipient.CertificateCount++;
                            if (!resolvedRecipient.GlobalCertLimitWasHit && this.certificateSlotsLeft <= 0)
                            {
                                resolvedRecipient.GlobalCertLimitWasHit = true;
                                this.certificateSlotsLeft += resolvedRecipient.Certificates.Count;
                                resolvedRecipient.Certificates.Clear();
                            }
                            else if (!resolvedRecipient.GlobalCertLimitWasHit)
                            {
                                resolvedRecipient.Certificates.Add(adrecipientCert);
                                this.certificateSlotsLeft--;
                            }
                        }
                    }
                }
            }
        }