示例#1
0
        public virtual void EnsureDataLoaded(IFolder folder, FolderRecDataFlags dataToLoad, MailboxCopierBase mbxCtx)
        {
            FolderRecDataFlags folderRecDataFlags = dataToLoad & FolderRecDataFlags.ExtendedData;

            if (folderRecDataFlags != FolderRecDataFlags.None && !this.FieldIsLoaded(folderRecDataFlags))
            {
                GetFolderRecFlags getFolderRecFlags = GetFolderRecFlags.None;
                if (this.FolderType == FolderType.Generic)
                {
                    if ((dataToLoad & FolderRecDataFlags.PromotedProperties) != FolderRecDataFlags.None && !this.FieldIsLoaded(FolderRecDataFlags.PromotedProperties))
                    {
                        getFolderRecFlags |= GetFolderRecFlags.PromotedProperties;
                    }
                    if ((dataToLoad & FolderRecDataFlags.Restrictions) != FolderRecDataFlags.None && !this.FieldIsLoaded(FolderRecDataFlags.Restrictions))
                    {
                        getFolderRecFlags |= GetFolderRecFlags.Restrictions;
                    }
                }
                if ((this.FolderType == FolderType.Generic || this.FolderType == FolderType.Search) && (dataToLoad & FolderRecDataFlags.Views) != FolderRecDataFlags.None && !this.FieldIsLoaded(FolderRecDataFlags.Views))
                {
                    getFolderRecFlags |= GetFolderRecFlags.Views;
                }
                if (getFolderRecFlags != GetFolderRecFlags.None)
                {
                    FolderRec folderRec = folder.GetFolderRec(null, getFolderRecFlags);
                    this.FolderRec.SetPromotedProperties(folderRec.GetPromotedProperties());
                    this.FolderRec.Views        = folderRec.Views;
                    this.FolderRec.ICSViews     = folderRec.ICSViews;
                    this.FolderRec.Restrictions = folderRec.Restrictions;
                }
                this.LoadedData |= folderRecDataFlags;
            }
            if ((dataToLoad & FolderRecDataFlags.SearchCriteria) != FolderRecDataFlags.None && !this.IsSpoolerQueue && !this.FieldIsLoaded(FolderRecDataFlags.SearchCriteria))
            {
                this.ReadSearchCriteria(folder, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.LoadedData |= FolderRecDataFlags.SearchCriteria;
            }
            if ((dataToLoad & FolderRecDataFlags.Rules) != FolderRecDataFlags.None && !this.FieldIsLoaded(FolderRecDataFlags.Rules))
            {
                this.ReadRules(folder, FolderRecWrapper.extraTags, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.LoadedData |= FolderRecDataFlags.Rules;
                MrsTracer.Service.Debug("Rules loaded: {0}", new object[]
                {
                    new RulesDataContext(this.Rules)
                });
            }
            if ((dataToLoad & FolderRecDataFlags.SecurityDescriptors) != FolderRecDataFlags.None && !this.FieldIsLoaded(FolderRecDataFlags.SecurityDescriptors))
            {
                this.FolderNTSD         = this.ReadSD(folder, SecurityProp.NTSD, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.FolderFreeBusyNTSD = this.ReadSD(folder, SecurityProp.FreeBusyNTSD, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.LoadedData        |= FolderRecDataFlags.SecurityDescriptors;
                MrsTracer.Service.Debug("FolderSDs loaded: NTSD {0}, FreeBusyNTSD {1}", new object[]
                {
                    CommonUtils.GetSDDLString(this.FolderNTSD),
                    CommonUtils.GetSDDLString(this.FolderFreeBusyNTSD)
                });
            }
            if (dataToLoad.HasFlag(FolderRecDataFlags.FolderAcls) && !this.FieldIsLoaded(FolderRecDataFlags.FolderAcls))
            {
                this.FolderACL         = this.ReadACL(folder, SecurityProp.NTSD, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.FolderFreeBusyACL = this.ReadACL(folder, SecurityProp.FreeBusyNTSD, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.LoadedData       |= FolderRecDataFlags.FolderAcls;
                MrsTracer.Service.Debug("FolderAcls are loaded: ACL {0}, FreeBusyACL {1}", new object[]
                {
                    new PropValuesDataContext(this.FolderACL).ToString(),
                    new PropValuesDataContext(this.FolderFreeBusyACL).ToString()
                });
            }
            if (dataToLoad.HasFlag(FolderRecDataFlags.ExtendedAclInformation) && !this.FieldIsLoaded(FolderRecDataFlags.ExtendedAclInformation))
            {
                this.FolderACL         = this.ReadExtendedAcl(folder, AclFlags.FolderAcl, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.FolderFreeBusyACL = this.ReadExtendedAcl(folder, AclFlags.FreeBusyAcl, new Action <List <BadMessageRec> >(mbxCtx.ReportBadItems), new Func <byte[], IFolder>(mbxCtx.SourceMailboxWrapper.GetFolder));
                this.LoadedData       |= FolderRecDataFlags.ExtendedAclInformation;
                MrsTracer.Service.Debug("FolderExtendedAcls are loaded: Acl {0}, FreeBusyAcl {1}", new object[]
                {
                    new PropValuesDataContext(this.FolderACL).ToString(),
                    new PropValuesDataContext(this.FolderFreeBusyACL).ToString()
                });
            }
        }
        void IDestinationMailbox.CreateFolder(FolderRec sourceFolder, CreateFolderFlags createFolderFlags, out byte[] newFolderId)
        {
            MrsTracer.Provider.Function("MapiDestinationMailbox.CreateFolder(\"{0}\")", new object[]
            {
                sourceFolder.FolderName
            });
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            if (createFolderFlags.HasFlag(CreateFolderFlags.InternalAccess))
            {
                throw new InternalAccessFolderCreationIsNotSupportedException();
            }
            FolderRec folderRec = null;

            newFolderId = null;
            using (base.RHTracker.Start())
            {
                if (!createFolderFlags.HasFlag(CreateFolderFlags.FailIfExists) && sourceFolder.EntryId != null)
                {
                    OpenEntryFlags flags = OpenEntryFlags.DontThrowIfEntryIsMissing;
                    using (MapiFolder mapiFolder = (MapiFolder)base.MapiStore.OpenEntry(sourceFolder.EntryId, flags))
                    {
                        if (mapiFolder != null)
                        {
                            folderRec   = FolderRec.Create(mapiFolder, null);
                            newFolderId = folderRec.EntryId;
                        }
                    }
                }
                if (newFolderId == null)
                {
                    OpenEntryFlags flags2 = OpenEntryFlags.DeferredErrors | OpenEntryFlags.Modify;
                    using (MapiFolder mapiFolder2 = (MapiFolder)base.MapiStore.OpenEntry(sourceFolder.ParentId, flags2))
                    {
                        using (MapiFolder mapiFolder3 = mapiFolder2.CreateFolder(sourceFolder.FolderName, null, false, sourceFolder.FolderType == FolderType.Search, sourceFolder.EntryId))
                        {
                            newFolderId = mapiFolder3.GetProp(PropTag.EntryId).GetBytes();
                        }
                        goto IL_160;
                    }
                }
                if (!CommonUtils.IsSameEntryId(folderRec.ParentId, sourceFolder.ParentId))
                {
                    MrsTracer.Provider.Debug("Existing folder is under the wrong parent. Moving it.", new object[0]);
                    ((IDestinationMailbox)this).MoveFolder(folderRec.EntryId, folderRec.ParentId, sourceFolder.ParentId);
                }
IL_160:
                PropTag[] promotedProperties = sourceFolder.GetPromotedProperties();
                if ((promotedProperties != null && promotedProperties.Length > 0) || (sourceFolder.Restrictions != null && sourceFolder.Restrictions.Length > 0) || (sourceFolder.Views != null && sourceFolder.Views.Length > 0) || (sourceFolder.ICSViews != null && sourceFolder.ICSViews.Length > 0))
                {
                    using (MapiDestinationFolder folder = base.GetFolder <MapiDestinationFolder>(newFolderId))
                    {
                        ICSViewData[] icsViews = null;
                        if (this.ServerVersion >= Server.E15MinVersion)
                        {
                            icsViews = sourceFolder.ICSViews;
                        }
                        folder.SetExtendedProps(promotedProperties, sourceFolder.Restrictions, sourceFolder.Views, icsViews);
                    }
                }
            }
        }
示例#3
0
        void IDestinationMailbox.CreateFolder(FolderRec sourceFolder, CreateFolderFlags createFolderFlags, out byte[] newFolderId)
        {
            MrsTracer.Provider.Function("StorageDestinationMailbox.CreateFolder(\"{0}\")", new object[]
            {
                sourceFolder.FolderName
            });
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            FolderRec folderRec = null;

            newFolderId = null;
            bool   isSearchFolder = sourceFolder.FolderType == FolderType.Search;
            string text           = sourceFolder.FolderName;

            if (string.IsNullOrWhiteSpace(text))
            {
                text = Guid.NewGuid().ToString();
            }
            using (base.RHTracker.Start())
            {
                if (sourceFolder.EntryId != null)
                {
                    using (StorageDestinationFolder folder = base.GetFolder <StorageDestinationFolder>(sourceFolder.EntryId))
                    {
                        if (folder != null)
                        {
                            MrsTracer.Provider.Debug("Source folder '{0}' already exists in destination.", new object[]
                            {
                                sourceFolder.FolderName
                            });
                            if (createFolderFlags.HasFlag(CreateFolderFlags.FailIfExists))
                            {
                                throw new FolderAlreadyExistsException(sourceFolder.FolderName);
                            }
                            folderRec   = ((IFolder)folder).GetFolderRec(null, GetFolderRecFlags.None);
                            newFolderId = folderRec.EntryId;
                        }
                    }
                }
                if (newFolderId == null)
                {
                    CreateMode createMode = CreateMode.OverrideFolderCreationBlock;
                    if (createFolderFlags.HasFlag(CreateFolderFlags.CreatePublicFolderDumpster))
                    {
                        createMode |= CreateMode.CreatePublicFolderDumpster;
                    }
                    using (CoreFolder coreFolder = createFolderFlags.HasFlag(CreateFolderFlags.InternalAccess) ? CoreFolder.CreateSecure(base.StoreSession, base.GetFolderId(sourceFolder.ParentId), isSearchFolder, text, createMode) : CoreFolder.Create(base.StoreSession, base.GetFolderId(sourceFolder.ParentId), isSearchFolder, text, createMode))
                    {
                        if (sourceFolder.EntryId != null)
                        {
                            coreFolder.PropertyBag[StoreObjectSchema.EntryId] = sourceFolder.EntryId;
                        }
                        string value;
                        if (!string.IsNullOrEmpty(sourceFolder.FolderClass) && StorageDestinationMailbox.folderClassMap.TryGetValue(sourceFolder.FolderClass, out value))
                        {
                            coreFolder.PropertyBag[StoreObjectSchema.ContainerClass] = value;
                        }
                        coreFolder.Save(SaveMode.FailOnAnyConflict);
                        coreFolder.PropertyBag.Load(FolderSchema.Instance.AutoloadProperties);
                        newFolderId = coreFolder.Id.ObjectId.ProviderLevelItemId;
                        goto IL_225;
                    }
                }
                if (!CommonUtils.IsSameEntryId(folderRec.ParentId, sourceFolder.ParentId))
                {
                    MrsTracer.Common.Debug("Existing folder is under the wrong parent. Moving it.", new object[0]);
                    ((IDestinationMailbox)this).MoveFolder(sourceFolder.EntryId, folderRec.ParentId, sourceFolder.ParentId);
                }
IL_225:
                PropTag[] promotedProperties = sourceFolder.GetPromotedProperties();
                if ((promotedProperties != null && promotedProperties.Length > 0) || (sourceFolder.Restrictions != null && sourceFolder.Restrictions.Length > 0) || (sourceFolder.Views != null && sourceFolder.Views.Length > 0) || (sourceFolder.ICSViews != null && sourceFolder.ICSViews.Length > 0))
                {
                    using (StorageDestinationFolder folder2 = base.GetFolder <StorageDestinationFolder>(sourceFolder.EntryId))
                    {
                        folder2.SetExtendedProps(promotedProperties, sourceFolder.Restrictions, sourceFolder.Views, sourceFolder.ICSViews);
                    }
                }
            }
        }