private static string[] GetSmtpAddressCache(ADRawEntry person)
		{
			List<string> list = new List<string>(1);
			object obj;
			if (person.TryGetValueWithoutDefault(ADRecipientSchema.EmailAddresses, out obj))
			{
				ProxyAddressCollection proxyAddressCollection = obj as ProxyAddressCollection;
				if (proxyAddressCollection != null)
				{
					foreach (ProxyAddress proxyAddress in proxyAddressCollection)
					{
						SmtpProxyAddress smtpProxyAddress = proxyAddress as SmtpProxyAddress;
						if (smtpProxyAddress != null)
						{
							string text = smtpProxyAddress.ToString();
							if (!string.IsNullOrEmpty(text))
							{
								list.Add(text);
							}
						}
					}
				}
			}
			return list.ToArray();
		}
Exemplo n.º 2
0
        private ExchangePrincipal GetExchangePrincipalForRecipient(MailRecipient recipient, DeliverableItem item, ICollection <CultureInfo> recipientLanguages, bool useCompletePrincipal)
        {
            ADSessionSettings adsessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(recipient.MailItemScopeOrganizationId);
            Guid databaseGuid = this.context.MbxTransportMailItem.DatabaseGuid;
            ExchangePrincipal exchangePrincipal;

            if (this.IsPublicFolderRecipient(item))
            {
                ADObjectId    value         = recipient.ExtendedProperties.GetValue <ADObjectId>("Microsoft.Exchange.Transport.DirectoryData.ContentMailbox", null);
                StoreObjectId storeObjectId = null;
                if (value == null || !StoreObjectId.TryParseFromHexEntryId(recipient.ExtendedProperties.GetValue <string>("Microsoft.Exchange.Transport.DirectoryData.EntryId", null), out storeObjectId))
                {
                    throw new SmtpResponseException(AckReason.UnableToDetermineTargetPublicFolderMailbox, MessageAction.Reroute);
                }
                this.deliverToFolder = storeObjectId;
                try
                {
                    exchangePrincipal = ExchangePrincipal.FromDirectoryObjectId(DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, adsessionSettings, 830, "GetExchangePrincipalForRecipient", "f:\\15.00.1497\\sources\\dev\\MailboxTransport\\src\\MailboxTransportDelivery\\StoreDriver\\DeliveryItem.cs"), value, RemotingOptions.LocalConnectionsOnly);
                    goto IL_14C;
                }
                catch (Microsoft.Exchange.Data.Storage.ObjectNotFoundException)
                {
                    throw new SmtpResponseException(AckReason.PublicFolderMailboxNotFound, MessageAction.Reroute);
                }
            }
            MailboxItem mailboxItem = item as MailboxItem;

            if (mailboxItem == null)
            {
                throw new InvalidOperationException("Delivery to PFDBs is not supported in E15");
            }
            if (!useCompletePrincipal)
            {
                string legacyExchangeDN;
                if (!recipient.ExtendedProperties.TryGetValue <string>("Microsoft.Exchange.Transport.MailRecipient.DisplayName", out legacyExchangeDN))
                {
                    legacyExchangeDN = mailboxItem.LegacyExchangeDN;
                }
                exchangePrincipal = ExchangePrincipal.FromMailboxData(legacyExchangeDN, adsessionSettings, databaseGuid, mailboxItem.MailboxGuid, mailboxItem.LegacyExchangeDN, recipient.Email.ToString(), recipientLanguages ?? new MultiValuedProperty <CultureInfo>(), true, mailboxItem.RecipientType, mailboxItem.RecipientTypeDetails.GetValueOrDefault());
            }
            else
            {
                ProxyAddress proxyAddress = new SmtpProxyAddress((string)recipient.Email, true);
                exchangePrincipal = ExchangePrincipal.FromProxyAddress(adsessionSettings, proxyAddress.ToString());
            }
IL_14C:
            if (exchangePrincipal.MailboxInfo.IsRemote)
            {
                throw new SmtpResponseException(AckReason.RecipientMailboxIsRemote, MessageAction.Reroute);
            }
            if (exchangePrincipal.MailboxInfo.Location == MailboxDatabaseLocation.Unknown)
            {
                throw new SmtpResponseException(AckReason.RecipientMailboxLocationInfoNotAvailable, MessageAction.Reroute);
            }
            return(exchangePrincipal);
        }