Example #1
0
        protected override StoreSession CreateStoreConnection(MailboxConnectFlags mailboxConnectFlags)
        {
            StoreSession storeSession = null;
            StoreSession result;

            try
            {
                if (base.UseHomeMDB || base.IsPublicFolderMove || base.IsFolderMove || mailboxConnectFlags.HasFlag(MailboxConnectFlags.NonMrsLogon))
                {
                    storeSession = base.CreateStoreConnection(mailboxConnectFlags);
                    if (storeSession != null && base.Flags.HasFlag(LocalMailboxFlags.WordBreak))
                    {
                        bool invalidateAnnotations = base.Flags.HasFlag(LocalMailboxFlags.InvalidateContentIndexAnnotations);
                        storeSession.ContentIndexingSession = ContentIndexingSession.CreateSession(storeSession, invalidateAnnotations);
                    }
                }
                else
                {
                    storeSession = this.ConnectToTargetMailbox(false, mailboxConnectFlags);
                }
                StoreSession storeSession2 = storeSession;
                storeSession = null;
                result       = storeSession2;
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(result);
        }
        // Token: 0x0600191D RID: 6429 RVA: 0x000922A4 File Offset: 0x000904A4
        private Folder GetFolderFromPath(string path, bool isPublicFolder)
        {
            string[] array = path.Split(new char[]
            {
                '/',
                '\\'
            }, StringSplitOptions.RemoveEmptyEntries);
            CultureInfo          userCulture   = Culture.GetUserCulture();
            StoreObjectId        storeObjectId = null;
            StoreSession         storeSession  = null;
            OwaStoreObjectIdType objectIdType  = OwaStoreObjectIdType.MailBoxObject;

            try
            {
                if (isPublicFolder)
                {
                    storeSession  = PublicFolderSession.OpenAsAdmin(this.userContext.ExchangePrincipal.MailboxInfo.OrganizationId, this.userContext.ExchangePrincipal, Guid.Empty, null, userCulture, "Client=OWA;Action=WebPart + Admin + GetFolderFromPath", null);
                    storeObjectId = this.userContext.PublicFolderRootId;
                    objectIdType  = OwaStoreObjectIdType.PublicStoreFolder;
                }
                else
                {
                    storeSession = MailboxSession.OpenAsAdmin(this.owaContext.ExchangePrincipal, userCulture, "Client=OWA;Action=WebPart + Admin + GetFolderFromPath");
                    GccUtils.SetStoreSessionClientIPEndpointsFromHttpRequest(storeSession, this.owaContext.HttpContext.Request);
                    storeObjectId = this.userContext.GetRootFolderId(this.userContext.MailboxSession);
                }
                for (int i = 0; i < array.Length; i++)
                {
                    object[][] folderIdByDisplayName = this.GetFolderIdByDisplayName(array[i], storeObjectId, storeSession);
                    if (folderIdByDisplayName == null || folderIdByDisplayName.Length == 0)
                    {
                        return(null);
                    }
                    storeObjectId = ((VersionedId)folderIdByDisplayName[0][0]).ObjectId;
                }
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                    storeSession = null;
                }
            }
            if (storeObjectId == null)
            {
                return(null);
            }
            return(this.GetFolderFromId(OwaStoreObjectId.CreateFromFolderId(storeObjectId, objectIdType)));
        }
        private int WriteFailures(MailboxDatabase mdb, int?errorcode, FailureMode failureMode, ExDateTime?startDate, ExDateTime?endDate)
        {
            int          num          = 0;
            StoreSession storeSession = null;
            ADUser       aduser       = null;
            Guid?        mailboxGuid  = null;

            if (this.Identity != null)
            {
                mailboxGuid = new Guid?(this.Archive ? this.mailbox.ArchiveGuid : this.mailbox.ExchangeGuid);
                aduser      = this.mailbox;
            }
            MdbInfo mdbInfo = new MdbInfo(mdb);

            mdbInfo.EnableOwningServerUpdate = true;
            mdbInfo.UpdateDatabaseLocationInfo();
            Guid?guid = null;

            try
            {
                using (IFailedItemStorage failedItemStorage = Factory.Current.CreateFailedItemStorage(Factory.Current.CreateSearchServiceConfig(mdbInfo.Guid), mdbInfo.IndexSystemName, mdbInfo.OwningServer))
                {
                    FailedItemParameters parameters = new FailedItemParameters(failureMode, FieldSet.Default)
                    {
                        MailboxGuid = mailboxGuid,
                        ErrorCode   = errorcode,
                        StartDate   = startDate,
                        EndDate     = endDate
                    };
                    foreach (IFailureEntry failureEntry in failedItemStorage.GetFailedItems(parameters))
                    {
                        if (failureEntry.MailboxGuid != guid)
                        {
                            guid = new Guid?(failureEntry.MailboxGuid);
                            if (storeSession != null)
                            {
                                storeSession.Dispose();
                                storeSession = null;
                            }
                            if (mailboxGuid == null)
                            {
                                aduser = this.GetADUser(guid.Value);
                            }
                            if (aduser != null && aduser.RecipientTypeDetails == RecipientTypeDetails.PublicFolderMailbox)
                            {
                                storeSession = this.OpenPublicFolderMailboxSession(mdbInfo.Guid, aduser);
                            }
                            else
                            {
                                storeSession = this.OpenMailboxSession(mdbInfo.Guid, guid.Value);
                            }
                        }
                        if (storeSession != null)
                        {
                            int num2 = (int)storeSession.Mailbox.TryGetProperty(MailboxSchema.MailboxNumber);
                            if (num2 != ((MdbItemIdentity)failureEntry.ItemId).MailboxNumber)
                            {
                                continue;
                            }
                        }
                        string subject = this.GetSubject(failureEntry, storeSession);
                        this.WriteResult(new FailedDocument(failureEntry, subject, mdbInfo.Name, aduser));
                        num++;
                    }
                }
            }
            catch (ComponentException exception)
            {
                base.WriteError(exception, ErrorCategory.ReadError, null);
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(num);
        }
Example #4
0
        private StoreSession ConnectToTargetMailbox(bool mailboxMustExist, MailboxConnectFlags mailboxConnectFlags)
        {
            MrsTracer.Provider.Function("StorageDestinationMailbox.ConnectToTargetMailbox", new object[0]);
            base.CheckDisposed();
            StoreSession result      = null;
            ConnectFlag  connectFlag = ConnectFlag.UseAdminPrivilege;

            connectFlag |= ConnectFlag.UseRpcContextPool;
            if (!mailboxMustExist)
            {
                bool flag = false;
                MrsTracer.Provider.Debug("Checking if destination mailbox exists...", new object[0]);
                using (ExRpcAdmin rpcAdmin = base.GetRpcAdmin())
                {
                    using (base.RHTracker.Start())
                    {
                        flag = MapiUtils.IsMailboxInDatabase(rpcAdmin, base.MdbGuid, base.MailboxGuid);
                    }
                }
                if (!flag)
                {
                    MrsTracer.Provider.Debug("Mailbox {0} does not exist in database {1}", new object[]
                    {
                        base.MailboxGuid,
                        base.MdbGuid
                    });
                    return(null);
                }
                MrsTracer.Provider.Debug("Mailbox {0} exists in database {1}", new object[]
                {
                    base.MailboxGuid,
                    base.MdbGuid
                });
            }
            StoreSession storeSession = null;

            try
            {
                using (base.RHTracker.Start())
                {
                    DefaultFolderType[] foldersToInit = (DefaultFolderType[])Enum.GetValues(typeof(DefaultFolderType));
                    MailboxSession.InitializationFlags initializationFlags = MailboxSession.InitializationFlags.DefaultFolders | MailboxSession.InitializationFlags.UserConfigurationManager | MailboxSession.InitializationFlags.DeadSessionChecking | MailboxSession.InitializationFlags.RequestLocalRpc | MailboxSession.InitializationFlags.OverrideHomeMdb | MailboxSession.InitializationFlags.SuppressFolderIdPrefetch | MailboxSession.InitializationFlags.UseNamedProperties | MailboxSession.InitializationFlags.DisconnectedMailbox | MailboxSession.InitializationFlags.MoveUser;
                    if (base.MbxType == MailboxType.DestMailboxCrossOrg)
                    {
                        initializationFlags |= MailboxSession.InitializationFlags.XForestMove;
                    }
                    MrsTracer.Provider.Debug("Opening Mailbox Session: mailbox='{0}', mailboxGuid={1}, dbGuid={2}, connectFlags=[{3}], initFlags=[{4}]", new object[]
                    {
                        base.TraceMailboxId,
                        base.MailboxGuid.ToString(),
                        base.MdbGuid.ToString(),
                        connectFlag,
                        initializationFlags
                    });
                    OrganizationId organizationId;
                    if (base.PartitionHint != null)
                    {
                        ADSessionSettings adsessionSettings = ADSessionSettings.FromTenantPartitionHint(base.PartitionHint);
                        organizationId = adsessionSettings.CurrentOrganizationId;
                    }
                    else
                    {
                        organizationId = OrganizationId.ForestWideOrgId;
                    }
                    ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromMailboxData(base.MailboxGuid, base.MdbGuid, organizationId, StorageMailbox.CultureInfos);
                    string            clientInfoString  = "Client=MSExchangeMigration";
                    if ((mailboxConnectFlags & MailboxConnectFlags.PublicFolderHierarchyReplication) != MailboxConnectFlags.None)
                    {
                        clientInfoString = "Client=PublicFolderSystem;Action=PublicFolderHierarchyReplication";
                    }
                    if (base.IsPublicFolderMailbox)
                    {
                        storeSession = PublicFolderSession.OpenAsMRS(exchangePrincipal, clientInfoString, OpenMailboxSessionFlags.None);
                    }
                    else
                    {
                        MailboxAccessInfo accessInfo = new MailboxAccessInfo(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                        storeSession = MailboxSession.ConfigurableOpen(exchangePrincipal, accessInfo, CultureInfo.InvariantCulture, clientInfoString, LogonType.SystemService, null, initializationFlags, foldersToInit);
                    }
                    if (!base.TestIntegration.DisableFolderCreationBlockFeature)
                    {
                        storeSession.BlockFolderCreation = true;
                    }
                    if (storeSession != null && base.Flags.HasFlag(LocalMailboxFlags.WordBreak))
                    {
                        bool invalidateAnnotations = base.Flags.HasFlag(LocalMailboxFlags.InvalidateContentIndexAnnotations);
                        storeSession.ContentIndexingSession = ContentIndexingSession.CreateSession(storeSession, invalidateAnnotations);
                    }
                    result       = storeSession;
                    storeSession = null;
                }
            }
            catch (Exception ex)
            {
                if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                {
                    WellKnownException.MapiNotFound
                }))
                {
                    base.VerifyMdbIsOnline(ex);
                    if (mailboxMustExist)
                    {
                        throw;
                    }
                }
                else
                {
                    if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                    {
                        WellKnownException.MapiMailboxInTransit
                    }))
                    {
                        throw this.GetMailboxInTransitException(ex);
                    }
                    throw;
                }
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(result);
        }