public static string LookupEmailAddressString(Participant participant, IExchangePrincipal exchangePrincipal, bool addBrackets)
        {
            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "Calling EmailAddressConverter.LookupEmailAddressString()");
            if (null == participant)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "participant is null.");
                throw new ArgumentNullException("participant null");
            }
            if (exchangePrincipal == null)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "value of exchange principal is null.");
                throw new ArgumentNullException("exchangePrincipal null");
            }
            if (string.IsNullOrEmpty(participant.EmailAddress))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "participant's emailAddress is null. Returning Display name instead.");
                return(EmailAddressConverter.AddBrackets(participant.DisplayName, "<{0}>", addBrackets));
            }
            if (participant.RoutingType == "EX")
            {
                Participant cachedParticipant = EmailAddressConverter.GetCachedParticipant(participant.EmailAddress);
                if (cachedParticipant != null)
                {
                    participant = cachedParticipant;
                }
            }
            if (participant.RoutingType == "SMTP")
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "participant's is already of Routing Type SMTP. return participant's email address.");
                return(EmailAddressConverter.AddBrackets(participant.EmailAddress, "<{0}>", addBrackets));
            }
            Participant participant2 = null;

            try
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "Fetching SmtpAddress property from MAPI");
                object obj = participant.TryGetProperty(ParticipantSchema.SmtpAddress);
                if (obj != null && obj is string)
                {
                    return(EmailAddressConverter.AddBrackets((string)obj, "<{0}>", addBrackets));
                }
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, "calling TryConveryTo to convert Participant to SMTP");
                participant2 = EmailAddressConverter.DoADLookup(exchangePrincipal, participant);
            }
            catch (StoragePermanentException)
            {
                AirSyncDiagnostics.TraceError(ExTraceGlobals.CommonTracer, null, "StorePermanentException during ADLookUp while converting Participant to SMTP");
            }
            if (participant2 != null)
            {
                AirSyncDiagnostics.TraceDebug <string, string>(ExTraceGlobals.CommonTracer, null, "Convert to SMTP successful. Returned EmailAddress {0} , Format {1}", participant2.EmailAddress, "<{0}>");
                if (participant.RoutingType == "EX")
                {
                    EmailAddressConverter.CacheParticipant(participant.EmailAddress, participant2);
                }
                return(EmailAddressConverter.AddBrackets(participant2.EmailAddress, "<{0}>", addBrackets));
            }
            AirSyncDiagnostics.TraceDebug <string, string, string>(ExTraceGlobals.CommonTracer, null, "Could not convert participant to SMTP routing type. Returned RoutingType:{0}, EmailAddress:{1} and Format: {2}", participant.RoutingType, participant.EmailAddress, "[{0}]");
            return(EmailAddressConverter.AddBrackets(participant.RoutingType + ":" + participant.EmailAddress, "[{0}]", addBrackets));
        }
        public static string GetRecipientString(RecipientCollection collection, RecipientItemType recipientItemType, IExchangePrincipal exchangePrincipal)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("Recipient collection null");
            }
            if (collection.Count == 0)
            {
                return(string.Empty);
            }
            int num = 0;

            Participant[] array  = new Participant[collection.Count];
            Participant[] array2 = new Participant[collection.Count];
            foreach (Recipient recipient in collection)
            {
                if (recipient == null)
                {
                    throw new ArgumentNullException("recipient is null");
                }
                array2[num] = recipient.Participant;
                if (recipient.Participant.RoutingType == "EX" && !string.IsNullOrEmpty(recipient.Participant.EmailAddress))
                {
                    Participant cachedParticipant = EmailAddressConverter.GetCachedParticipant(recipient.Participant.EmailAddress);
                    array[num++] = ((cachedParticipant == null) ? recipient.Participant : cachedParticipant);
                }
                else
                {
                    array[num++] = recipient.Participant;
                }
            }
            ParticipantUpdater.GetSMTPAddressesForParticipantsIfNecessary(array, collection);
            for (int i = 0; i < array.Length; i++)
            {
                Participant participant  = array2[i];
                Participant participant2 = array[i];
                if (participant.RoutingType != participant2.RoutingType)
                {
                    EmailAddressConverter.CacheParticipant(participant.EmailAddress, participant2);
                }
            }
            StringBuilder stringBuilder = new StringBuilder(collection.Count * 100);
            int           num2          = 0;

            foreach (Recipient recipient2 in collection)
            {
                Participant participant3 = array[num2++];
                if (recipientItemType == RecipientItemType.Unknown || recipient2.RecipientItemType == recipientItemType)
                {
                    if (participant3.DisplayName.StartsWith("\"") && participant3.DisplayName.EndsWith("\""))
                    {
                        stringBuilder.Append(participant3.DisplayName);
                        stringBuilder.Append(" <");
                    }
                    else
                    {
                        stringBuilder.Append('"');
                        stringBuilder.Append(participant3.DisplayName);
                        stringBuilder.Append("\" ");
                    }
                    stringBuilder.Append(EmailAddressConverter.LookupEmailAddressString(participant3, exchangePrincipal, true));
                    stringBuilder.Append(", ");
                }
                if (stringBuilder.Length > 32000)
                {
                    break;
                }
            }
            if (stringBuilder.Length > 1)
            {
                stringBuilder.Length -= 2;
            }
            AirSyncDiagnostics.TraceInfo <StringBuilder>(ExTraceGlobals.CommonTracer, null, "GetRecipientString = {0}", stringBuilder);
            return(stringBuilder.ToString());
        }