internal static MbxPropertyDefinition ProxyAddressFromStringPropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false)
        {
            GetterDelegate getterDelegate = delegate(IPropertyBag propertyBag)
            {
                if (propertyBag[rawPropertyDefinition] != null)
                {
                    return(ProxyAddress.Parse((string)propertyBag[rawPropertyDefinition]));
                }
                return(null);
            };
            SetterDelegate setterDelegate = delegate(object value, IPropertyBag propertyBag)
            {
                propertyBag[rawPropertyDefinition] = ((ProxyAddress)value).ToString();
            };
            GetterDelegate getterDelegate2 = delegate(IPropertyBag propertyBag)
            {
                MultiValuedProperty <string>       multiValuedProperty  = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition];
                MultiValuedProperty <ProxyAddress> multiValuedProperty2 = new MultiValuedProperty <ProxyAddress>();
                foreach (string proxyAddressString in multiValuedProperty)
                {
                    multiValuedProperty2.Add(ProxyAddress.Parse(proxyAddressString));
                }
                return(multiValuedProperty2);
            };
            SetterDelegate setterDelegate2 = delegate(object value, IPropertyBag propertyBag)
            {
                MultiValuedProperty <ProxyAddress> multiValuedProperty  = (MultiValuedProperty <ProxyAddress>)value;
                MultiValuedProperty <string>       multiValuedProperty2 = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition];
                for (int i = multiValuedProperty2.Count - 1; i >= 0; i--)
                {
                    if (!string.IsNullOrEmpty(multiValuedProperty2[i]))
                    {
                        multiValuedProperty2.RemoveAt(i);
                    }
                }
                foreach (ProxyAddress proxyAddress in multiValuedProperty)
                {
                    multiValuedProperty2.Add(proxyAddress.ToString());
                }
            };

            return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(ProxyAddress), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : null, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[]
            {
                rawPropertyDefinition
            }, multivalued ? getterDelegate2 : getterDelegate, multivalued ? setterDelegate2 : setterDelegate));
        }
Ejemplo n.º 2
0
        private static ProxyAddress Deencapsulate(string smtpAddress)
        {
            if (!SmtpProxyAddress.HasEncapsulationPrefix(smtpAddress))
            {
                return(null);
            }
            int num = smtpAddress.IndexOf('-');

            if (-1 == num)
            {
                return(null);
            }
            string text = SmtpProxyAddress.DeencapsulateString(smtpAddress, "IMCEA".Length, num - "IMCEA".Length);

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            num++;
            int num2 = smtpAddress.LastIndexOf('@');

            if (num2 == -1 || num2 == smtpAddress.Length - 1)
            {
                return(null);
            }
            string text2 = SmtpProxyAddress.DeencapsulateString(smtpAddress, num, num2 - num);

            if (string.IsNullOrEmpty(text2))
            {
                return(null);
            }
            ProxyAddress result;

            try
            {
                result = ProxyAddress.Parse(text, text2);
            }
            catch (ArgumentOutOfRangeException)
            {
                result = null;
            }
            return(result);
        }