public void CreateMissingFolders() { IDestinationMailbox destMailbox = (IDestinationMailbox)this.MbxWrapper.Mailbox; base.EnumerateFolderHierarchy(EnumHierarchyFlags.AllFolders, delegate(FolderRecWrapper fRec, FolderMap.EnumFolderContext ctx) { if (fRec.EntryId != null) { return; } FolderMapping fm = (FolderMapping)fRec; fm.FolderRec.ParentId = fm.ParentId; ExecutionContext.Create(new DataContext[] { new FolderRecWrapperDataContext(fRec) }).Execute(delegate { byte[] array; destMailbox.CreateFolder(fRec.FolderRec, CreateFolderFlags.FailIfExists, out array); fm.FolderRec.EntryId = array; this[array] = fm; if (fm.SourceFolder != null) { List <PropValueData> list = new List <PropValueData>(); list.Add(new PropValueData(this.SourceEntryIDPtag, fm.SourceFolder.EntryId)); list.Add(new PropValueData(this.SourceLastModifiedTimestampPtag, fm.SourceFolder.FolderRec.LastModifyTimestamp)); if (fm.SourceFolder.WKFType != WellKnownFolderType.None) { list.Add(new PropValueData(this.SourceWKFTypePtag, (int)fm.SourceFolder.WKFType)); } using (IDestinationFolder folder = destMailbox.GetFolder(array)) { if (folder != null) { folder.SetProps(list.ToArray()); } else { MrsTracer.Service.Warning("Something just deleted newly created folder from under us. Ignoring.", new object[0]); } } if (fm.SourceFolder.WKFType != WellKnownFolderType.None && this.GetWellKnownFolder(fm.SourceFolder.WKFType) == null) { this.SetWellKnownFolder(fm.SourceFolder.WKFType, fm); if (this.RootFolder == this.RootRec && (this.MbxWrapper.Flags & MailboxWrapperFlags.Archive) == (MailboxWrapperFlags)0 && (this.MbxWrapper.Flags & MailboxWrapperFlags.PST) == (MailboxWrapperFlags)0) { this.WriteWellKnownFolderReference(fm.SourceFolder.WKFType, fm.EntryId); } } } }); }); }
public override void CopyFolderProperties(FolderRecWrapper folderRec, ISourceFolder sourceFolder, IDestinationFolder destFolder, FolderRecDataFlags dataToCopy, out bool wasPropertyCopyingSkipped) { base.CopyFolderProperties(folderRec, sourceFolder, destFolder, dataToCopy, out wasPropertyCopyingSkipped); MrsTracer.Service.Debug("Stamping additional properties on the target folder", new object[0]); List <PropValueData> list = new List <PropValueData>(3); list.Add(new PropValueData(this.DestHierarchy.SourceEntryIDPtag, folderRec.EntryId)); list.Add(new PropValueData(this.DestHierarchy.SourceLastModifiedTimestampPtag, folderRec.FolderRec.LastModifyTimestamp)); WellKnownFolderType wellKnownFolderType = WellKnownFolderType.None; if (this.SourceHierarchy != null) { wellKnownFolderType = this.SourceHierarchy.GetWellKnownFolderType(folderRec.EntryId); } if (wellKnownFolderType != WellKnownFolderType.None) { list.Add(new PropValueData(this.DestHierarchy.SourceWKFTypePtag, (int)wellKnownFolderType)); } destFolder.SetProps(list.ToArray()); }
private byte[] CreateAssociatedDumpsterFolder(string sourceFolderName, byte[] replicaListValue, byte[] destinationFolderEntryId) { FolderHierarchy folderHierarchy = base.DestMailboxWrapper.FolderMap as FolderHierarchy; FolderRec folderRec = new FolderRec(); folderRec.ParentId = folderHierarchy.GetWellKnownFolder(WellKnownFolderType.PublicFolderDumpsterRoot).EntryId; folderRec.FolderName = PublicFolderCOWSession.GenerateUniqueFolderName(sourceFolderName); folderRec.FolderType = FolderType.Generic; byte[] array; base.DestMailbox.CreateFolder(folderRec, CreateFolderFlags.FailIfExists, out array); using (IDestinationFolder folder = base.DestMailbox.GetFolder(array)) { folder.SetProps(new PropValueData[] { new PropValueData(PropTag.ReplicaList, replicaListValue), new PropValueData(PropTag.IpmWasteBasketEntryId, destinationFolderEntryId), new PropValueData(PropTag.TimeInServer, 64) }); } return(array); }
private void WriteWellKnownFolderReferenceToFolder(WellKnownFolderType targetFolderType, WellKnownFolderType wkfType, PropTagFolderMapping ptfm, byte[] folderId) { FolderMapping wellKnownFolder = this.GetWellKnownFolder(targetFolderType); if (wellKnownFolder == null && targetFolderType == WellKnownFolderType.NonIpmSubtree) { wellKnownFolder = this.GetWellKnownFolder(WellKnownFolderType.Root); } if (wellKnownFolder == null) { MrsTracer.Service.Warning("There's no {0} in the target mailbox, not writing WKF reference for {1}", new object[] { targetFolderType, wkfType }); } IDestinationMailbox destinationMailbox = this.MbxWrapper.Mailbox as IDestinationMailbox; using (IDestinationFolder folder = destinationMailbox.GetFolder(wellKnownFolder.EntryId)) { if (folder == null) { MrsTracer.Service.Error("{0} disappeared??? Not writing WKF reference for {1}", new object[] { targetFolderType, wkfType }); } else { this.WriteEntryIdReference(ptfm, folderId, (PropTag[] pta) => folder.GetProps(pta), delegate(PropValueData[] pvda) { folder.SetProps(pvda); }); } } }
private void CreateDumpsterFoldersForWellKnownFolders() { FolderHierarchy folderHierarchy = base.DestMailboxWrapper.FolderMap as FolderHierarchy; foreach (FolderMapping folderMapping in new List <FolderMapping>(8) { folderHierarchy.GetWellKnownFolder(WellKnownFolderType.Root), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.IpmSubtree), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.NonIpmSubtree), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.EFormsRegistry), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.PublicFolderDumpsterRoot), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.PublicFolderTombstonesRoot), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.PublicFolderAsyncDeleteState), folderHierarchy.GetWellKnownFolder(WellKnownFolderType.PublicFolderInternalSubmission) }) { List <PropValueData> list = new List <PropValueData>(2); using (IDestinationFolder folder = base.DestMailbox.GetFolder(folderMapping.EntryId)) { if (folder == null) { MrsTracer.Service.Error("Something deleted destination folder from under us", new object[0]); throw new UnexpectedErrorPermanentException(-2147221238); } if (!this.AssociatedDumpsterExists(folder)) { byte[] value = this.CreateAssociatedDumpsterFolder(folderMapping.FolderName, ReplicaListProperty.GetBytesFromStringArray(new string[] { base.TargetMailboxGuid.ToString() }), folderMapping.EntryId); list.Add(new PropValueData(PropTag.IpmWasteBasketEntryId, value)); folder.SetProps(list.ToArray()); } } } }
public override void CopyFolderProperties(FolderRecWrapper sourceFolderRecWrapper, ISourceFolder sourceFolder, IDestinationFolder destFolder, FolderRecDataFlags dataToCopy, out bool wasPropertyCopyingSkipped) { Guid empty = Guid.Empty; bool isRoot = base.IsRoot; bool flag = false; wasPropertyCopyingSkipped = false; FolderMapping folderMapping = sourceFolderRecWrapper as FolderMapping; while (folderMapping.WKFType != WellKnownFolderType.Root) { if (folderMapping.IsLegacyPublicFolder) { return; } folderMapping = (folderMapping.Parent as FolderMapping); } if (destFolder == null) { if (!isRoot || ((FolderMapping)sourceFolderRecWrapper).IsSystemPublicFolder) { MrsTracer.Service.Debug("Skipping final property copying for \"{0}\" folder since it's contents don't reside in this mailbox", new object[] { sourceFolderRecWrapper.FullFolderName }); return; } throw new FolderCopyFailedPermanentException(sourceFolderRecWrapper.FullFolderName); } else { PropValueData[] props = destFolder.GetProps(new PropTag[] { PropTag.ReplicaList, PropTag.IpmWasteBasketEntryId }); IDataConverter <PropValue, PropValueData> dataConverter = new PropValueConverter(); PropValue nativeRepresentation = dataConverter.GetNativeRepresentation(props[0]); byte[] array = nativeRepresentation.Value as byte[]; if (!nativeRepresentation.IsNull() && !nativeRepresentation.IsError() && array != null) { StorePropertyDefinition replicaList = CoreFolderSchema.ReplicaList; string[] stringArrayFromBytes = ReplicaListProperty.GetStringArrayFromBytes(array); if (stringArrayFromBytes.Length > 0 && GuidHelper.TryParseGuid(stringArrayFromBytes[0], out empty)) { flag = (empty == base.TargetMailboxGuid); } } FolderStateSnapshot folderStateSnapshot = base.ICSSyncState[sourceFolderRecWrapper.EntryId]; FolderState state = folderStateSnapshot.State; if (sourceFolder.GetFolderRec(this.GetAdditionalFolderPtags(), GetFolderRecFlags.None).IsGhosted) { folderStateSnapshot.State |= FolderState.IsGhosted; } else { folderStateSnapshot.State &= ~FolderState.IsGhosted; } if (state != folderStateSnapshot.State) { base.SaveICSSyncState(false); } if (!isRoot && !flag) { return; } List <PropValueData> list = new List <PropValueData>(2); bool flag2 = false; if (flag) { PropValue nativeRepresentation2 = dataConverter.GetNativeRepresentation(sourceFolder.GetProps(new PropTag[] { PropTag.PfProxy })[0]); if (!nativeRepresentation2.IsNull() && !nativeRepresentation2.IsError()) { byte[] array2 = nativeRepresentation2.Value as byte[]; if (array2 != null && array2.Length == 16 && new Guid(array2) != Guid.Empty) { Guid a = Guid.Empty; bool flag3 = base.Flags.HasFlag(MailboxCopierFlags.CrossOrg); if (flag3) { a = destFolder.LinkMailPublicFolder(LinkMailPublicFolderFlags.EntryId, sourceFolderRecWrapper.EntryId); } else { a = destFolder.LinkMailPublicFolder(LinkMailPublicFolderFlags.ObjectGuid, array2); } if (a != Guid.Empty) { list.Add(new PropValueData(PropTag.PfProxy, a.ToByteArray())); list.Add(new PropValueData(PropTag.PfProxyRequired, true)); flag2 = true; } else { base.Report.Append(new ReportEntry(MrsStrings.ReportFailedToLinkADPublicFolder(sourceFolderRecWrapper.FullFolderName, BitConverter.ToString(array2), BitConverter.ToString(sourceFolderRecWrapper.EntryId)), ReportEntryType.Warning)); } } } } if (!flag2) { list.Add(new PropValueData(PropTag.PfProxy, Guid.Empty.ToByteArray())); list.Add(new PropValueData(PropTag.PfProxyRequired, false)); } List <PropValueData> list2 = new List <PropValueData>(9); if (isRoot) { if (!flag) { dataToCopy &= (FolderRecDataFlags.SecurityDescriptors | FolderRecDataFlags.FolderAcls | FolderRecDataFlags.ExtendedAclInformation); } list2.AddRange(list); } else { byte[] sessionSpecificEntryId = this.hierarchyMailbox.GetSessionSpecificEntryId(sourceFolderRecWrapper.EntryId); using (IDestinationFolder folder = this.hierarchyMailbox.GetFolder(sessionSpecificEntryId)) { if (folder == null) { MrsTracer.Service.Error("Something deleted destination hierarchy folder from under us", new object[0]); throw new UnexpectedErrorPermanentException(-2147221238); } if (list.Count > 0) { folder.SetProps(list.ToArray()); } } } base.CopyFolderProperties(sourceFolderRecWrapper, sourceFolder, destFolder, dataToCopy, out wasPropertyCopyingSkipped); PropTag[] pta = new PropTag[] { PropTag.DisablePeruserRead, PropTag.OverallAgeLimit, PropTag.RetentionAgeLimit, PropTag.PfQuotaStyle, PropTag.PfOverHardQuotaLimit, PropTag.PfStorageQuota, PropTag.PfMsgSizeLimit }; foreach (PropValueData propValueData in sourceFolder.GetProps(pta)) { PropValue nativeRepresentation3 = dataConverter.GetNativeRepresentation(propValueData); if (!nativeRepresentation3.IsNull() && !nativeRepresentation3.IsError()) { if (propValueData.PropTag == 1721303043 && (int)propValueData.Value > 0) { propValueData.Value = (int)EnhancedTimeSpan.FromDays((double)((int)propValueData.Value)).TotalSeconds; } list2.Add(propValueData); } } if (list2.Count > 0) { destFolder.SetProps(list2.ToArray()); } return; } }
public override void CreateFolder(FolderMap.EnumFolderContext context, FolderRecWrapper sourceFolderRecWrapper, CreateFolderFlags createFolderFlags, out byte[] newFolderEntryId) { if (sourceFolderRecWrapper.IsInternalAccess) { throw new InternalAccessFolderCreationIsNotSupportedException(); } newFolderEntryId = null; FolderMapping folderMapping = sourceFolderRecWrapper as FolderMapping; FolderHierarchy folderHierarchy = base.DestMailboxWrapper.FolderMap as FolderHierarchy; byte[] sessionSpecificEntryId = base.DestMailbox.GetSessionSpecificEntryId(folderMapping.EntryId); FolderMapping folderMapping2 = folderMapping.Parent as FolderMapping; bool isRoot = base.IsRoot; byte[] parentId; switch (folderMapping2.WKFType) { case WellKnownFolderType.Root: case WellKnownFolderType.NonIpmSubtree: case WellKnownFolderType.IpmSubtree: case WellKnownFolderType.EFormsRegistry: parentId = folderHierarchy.GetWellKnownFolder(folderMapping2.WKFType).EntryId; break; default: if (isRoot || this.ShouldCreateUnderParentInSecondary()) { parentId = base.DestMailbox.GetSessionSpecificEntryId(folderMapping.ParentId); } else { parentId = folderHierarchy.GetWellKnownFolder(WellKnownFolderType.IpmSubtree).EntryId; } break; } byte[] entryId = folderMapping.FolderRec.EntryId; byte[] parentId2 = folderMapping.FolderRec.ParentId; folderMapping.FolderRec.EntryId = sessionSpecificEntryId; folderMapping.FolderRec.ParentId = parentId; base.DestMailbox.CreateFolder(folderMapping.FolderRec, createFolderFlags, out newFolderEntryId); folderMapping.FolderRec.EntryId = entryId; folderMapping.FolderRec.ParentId = parentId2; List <PropValueData> list = new List <PropValueData>(2); Guid contentMailboxGuid = this.GetContentMailboxGuid(sourceFolderRecWrapper); StorePropertyDefinition replicaList = CoreFolderSchema.ReplicaList; byte[] bytesFromStringArray = ReplicaListProperty.GetBytesFromStringArray(new string[] { contentMailboxGuid.ToString() }); list.Add(new PropValueData(PropTag.ReplicaList, bytesFromStringArray)); using (IDestinationFolder folder = base.DestMailbox.GetFolder(sessionSpecificEntryId)) { if (folder == null) { MrsTracer.Service.Error("Something deleted destination folder from under us", new object[0]); throw new UnexpectedErrorPermanentException(-2147221238); } if (isRoot && !this.AssociatedDumpsterExists(folder)) { byte[] value = this.CreateAssociatedDumpsterFolder(folderMapping.FolderName, bytesFromStringArray, sessionSpecificEntryId); list.Add(new PropValueData(PropTag.IpmWasteBasketEntryId, value)); } folder.SetProps(list.ToArray()); } }
private IFolderProxy CreateFolder(FolderRec folder) { IFolderProxy result = null; bool flag; folder.EntryId = this.syncContext.MapSourceToDestinationFolderId(folder.EntryId, out flag); folder.ParentId = this.syncContext.MapSourceToDestinationFolderId(folder.ParentId, out flag); using (DisposeGuard disposeGuard = default(DisposeGuard)) { IDestinationFolder folder2 = this.destinationMailbox.GetFolder(folder.EntryId); if (folder2 != null) { disposeGuard.Add <IDestinationFolder>(folder2); folder2.SetProps(CommonUtils.PropertiesToDelete); FolderRec folderRec = folder2.GetFolderRec(null, GetFolderRecFlags.None); if (!CommonUtils.IsSameEntryId(folderRec.ParentId, folder.ParentId)) { try { this.destinationMailbox.MoveFolder(folderRec.EntryId, folderRec.ParentId, folder.ParentId); } catch (ObjectNotFoundException arg) { PublicFolderHierarchyProxyPool.Tracer.TraceWarning <FolderRec, FolderRec, ObjectNotFoundException>((long)this.GetHashCode(), "ObjectNotFoundException caught during MoveFolder. Calling to FixParentChain before reattempting the folder move. SourceFolder={0}. DestinationFolder={1}. Exception={2}", folder, folderRec, arg); this.FixParentChain(folder); this.destinationMailbox.MoveFolder(folderRec.EntryId, folderRec.ParentId, folder.ParentId); } } result = base.WrappedObject.GetFolderProxy(folder.EntryId); PublicFolderHierarchyProxyPool.Tracer.TraceDebug <FolderRec>((long)this.GetHashCode(), "Folder updated: {0}", folder); this.syncContext.Logger.LogFolderUpdated(folder.EntryId); } else { try { result = base.WrappedObject.CreateFolder(folder); } catch (ObjectNotFoundException arg2) { PublicFolderHierarchyProxyPool.Tracer.TraceWarning <FolderRec, ObjectNotFoundException>((long)this.GetHashCode(), "ObjectNotFoundException caught during CreateFolder. Calling to FixParentChain before reattempting the folder creation. Folder={0}. Exception={1}", folder, arg2); this.FixParentChain(folder); result = base.WrappedObject.CreateFolder(folder); } folder2 = this.destinationMailbox.GetFolder(folder.EntryId); disposeGuard.Add <IDestinationFolder>(folder2); PublicFolderHierarchyProxyPool.Tracer.TraceDebug <FolderRec>((long)this.GetHashCode(), "Folder created: {0}", folder); this.syncContext.Logger.LogFolderCreated(folder.EntryId); } byte[] dumpsterEntryIdFromFolderRec = PublicFolderHierarchyProxyPool.GetDumpsterEntryIdFromFolderRec(folder); if (dumpsterEntryIdFromFolderRec != null) { bool flag2; byte[] value = this.syncContext.MapSourceToDestinationFolderId(dumpsterEntryIdFromFolderRec, out flag2); folder2.SetProps(new PropValueData[] { new PropValueData(PropTag.IpmWasteBasketEntryId, value) }); } } return(result); }