Exemplo n.º 1
0
        internal static bool TryGetBackEndWebServicesUrlFromSmtp(string smtpString, Func <SmtpAddress, IRecipientSession> createRecipientSession, out Uri ewsUri)
        {
            ewsUri = null;
            ProxyAddress proxyAddress;

            if (!ProxyAddress.TryParse(smtpString, out proxyAddress))
            {
                ExTraceGlobals.CafeTracer.TraceDebug <string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] The smtp address was invalid: {0}", smtpString);
                return(false);
            }
            if (proxyAddress.Prefix != ProxyAddressPrefix.Smtp)
            {
                ExTraceGlobals.CafeTracer.TraceDebug <string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Non-SMTP address is not supported: {0}", smtpString);
                return(false);
            }
            SmtpAddress       arg     = new SmtpAddress(proxyAddress.AddressString);
            IRecipientSession session = createRecipientSession(arg);

            try
            {
                ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromProxyAddress(session, smtpString);
                ewsUri = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo);
            }
            catch (ObjectNotFoundException ex)
            {
                ExTraceGlobals.CafeTracer.TraceDebug <string, string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Couldn't find exchange principal for smtp address: {0}. Exception {1}", smtpString, ex.ToString());
                return(false);
            }
            catch (BackEndLocatorException ex2)
            {
                ExTraceGlobals.CafeTracer.TraceDebug <string, string>(0L, "[HttpProxyBackEndHelper.TryGetBackEndWebServicesUrlFromSmtp] Couldn't find exchange services url for smtp address: {0}. Exception: {1}", smtpString, ex2.ToString());
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
 private void ComputeTargetPrincipalAndStampOntoRequest(PhotoRequest request)
 {
     if (request.TargetPrincipal != null)
     {
         this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: target principal has already been initialized.");
         return;
     }
     if (request.Requestor == null || request.Requestor.OrganizationId == null)
     {
         this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: cannot compute target principal because requestor's organization id has not been initialized.");
         return;
     }
     if (string.IsNullOrEmpty(request.TargetSmtpAddress))
     {
         this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: cannot compute target principal because the target's SMTP address has not been initialized.");
         return;
     }
     using (new StopwatchPerformanceTracker("MailboxPhotoHandlerComputeTargetPrincipal", request.PerformanceLogger))
     {
         using (new ADPerformanceTracker("MailboxPhotoHandlerComputeTargetPrincipal", request.PerformanceLogger))
         {
             this.tracer.TraceDebug((long)this.GetHashCode(), "MAILBOX HANDLER: computing target principal.");
             request.TargetPrincipal = ExchangePrincipal.FromProxyAddress(this.recipientSession, request.TargetSmtpAddress, RemotingOptions.LocalConnectionsOnly);
             if (request.TargetAdObjectId == null)
             {
                 request.TargetAdObjectId = request.TargetPrincipal.ObjectId;
                 this.tracer.TraceDebug <ADObjectId>((long)this.GetHashCode(), "MAILBOX HANDLER: stamped AD object ID '{0}' onto request.", request.TargetAdObjectId);
             }
         }
     }
 }
        public void ReloadPrincipal()
        {
            string      text        = this.currentExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString();
            SmtpAddress smtpAddress = new SmtpAddress(text);

            this.currentExchangePrincipal = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(smtpAddress.Domain), text);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            CalendarLog calendarLog = this.CalendarLogs.FirstOrDefault <CalendarLog>();

            if (calendarLog == null)
            {
                return;
            }
            CalendarDiagnosticAnalyzer calendarDiagnosticAnalyzer;

            if (calendarLog.IsFileLink)
            {
                calendarDiagnosticAnalyzer = new CalendarDiagnosticAnalyzer(null, this.DetailLevel);
            }
            else
            {
                CalendarLogId calendarLogId = calendarLog.Identity as CalendarLogId;
                UriHandler    uriHandler    = new UriHandler(calendarLogId.Uri);
                string        host          = uriHandler.Host;
                SmtpAddress   address       = new SmtpAddress(uriHandler.UserName, host);
                if (!address.IsValidAddress)
                {
                    base.WriteError(new InvalidADObjectOperationException(Strings.Error_InvalidAddress((string)address)), ErrorCategory.InvalidData, null);
                }
                ExchangePrincipal principal = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(host), (string)address, RemotingOptions.AllowCrossSite);
                calendarDiagnosticAnalyzer = new CalendarDiagnosticAnalyzer(principal, this.DetailLevel);
            }
            try
            {
                CalendarLog[] array;
                if (!string.IsNullOrEmpty(this.GlobalObjectId))
                {
                    array = (from f in this.CalendarLogs
                             where f.CleanGlobalObjectId == this.GlobalObjectId
                             select f).ToArray <CalendarLog>();
                }
                else
                {
                    array = this.CalendarLogs;
                }
                CalendarLog[] calendarLogs             = array;
                IEnumerable <CalendarLogAnalysis> logs = calendarDiagnosticAnalyzer.AnalyzeLogs(calendarLogs);
                base.WriteObject(CalendarLogAnalysisSerializer.Serialize(logs, this.OutputAs, this.DetailLevel, true));
            }
            catch (InvalidLogCollectionException)
            {
                base.WriteError(new InvalidADObjectOperationException(Strings.Error_MultipleItemsFound), ErrorCategory.InvalidData, null);
            }
            TaskLogger.LogExit();
        }
Exemplo n.º 6
0
        public static ExchangePrincipal GetExchangePrincipal(string smtpAddress, out ADSessionSettings adSessionSettings, bool isArchive)
        {
            adSessionSettings = Directory.SessionSettingsFromAddress(smtpAddress);
            ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromProxyAddress(adSessionSettings, ProxyAddressPrefix.Smtp.PrimaryPrefix + ":" + smtpAddress);

            if (exchangePrincipal == null)
            {
                throw new OwaADUserNotFoundException("PrimarySmtpAddress=" + smtpAddress);
            }
            if (isArchive)
            {
                return(exchangePrincipal.GetArchiveExchangePrincipal());
            }
            return(exchangePrincipal);
        }
Exemplo n.º 7
0
 private void ResolveAccessedUser()
 {
     if (string.IsNullOrEmpty(this.accessedUserSmtpAddress))
     {
         this.accessedUserExchangePrincipal = ExchangePrincipal.FromUserSid(this.GetOrganizationIdFromIdentity(this.accessedUserIdentity).ToADSessionSettings(), this.accessedUserSid);
         this.logonUserPrincipal            = new GenericPrincipal(this.LogonUserIdentity, null);
     }
     else
     {
         OrganizationId   organizationId   = OrganizationId.ForestWideOrgId;
         SidBasedIdentity sidBasedIdentity = this.LogonUserIdentity as SidBasedIdentity;
         if (sidBasedIdentity != null)
         {
             organizationId = sidBasedIdentity.UserOrganizationId;
         }
         else
         {
             DelegatedPrincipal delegatedPrincipal = this.logonUserPrincipal as DelegatedPrincipal;
             if (delegatedPrincipal != null)
             {
                 SmtpDomain domain;
                 if (SmtpDomain.TryParse(delegatedPrincipal.DelegatedOrganization, out domain))
                 {
                     organizationId = DomainCache.Singleton.Get(new SmtpDomainWithSubdomains(domain, false)).OrganizationId;
                 }
             }
             else
             {
                 ExchangePrincipal exchangePrincipal = this.GetLogonUserExchangePrincipal();
                 if (exchangePrincipal != null)
                 {
                     organizationId = exchangePrincipal.MailboxInfo.OrganizationId;
                 }
             }
         }
         ADSessionSettings adSettings  = organizationId.ToADSessionSettings();
         string            partitionId = null;
         if (organizationId != null && organizationId != OrganizationId.ForestWideOrgId && organizationId.PartitionId != null)
         {
             partitionId = organizationId.PartitionId.ToString();
         }
         this.accessedUserExchangePrincipal = ExchangePrincipal.FromProxyAddress(adSettings, this.accessedUserSmtpAddress, RemotingOptions.AllowCrossSite);
         this.accessedUserIdentity          = new GenericSidIdentity(this.accessedUserExchangePrincipal.Sid.Value, this.LogonUserIdentity.AuthenticationType + "-ExplicitSignOn", this.accessedUserExchangePrincipal.Sid, partitionId);
         this.accessedUserSid = this.accessedUserIdentity.GetSecurityIdentifier();
     }
     this.hasFullAccess    = this.CanOpenAccessedUserMailbox();
     this.identityResolved = true;
 }
        // Token: 0x060006CD RID: 1741 RVA: 0x00025EEC File Offset: 0x000240EC
        internal override GetSyncStateResult GetExchangeDiagnosticsInfoData(DiagnosableParameters arguments)
        {
            ParsedCallData     parsedCallData = this.ParseCallData(arguments.Argument);
            ExchangePrincipal  mailboxOwner   = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(parsedCallData.Mailbox.Domain), parsedCallData.Mailbox.ToString(), RemotingOptions.AllowCrossSite);
            GetSyncStateResult result;

            using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.CurrentCulture, "Client=ActiveSync"))
            {
                GetSyncStateResult data = SyncStateDiagnostics.GetData(mailboxSession, parsedCallData);
                if (parsedCallData.FidMapping)
                {
                    this.FillFidMapping(data, mailboxSession);
                }
                result = data;
            }
            return(result);
        }
Exemplo n.º 9
0
        private DeletionResult DeleteMessageFromOutboxHelper(DeleteMapiMailDefinition deleteMapiMailDefinition)
        {
            DeletionResult    result = DeletionResult.Fail;
            string            domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(deleteMapiMailDefinition.SenderEmailAddress);
            ExchangePrincipal mailboxOwner             = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), deleteMapiMailDefinition.SenderEmailAddress);
            QueryFilter       queryFilter = new AndFilter(new List <QueryFilter>(2)
            {
                new TextFilter(ItemSchema.InternetMessageId, deleteMapiMailDefinition.InternetMessageId, MatchOptions.FullString, MatchFlags.IgnoreCase),
                new TextFilter(StoreObjectSchema.ItemClass, deleteMapiMailDefinition.MessageClass, MatchOptions.FullString, MatchFlags.IgnoreCase)
            }.ToArray());

            using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe"))
            {
                using (Folder folder = Folder.Bind(mailboxSession, DefaultFolderType.Outbox))
                {
                    using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, queryFilter, null, new PropertyDefinition[]
                    {
                        ItemSchema.Id
                    }))
                    {
                        object[][] rows = queryResult.GetRows(1);
                        if (rows == null || rows.Length == 0)
                        {
                            result = DeletionResult.NoMatchingMessage;
                        }
                        else
                        {
                            mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                            {
                                ((VersionedId)rows[0][0]).ObjectId
                            });
                            result = DeletionResult.Success;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 10
0
        private void SendMapiMessageHelper(bool setLamNotificationId, string lamNotificationId, SendMapiMailDefinition mapiMailDefinition, bool returnOutParameters, out string entryId, out string internetMessageId, out Guid senderMbxGuid)
        {
            entryId           = string.Empty;
            internetMessageId = string.Empty;
            senderMbxGuid     = Guid.Empty;
            ExchangePrincipal mailboxOwner;

            if (mapiMailDefinition.SenderMbxGuid != Guid.Empty)
            {
                mailboxOwner = ExchangePrincipal.FromMailboxData(mapiMailDefinition.SenderMbxGuid, mapiMailDefinition.SenderMdbGuid, new List <CultureInfo>(0));
            }
            else
            {
                string domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(mapiMailDefinition.SenderEmailAddress);
                mailboxOwner = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), mapiMailDefinition.SenderEmailAddress);
            }
            using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe"))
            {
                using (MessageItem messageItem = MessageItem.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox)))
                {
                    messageItem.ClassName = mapiMailDefinition.MessageClass;
                    if (setLamNotificationId)
                    {
                        messageItem[MessageItemSchema.MapiSubmitLamNotificationId] = lamNotificationId;
                        messageItem[MessageItemSchema.XLAMNotificationId]          = lamNotificationId;
                    }
                    messageItem[MessageItemSchema.DoNotDeliver] = (mapiMailDefinition.DoNotDeliver ? "Supress" : "Deliver");
                    if (mapiMailDefinition.DropMessageInHub)
                    {
                        messageItem[MessageItemSchema.DropMessageInHub] = "FrontEnd-CAT-250";
                        messageItem[MessageItemSchema.SystemProbeDrop]  = "OnEndOfHeaders";
                    }
                    messageItem.Subject = mapiMailDefinition.MessageSubject;
                    BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);
                    using (TextWriter textWriter = messageItem.Body.OpenTextWriter(configuration))
                    {
                        textWriter.Write(mapiMailDefinition.MessageBody);
                    }
                    messageItem.Recipients.Add(new Participant(mapiMailDefinition.RecipientEmailAddress, mapiMailDefinition.RecipientEmailAddress, "SMTP"), RecipientItemType.To);
                    if (mapiMailDefinition.DeleteAfterSubmit)
                    {
                        messageItem.SendWithoutSavingMessage();
                    }
                    else
                    {
                        messageItem.Send();
                    }
                    if (returnOutParameters)
                    {
                        senderMbxGuid = mailboxSession.MailboxGuid;
                        messageItem.Load(new PropertyDefinition[]
                        {
                            StoreObjectSchema.EntryId,
                            ItemSchema.InternetMessageId
                        });
                        object obj      = messageItem.TryGetProperty(StoreObjectSchema.EntryId);
                        byte[] entryId2 = (byte[])obj;
                        entryId = MapiMessageSubmitter.EntryIdString(entryId2);
                        object obj2 = messageItem.TryGetProperty(ItemSchema.InternetMessageId);
                        internetMessageId = obj2.ToString();
                    }
                }
            }
        }
Exemplo n.º 11
0
        // Token: 0x06000AFA RID: 2810 RVA: 0x0002C438 File Offset: 0x0002A638
        internal override MailAppsResult GetExchangeDiagnosticsInfoData(DiagnosableParameters argument)
        {
            MailAppsResult mailAppsResult = new MailAppsResult();
            string         text           = argument.Argument;

            if (!string.IsNullOrEmpty(text))
            {
                string value = null;
                string text2 = ",val=";
                int    num   = text.IndexOf(text2);
                if (num != -1)
                {
                    value = text.Substring(num + text2.Length);
                    text  = argument.Argument.Substring(0, num);
                }
                MailAppsArgument mailAppsArgument = new MailAppsArgument(text);
                if (mailAppsArgument.HasArgument("org") && mailAppsArgument.HasArgument("cmd"))
                {
                    bool              flag      = false;
                    string            argument2 = mailAppsArgument.GetArgument <string>("org");
                    ExchangePrincipal exchangePrincipal;
                    if (mailAppsArgument.HasArgument("usr"))
                    {
                        string            argument3  = mailAppsArgument.GetArgument <string>("usr");
                        ADSessionSettings adSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(argument2);
                        exchangePrincipal = ExchangePrincipal.FromProxyAddress(adSettings, argument3 + "@" + argument2, RemotingOptions.AllowCrossSite);
                    }
                    else
                    {
                        ADUser orgMailbox = OrgExtensionTable.GetOrgMailbox(argument2);
                        exchangePrincipal = ExchangePrincipal.FromADUser(orgMailbox, null);
                        flag = true;
                    }
                    using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, CultureInfo.CurrentCulture, "Client=WebServices"))
                    {
                        using (UserConfiguration folderConfiguration = UserConfigurationHelper.GetFolderConfiguration(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox), "ExtensionMasterTable", UserConfigurationTypes.XML, true, false))
                        {
                            using (Stream xmlStream = folderConfiguration.GetXmlStream())
                            {
                                if (string.Equals(mailAppsArgument.GetArgument <string>("cmd"), "set", StringComparison.OrdinalIgnoreCase) && num != -1)
                                {
                                    xmlStream.SetLength(0L);
                                    bool flag2 = string.IsNullOrEmpty(value);
                                    if (!flag2)
                                    {
                                        using (StreamWriter streamWriter = new StreamWriter(xmlStream, Encoding.UTF8))
                                        {
                                            streamWriter.Write(value);
                                        }
                                    }
                                    folderConfiguration.Save();
                                    if (flag)
                                    {
                                        OrgEmptyMasterTableCache.Singleton.Update(exchangePrincipal.MailboxInfo.OrganizationId, flag2);
                                    }
                                    mailAppsResult.Message = "Raw value saved.";
                                }
                                else
                                {
                                    using (StreamReader streamReader = new StreamReader(xmlStream, true))
                                    {
                                        mailAppsResult.RawMasterTable = streamReader.ReadToEnd();
                                        if (mailAppsArgument.HasArgument("len"))
                                        {
                                            int argument4 = mailAppsArgument.GetArgument <int>("len");
                                            if (argument4 > 0 && argument4 < mailAppsResult.RawMasterTable.Length)
                                            {
                                                mailAppsResult.RawMasterTable = mailAppsResult.RawMasterTable.Substring(0, argument4);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(mailAppsResult);
        }
Exemplo n.º 12
0
        private void PerformArchiveConnectivityTest(ref ArchiveConnectivityOutcome result)
        {
            bool flag  = false;
            bool flag2 = false;

            try
            {
                SmtpAddress       userSmtp          = this.UserSmtp;
                ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(userSmtp.Domain), userSmtp.ToString());
                if (exchangePrincipal != null)
                {
                    if (this.IncludeArchiveMRMConfiguration || !string.IsNullOrEmpty(this.MessageId))
                    {
                        this.LogonPrimary(exchangePrincipal);
                        result.PrimaryMRMConfiguration  = this.primaryFAI;
                        result.PrimaryLastProcessedTime = this.primaryLastProcessedTime;
                    }
                    flag = true;
                    ADObjectId        objectId = exchangePrincipal.ObjectId;
                    IRecipientSession tenantOrRootOrgRecipientSession;
                    if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled)
                    {
                        tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.FullyConsistent, exchangePrincipal.MailboxInfo.OrganizationId.ToADSessionSettings(), 276, "PerformArchiveConnectivityTest", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Monitoring\\ArchiveConnectivity\\TestArchiveConnectivityTask.cs");
                    }
                    else
                    {
                        tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.FullyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 284, "PerformArchiveConnectivityTest", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Monitoring\\ArchiveConnectivity\\TestArchiveConnectivityTask.cs");
                    }
                    ADUser aduser = tenantOrRootOrgRecipientSession.FindADUserByObjectId(objectId);
                    this.complianceConfiguration   = aduser.ElcMailboxFlags.ToString();
                    result.ComplianceConfiguration = this.complianceConfiguration;
                    if (exchangePrincipal.GetArchiveMailbox() == null)
                    {
                        result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, Strings.ArchiveConnectivityResultArchiveNotProvisioned);
                    }
                    else
                    {
                        if (aduser.ArchiveDomain != null)
                        {
                            result.ArchiveDomain = aduser.ArchiveDomain.ToString();
                            flag2 = true;
                        }
                        if (aduser.ArchiveDatabase != null)
                        {
                            result.ArchiveDatabase = aduser.ArchiveDatabase.ToString();
                        }
                        if (aduser.RecipientType == RecipientType.UserMailbox)
                        {
                            if (flag2)
                            {
                                if (ArchiveStatusFlags.Active != aduser.ArchiveStatus)
                                {
                                    result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, Strings.ArchiveConnectivityResultArchiveNotActive);
                                }
                                else if (this.LogonArchive(this.GetArchivePrincipal(exchangePrincipal, aduser)))
                                {
                                    result.Update(ArchiveConnectivityResultEnum.Success, "");
                                }
                            }
                            else if (this.LogonArchive(this.GetArchivePrincipal(exchangePrincipal, aduser)))
                            {
                                result.Update(ArchiveConnectivityResultEnum.Success, "");
                            }
                        }
                        if (this.IncludeArchiveMRMConfiguration)
                        {
                            result.ArchiveMRMConfiguration  = this.archiveFAI;
                            result.ArchiveLastProcessedTime = this.archiveLastProcessedTime;
                        }
                    }
                }
                this.mrmProperties = this.mrmPropReport.ToString();
                if (!string.IsNullOrEmpty(this.mrmProperties))
                {
                    result.ItemMRMProperties = this.mrmProperties;
                }
                else if (!string.IsNullOrEmpty(this.MessageId))
                {
                    result.ItemMRMProperties = "Item not found.";
                }
            }
            catch (ObjectNotFoundException ex)
            {
                if (!flag)
                {
                    result.Update(ArchiveConnectivityResultEnum.PrimaryFailure, this.GetAllInnerExceptions(ex));
                }
                else
                {
                    result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex));
                }
            }
            catch (ConnectionFailedTransientException ex2)
            {
                result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex2));
            }
            catch (AutoDAccessException ex3)
            {
                result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex3));
            }
            catch (StoragePermanentException ex4)
            {
                result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex4));
            }
            catch (StorageTransientException ex5)
            {
                result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex5));
            }
            catch (ArgumentException ex6)
            {
                result.Update(ArchiveConnectivityResultEnum.ArchiveFailure, this.GetAllInnerExceptions(ex6));
            }
        }