Ejemplo n.º 1
0
 internal SharingProvider GetTargetSharingProvider(ADRecipient mailboxOwner)
 {
     Util.ThrowOnNullArgument(mailboxOwner, "mailboxOwner");
     if (this.AvailableSharingProviders.Keys.Count == 1)
     {
         using (Dictionary <SharingProvider, CheckRecipientsResults> .KeyCollection.Enumerator enumerator = this.AvailableSharingProviders.Keys.GetEnumerator())
         {
             if (enumerator.MoveNext())
             {
                 SharingProvider sharingProvider = enumerator.Current;
                 ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient, SharingProvider>((long)this.GetHashCode(), "{0}: Found target provider {1} for current user.", mailboxOwner, sharingProvider);
                 return(sharingProvider);
             }
         }
     }
     foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.AvailableSharingProviders)
     {
         SharingProvider        key   = keyValuePair.Key;
         CheckRecipientsResults value = keyValuePair.Value;
         if (value != null && mailboxOwner.IsAnyAddressMatched(ValidRecipient.ConvertToStringArray(value.ValidRecipients)))
         {
             ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient, SharingProvider>((long)this.GetHashCode(), "{0}: Found target provider {1} for current user.", mailboxOwner, key);
             return(key);
         }
     }
     ExTraceGlobals.SharingTracer.TraceError <ADRecipient>((long)this.GetHashCode(), "{0}: No available provider is found for this user.", mailboxOwner);
     return(null);
 }
Ejemplo n.º 2
0
        private void PostResponded(SharingResponseType responseType)
        {
            if (!this.SharingMessageType.IsRequest)
            {
                throw new InvalidOperationException("Only can response to a request message.");
            }
            base.OpenAsReadWrite();
            this.SharingResponseType = responseType;
            this.SharingResponseTime = new ExDateTime?(ExDateTime.Now);
            ConflictResolutionResult conflictResolutionResult = base.Save(SaveMode.ResolveConflicts);

            if (conflictResolutionResult.SaveStatus == SaveResult.IrresolvableConflict)
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Conflict occurred when saving response-status into request message {1}", this.MailboxSession.MailboxOwner, base.Id);
            }
            if (responseType == SharingResponseType.Denied)
            {
                try
                {
                    SharingProvider targetSharingProvider = this.GetTargetSharingProvider();
                    targetSharingProvider.PerformRevocation(this.MailboxSession, this.SharingContext);
                }
                catch (StoragePermanentException arg)
                {
                    ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, StoragePermanentException>((long)this.GetHashCode(), "{0}: Error occurred when revoking sharing from denied requester. Exception = {1}", this.MailboxSession.MailboxOwner, arg);
                }
            }
        }
Ejemplo n.º 3
0
        private SharingProvider GetTargetSharingProvider()
        {
            SharingProvider sharingProvider = this.TryGetTargetSharingProvider();

            if (sharingProvider == null)
            {
                throw new InvalidSharingTargetRecipientException();
            }
            return(sharingProvider);
        }
Ejemplo n.º 4
0
        private bool IsProviderEffective(SharingProvider provider)
        {
            if (!this.AvailableSharingProviders.ContainsKey(provider))
            {
                return(false);
            }
            CheckRecipientsResults checkRecipientsResults = this.AvailableSharingProviders[provider];

            return(checkRecipientsResults != null && checkRecipientsResults.ValidRecipients != null && checkRecipientsResults.ValidRecipients.Length != 0);
        }
Ejemplo n.º 5
0
        internal SharingContext(Folder folderToShare, SharingProvider sharingProvider) : this()
        {
            Util.ThrowOnNullArgument(folderToShare, "folderToShare");
            MailboxSession     mailboxSession = folderToShare.Session as MailboxSession;
            IExchangePrincipal mailboxOwner   = mailboxSession.MailboxOwner;

            if (sharingProvider == null)
            {
                SharingProvider[] compatibleProviders = SharingProvider.GetCompatibleProviders(folderToShare);
                if (compatibleProviders.Length == 0)
                {
                    ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Cannot share folder {1}: no compatible provider was found.", mailboxOwner, folderToShare.Id);
                    throw new CannotShareFolderException(ServerStrings.NoProviderSupportShareFolder);
                }
                for (int i = 0; i < compatibleProviders.Length; i++)
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, VersionedId>((long)this.GetHashCode(), "{0}: Find compatible provider {1} for folder {2}.", mailboxOwner, compatibleProviders[i], folderToShare.Id);
                    this.AvailableSharingProviders.Add(compatibleProviders[i], null);
                }
            }
            else if (!sharingProvider.IsCompatible(folderToShare))
            {
                ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, SharingProvider>((long)this.GetHashCode(), "{0}: Cannot share folder {1} with sharing provider: {2}.", mailboxOwner, folderToShare.Id, sharingProvider);
                if (sharingProvider == SharingProvider.SharingProviderPublish)
                {
                    throw new FolderNotPublishedException();
                }
                throw new CannotShareFolderException(ServerStrings.NoProviderSupportShareFolder);
            }
            else
            {
                this.AvailableSharingProviders.Add(sharingProvider, null);
                if (sharingProvider == SharingProvider.SharingProviderPublish)
                {
                    this.PopulateUrls(folderToShare);
                }
            }
            this.InitiatorName        = mailboxOwner.MailboxInfo.DisplayName;
            this.InitiatorSmtpAddress = mailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            this.InitiatorEntryId     = AddressBookEntryId.MakeAddressBookEntryID(mailboxOwner);
            this.FolderClass          = folderToShare.ClassName;
            this.FolderId             = folderToShare.StoreObjectId;
            this.IsPrimary            = (mailboxSession.IsDefaultFolderType(this.FolderId) != DefaultFolderType.None);
            this.FolderName           = (this.IsPrimary ? this.DataType.DisplayName.ToString(mailboxSession.InternalPreferedCulture) : folderToShare.DisplayName);
            this.MailboxId            = StoreEntryId.ToProviderStoreEntryId(mailboxOwner);
            this.SharingMessageType   = SharingMessageType.Invitation;
            this.SharingPermissions   = SharingContextPermissions.Reviewer;
            if (StringComparer.OrdinalIgnoreCase.Equals(folderToShare.ClassName, "IPF.Appointment"))
            {
                this.SharingDetail = (this.IsPrimary ? SharingContextDetailLevel.AvailabilityOnly : SharingContextDetailLevel.FullDetails);
            }
            this.SetDefaultCapabilities();
            this.UserLegacyDN = mailboxOwner.LegacyDn;
        }
Ejemplo n.º 6
0
        public SubscribeResults Subscribe()
        {
            this.CheckDisposed("Subscribe");
            if (base.IsDraft)
            {
                throw new InvalidOperationException("Cannot subscribe draft message.");
            }
            SharingProvider  targetSharingProvider = this.GetTargetSharingProvider();
            SubscribeResults result = targetSharingProvider.PerformSubscribe(this.MailboxSession, this.SharingContext);

            this.SaveSubscribeTime();
            return(result);
        }
Ejemplo n.º 7
0
        internal void SaveIntoMessageXProperties(MessageItem messageItem, bool isClear)
        {
            SharingProvider sharingProviderPublish = SharingProvider.SharingProviderPublish;

            messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderGuid, isClear ? null : HexConverter.ByteArrayToHexString(sharingProviderPublish.Guid.ToByteArray()));
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderName, isClear ? null : sharingProviderPublish.Name);
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderUrl, isClear ? null : sharingProviderPublish.Url);
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingCapabilities, isClear ? null : string.Format("{0:X}", 521));
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingFlavor, isClear ? null : string.Format("{0:X}", 784));
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemoteType, isClear ? null : this.context.DataType.PublishName);
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingLocalType, isClear ? null : this.context.FolderClass);
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemoteName, isClear ? null : this.context.FolderName);
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingBrowseUrl, isClear ? null : this.context.BrowseUrl.ToString());
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemotePath, isClear ? null : this.context.ICalUrl.ToString());
            messageItem.SetOrDeleteProperty(InternalSchema.XSharingInstanceGuid, isClear ? null : HexConverter.ByteArrayToHexString(Guid.NewGuid().ToByteArray()));
        }
Ejemplo n.º 8
0
        private SharingMessageAction CreateRequestAction()
        {
            List <SharingMessageProvider> list = new List <SharingMessageProvider>(this.context.AvailableSharingProviders.Count);

            foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.context.AvailableSharingProviders)
            {
                SharingProvider        key   = keyValuePair.Key;
                CheckRecipientsResults value = keyValuePair.Value;
                if (key != SharingProvider.SharingProviderPublish && value != null && value.ValidRecipients != null && value.ValidRecipients.Length > 0)
                {
                    SharingMessageProvider sharingMessageProvider = key.CreateSharingMessageProvider();
                    sharingMessageProvider.TargetRecipients = value.TargetRecipients;
                    list.Add(sharingMessageProvider);
                }
            }
            return(new SharingMessageAction
            {
                Providers = list.ToArray()
            });
        }
Ejemplo n.º 9
0
        private SharingMessageAction CreateInvitationAction()
        {
            List <SharingMessageProvider> list = new List <SharingMessageProvider>(this.context.AvailableSharingProviders.Count);

            foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.context.AvailableSharingProviders)
            {
                SharingProvider        key   = keyValuePair.Key;
                CheckRecipientsResults value = keyValuePair.Value;
                if (value != null && value.ValidRecipients != null && value.ValidRecipients.Length > 0)
                {
                    SharingMessageProvider sharingMessageProvider = key.CreateSharingMessageProvider(this.context);
                    sharingMessageProvider.TargetRecipients = value.TargetRecipients;
                    list.Add(sharingMessageProvider);
                }
            }
            return(new SharingMessageAction
            {
                Title = (this.context.IsPrimary ? null : this.context.FolderName),
                Providers = list.ToArray()
            });
        }
Ejemplo n.º 10
0
        internal static SharingProvider[] GetCompatibleProviders(SharingProvider provider, Folder folderToShare)
        {
            List <SharingProvider> list = new List <SharingProvider>(SharingProvider.AllSharingProviders.Length);

            if (provider != null)
            {
                list.Add(provider);
                if (provider == SharingProvider.SharingProviderInternal)
                {
                    if (SharingProvider.SharingProviderExternal.IsCompatible(folderToShare))
                    {
                        list.Add(SharingProvider.SharingProviderExternal);
                    }
                    if (SharingProvider.SharingProviderPublish.IsCompatible(folderToShare))
                    {
                        list.Add(SharingProvider.SharingProviderPublish);
                    }
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 11
0
        internal void SaveIntoMessageProperties(MessageItem messageItem, bool isClear)
        {
            SharingProvider primarySharingProvider = this.context.PrimarySharingProvider;

            messageItem.SetOrDeleteProperty(InternalSchema.ProviderGuidBinary, isClear ? null : primarySharingProvider.Guid.ToByteArray());
            messageItem.SetOrDeleteProperty(InternalSchema.SharingProviderName, isClear ? null : primarySharingProvider.Name);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingProviderUrl, isClear ? null : primarySharingProvider.Url);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingCapabilities, isClear ? null : this.context.SharingCapabilities);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingFlavor, isClear ? null : this.context.SharingFlavor);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteType, isClear ? null : this.context.FolderClass);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalType, isClear ? null : this.context.FolderClass);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteName, isClear ? null : this.context.FolderName);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalName, isClear ? null : this.context.FolderName);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteUid, isClear ? null : this.context.FolderId.ToHexEntryId());
            messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalUid, isClear ? null : this.context.FolderId.ToHexEntryId());
            messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteStoreUid, isClear ? null : HexConverter.ByteArrayToHexString(this.context.MailboxId));
            messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalStoreUid, isClear ? null : HexConverter.ByteArrayToHexString(this.context.MailboxId));
            messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorName, isClear ? null : this.context.InitiatorName);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorSmtp, isClear ? null : this.context.InitiatorSmtpAddress);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorEntryId, isClear ? null : this.context.InitiatorEntryId);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingPermissions, isClear ? null : this.context.SharingPermissions);
            messageItem.SetOrDeleteProperty(InternalSchema.SharingDetail, isClear ? null : this.context.SharingDetail);
        }
Ejemplo n.º 12
0
 private void ReadActionFromMetadataXml(SharingMessageAction action)
 {
     if (action != null)
     {
         this.context.IsPrimary = string.IsNullOrEmpty(action.Title);
         if (!this.context.IsPrimary)
         {
             this.context.FolderName = action.Title;
         }
         foreach (SharingMessageProvider sharingMessageProvider in action.Providers)
         {
             string[] recipients = sharingMessageProvider.TargetRecipients.Split(new char[]
             {
                 ';'
             });
             SharingProvider sharingProvider = SharingProvider.FromExternalName(sharingMessageProvider.Type);
             if (sharingProvider != null)
             {
                 sharingProvider.ParseSharingMessageProvider(this.context, sharingMessageProvider);
                 this.context.AvailableSharingProviders.Add(sharingProvider, new CheckRecipientsResults(ValidRecipient.ConvertFromStringArray(recipients)));
             }
         }
     }
 }
Ejemplo n.º 13
0
        private static SharingMessageItem InternalCreate(MailboxSession mailboxSession, StoreId destFolderId, StoreId folderIdToShare, SharingProvider provider)
        {
            Util.ThrowOnNullArgument(mailboxSession, "mailboxSession");
            Util.ThrowOnNullArgument(destFolderId, "destFolderId");
            Util.ThrowOnNullArgument(folderIdToShare, "folderIdToShare");
            SharingMessageItem result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                SharingMessageItem sharingMessageItem = ItemBuilder.CreateNewItem <SharingMessageItem>(mailboxSession, destFolderId, ItemCreateInfo.SharingMessageItemInfo, CreateMessageType.Normal);
                disposeGuard.Add <SharingMessageItem>(sharingMessageItem);
                sharingMessageItem[InternalSchema.ItemClass] = "IPM.Sharing";
                using (Folder folder = Folder.Bind(mailboxSession, folderIdToShare))
                {
                    sharingMessageItem.SharingContext = new SharingContext(folder, provider);
                }
                disposeGuard.Success();
                result = sharingMessageItem;
            }
            return(result);
        }
Ejemplo n.º 14
0
        public static SharingMessageItem CreateWithSpecficProvider(MailboxSession session, StoreId destFolderId, StoreId folderIdToShare, SharingProvider provider, bool force)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            SharingMessageItem sharingMessageItem = SharingMessageItem.InternalCreate(session, destFolderId, folderIdToShare, provider);

            if (force)
            {
                sharingMessageItem.ForceSharingProvider = provider;
            }
            return(sharingMessageItem);
        }
Ejemplo n.º 15
0
        private void PerformInvitation()
        {
            Dictionary <SharingProvider, ValidRecipient[]> dictionary = new Dictionary <SharingProvider, ValidRecipient[]>();
            List <ValidRecipient> list = new List <ValidRecipient>();
            SharingProvider       fallbackSharingProvider = this.SharingContext.FallbackSharingProvider;

            using (FolderPermissionContext current = FolderPermissionContext.GetCurrent(this.MailboxSession, this.SharingContext))
            {
                bool flag = false;
                try
                {
                    foreach (KeyValuePair <SharingProvider, CheckRecipientsResults> keyValuePair in this.SharingContext.AvailableSharingProviders)
                    {
                        SharingProvider        key   = keyValuePair.Key;
                        CheckRecipientsResults value = keyValuePair.Value;
                        if (this.FallbackEnabled && key == fallbackSharingProvider)
                        {
                            if (value != null)
                            {
                                list.AddRange(value.ValidRecipients);
                            }
                        }
                        else if (value != null)
                        {
                            PerformInvitationResults performInvitationResults = key.PerformInvitation(this.MailboxSession, this.SharingContext, value.ValidRecipients, this.FrontEndLocator);
                            ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, PerformInvitationResults>((long)this.GetHashCode(), "{0}: Performed invitation by provider {1}. Result = {2}", this.MailboxSession.MailboxOwner, key, performInvitationResults);
                            if (performInvitationResults.Result == PerformInvitationResultType.Failed || performInvitationResults.Result == PerformInvitationResultType.PartiallySuccess)
                            {
                                if (!this.FallbackEnabled)
                                {
                                    StoreObjectId folderId = this.SharingContext.FolderId;
                                    InvalidSharingRecipientsResolution invalidSharingRecipientsResolution;
                                    if (!this.CanUseFallback)
                                    {
                                        invalidSharingRecipientsResolution = new InvalidSharingRecipientsResolution(folderId);
                                    }
                                    else
                                    {
                                        using (Folder folder = Folder.Bind(this.MailboxSession, folderId))
                                        {
                                            this.SharingContext.PopulateUrls(folder);
                                        }
                                        invalidSharingRecipientsResolution = new InvalidSharingRecipientsResolution(this.BrowseUrl, this.ICalUrl);
                                    }
                                    ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, InvalidSharingRecipientsResolution>((long)this.GetHashCode(), "{0}: No fall back for these invalid recipients. Resolution = {1}", this.MailboxSession.MailboxOwner, invalidSharingRecipientsResolution);
                                    throw new InvalidSharingRecipientsException(performInvitationResults.FailedRecipients, invalidSharingRecipientsResolution);
                                }
                                ValidRecipient[] array = Array.ConvertAll <InvalidRecipient, ValidRecipient>(performInvitationResults.FailedRecipients, (InvalidRecipient invalidRecipient) => new ValidRecipient(invalidRecipient.SmtpAddress, null));
                                ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, int>((long)this.GetHashCode(), "{0}: Fall back on provider {1} for these {2} failed recipients.", this.MailboxSession.MailboxOwner, fallbackSharingProvider, array.Length);
                                list.AddRange(array);
                                dictionary.Add(key, performInvitationResults.SucceededRecipients);
                            }
                        }
                    }
                    if (this.FallbackEnabled)
                    {
                        foreach (KeyValuePair <SharingProvider, ValidRecipient[]> keyValuePair2 in dictionary)
                        {
                            SharingProvider  key2   = keyValuePair2.Key;
                            ValidRecipient[] value2 = keyValuePair2.Value;
                            this.SharingContext.AvailableSharingProviders[key2] = new CheckRecipientsResults(value2);
                        }
                        this.SharingContext.AvailableSharingProviders[fallbackSharingProvider] = new CheckRecipientsResults(list.ToArray());
                        PerformInvitationResults performInvitationResults2 = fallbackSharingProvider.PerformInvitation(this.MailboxSession, this.SharingContext, list.ToArray(), this.FrontEndLocator);
                        ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingProvider, PerformInvitationResults>((long)this.GetHashCode(), "{0}: Performed invitation by fallback provider {1}. Result = {2}", this.MailboxSession.MailboxOwner, fallbackSharingProvider, performInvitationResults2);
                        if (performInvitationResults2.Result == PerformInvitationResultType.Failed || performInvitationResults2.Result == PerformInvitationResultType.PartiallySuccess)
                        {
                            throw new InvalidOperationException("The fallback provider should never fail.");
                        }
                    }
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        current.Disable();
                    }
                }
            }
        }
Ejemplo n.º 16
0
        internal void ReadFromMessageItem(MessageItem messageItem, bool isDraft)
        {
            byte[] array = messageItem.GetValueOrDefault <byte[]>(InternalSchema.ProviderGuidBinary, null);
            if (array == null)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: ProviderGuidBinary is missing, reading from XSharingProviderGuid", messageItem.Session.UserLegacyDN);
                string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingProviderGuid, null);
                if (valueOrDefault == null)
                {
                    ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingProviderGuid is missing", messageItem.Session.UserLegacyDN);
                    throw new NotSupportedSharingMessageException();
                }
                try
                {
                    array = HexConverter.HexStringToByteArray(valueOrDefault);
                }
                catch (FormatException)
                {
                    ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingProviderGuid is invalid", messageItem.Session.UserLegacyDN);
                    throw new NotSupportedSharingMessageException();
                }
            }
            SharingProvider sharingProvider = SharingProvider.FromGuid(new Guid(array));

            if (sharingProvider == null)
            {
                ExTraceGlobals.SharingTracer.TraceError <string, byte[]>((long)this.GetHashCode(), "{0}: Unknown sharing provider guid: {1}", messageItem.Session.UserLegacyDN, array);
                throw new NotSupportedSharingMessageException();
            }
            ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Find provider {1} that is specified in message.", messageItem.Session.UserLegacyDN, sharingProvider);
            if (sharingProvider == SharingProvider.SharingProviderPublish)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Read from message x-properties for provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider);
                this.ReadFromMessageXProperties(messageItem);
            }
            if (isDraft || sharingProvider != SharingProvider.SharingProviderPublish)
            {
                ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Read from message properties for provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider);
                this.ReadFromMessageProperties(messageItem);
            }
            if (this.context.SharingMessageType == SharingMessageType.Unknown && !isDraft)
            {
                ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingMessageType is unknown", messageItem.Session.UserLegacyDN);
                throw new InvalidSharingMessageException("SharingFlavor");
            }
            this.context.AvailableSharingProviders.Clear();
            if (isDraft && !this.context.SharingMessageType.IsResponseToRequest)
            {
                SharingProvider[] array2 = null;
                using (Folder folder = Folder.Bind(messageItem.Session, this.context.FolderId))
                {
                    array2 = SharingProvider.GetCompatibleProviders(sharingProvider, folder);
                }
                foreach (SharingProvider sharingProvider2 in array2)
                {
                    ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Find compatible provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider2);
                    this.context.AvailableSharingProviders.Add(sharingProvider2, null);
                }
                return;
            }
            this.context.AvailableSharingProviders.Add(sharingProvider, null);
        }
        public bool TryGetProvider(SmtpAddress recipientAddress, ADRecipient adRecipient, IFrontEndLocator frontEndLocator, out SharingProvider provider, out DetailLevelEnumType detailLevel)
        {
            provider    = null;
            detailLevel = DetailLevelEnumType.AvailabilityOnly;
            bool result;

            try
            {
                if (this.mailboxOwner.GetConfiguration().DataStorage.XOWAConsumerSharing.Enabled)
                {
                    provider    = SharingProvider.SharingProviderConsumer;
                    detailLevel = DetailLevelEnumType.Editor;
                    result      = true;
                }
                else
                {
                    if (adRecipient != null)
                    {
                        if (adRecipient.IsValidSecurityPrincipal)
                        {
                            provider    = SharingProvider.SharingProviderInternal;
                            detailLevel = DetailLevelEnumType.Editor;
                            return(true);
                        }
                        if (DelegateUserCollection.IsCrossPremiseDelegateEnabled(this.mailboxOwner) && (adRecipient.RecipientType == RecipientType.User || adRecipient.RecipientType == RecipientType.UserMailbox || adRecipient.RecipientType == RecipientType.MailUser))
                        {
                            provider    = SharingProvider.SharingProviderInternal;
                            detailLevel = DetailLevelEnumType.Editor;
                            return(true);
                        }
                        if (adRecipient.RecipientType != RecipientType.User && adRecipient.RecipientType != RecipientType.UserMailbox && adRecipient.RecipientType != RecipientType.MailUser && adRecipient.RecipientType != RecipientType.Contact && adRecipient.RecipientType != RecipientType.MailContact)
                        {
                            return(false);
                        }
                    }
                    SharingPolicyDomain effectiveCalendarSharingPolicy = this.GetEffectiveCalendarSharingPolicy(recipientAddress.Domain, frontEndLocator);
                    this.TraceDebug("Policy found:{0}", new object[]
                    {
                        (effectiveCalendarSharingPolicy == null) ? "none" : effectiveCalendarSharingPolicy.Domain
                    });
                    int maxAllowed;
                    if (effectiveCalendarSharingPolicy != null && (maxAllowed = PolicyAllowedDetailLevel.GetMaxAllowed(effectiveCalendarSharingPolicy.Actions)) > 0)
                    {
                        detailLevel = (DetailLevelEnumType)maxAllowed;
                        if (effectiveCalendarSharingPolicy.Domain == "Anonymous")
                        {
                            provider = SharingProvider.SharingProviderPublishReach;
                        }
                        else
                        {
                            provider = SharingProvider.SharingProviderExternal;
                        }
                    }
                    result = (provider != null);
                }
            }
            finally
            {
                this.TraceDebug("MailboxOwner:{0},Recipient:{1},RecipientType:{2},Handler={2},DetailLevel={3}", new object[]
                {
                    this.mailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                    recipientAddress,
                    (adRecipient == null) ? "none" : adRecipient.RecipientType.ToString(),
                    (provider == null) ? "none" : provider.Name,
                    detailLevel
                });
            }
            return(result);
        }