コード例 #1
0
        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));
        }
コード例 #2
0
        public static Participant CreateParticipant(string textString)
        {
            if (string.IsNullOrEmpty(textString))
            {
                throw new ArgumentNullException("Participant string null");
            }
            AirSyncDiagnostics.TraceInfo <string>(ExTraceGlobals.CommonTracer, null, "CreateParticipant = {0}", textString);
            Participant participant = Participant.Parse(textString);

            EmailAddressConverter.ValidateParticipant(participant);
            return(participant);
        }
コード例 #3
0
 public static void SetRecipientCollection(RecipientCollection collection, RecipientItemType recipientItemType, string textString)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("Recipient collection null");
     }
     if (textString == null)
     {
         throw new ArgumentNullException("Recipient string null");
     }
     string[] array = ParseRecipientHelper.ParseRecipientChunk(textString);
     EmailAddressConverter.ClearRecipients(collection, recipientItemType);
     for (int i = 0; i < array.Length; i++)
     {
         if (!string.IsNullOrEmpty(array[i]))
         {
             Participant participant = Participant.Parse(array[i]);
             EmailAddressConverter.ValidateParticipant(participant);
             collection.Add(participant, recipientItemType);
         }
     }
 }
コード例 #4
0
        public static string GetParticipantString(Participant participant, IExchangePrincipal exchangePrincipal)
        {
            if (null == participant)
            {
                throw new ArgumentNullException("participant null");
            }
            StringBuilder stringBuilder = new StringBuilder(100);

            if (participant.DisplayName.StartsWith("\"") && participant.DisplayName.EndsWith("\""))
            {
                stringBuilder.Append(participant.DisplayName);
                stringBuilder.Append(" ");
            }
            else
            {
                stringBuilder.Append('"');
                stringBuilder.Append(participant.DisplayName);
                stringBuilder.Append("\" ");
            }
            stringBuilder.Append(EmailAddressConverter.LookupEmailAddressString(participant, exchangePrincipal, true));
            AirSyncDiagnostics.TraceInfo <StringBuilder>(ExTraceGlobals.CommonTracer, null, "GetParticipantString = {0}", stringBuilder);
            return(stringBuilder.ToString());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
 public static string LookupEmailAddressString(Participant participant, IExchangePrincipal exchangePrincipal)
 {
     return(EmailAddressConverter.LookupEmailAddressString(participant, exchangePrincipal, false));
 }