public bool CompareRootFolders() { ISourceFolder folder = base.SourceMailbox.GetFolder(null); if (folder == null) { throw new RootFolderNotFoundPermananentException(); } FolderRec folderRec; using (folder) { folderRec = folder.GetFolderRec(null, GetFolderRecFlags.None); } IDestinationFolder folder2 = base.DestMailbox.GetFolder(null); if (folder2 == null) { throw new RootFolderNotFoundPermananentException(); } FolderRec folderRec2; using (folder2) { folderRec2 = folder2.GetFolderRec(null, GetFolderRecFlags.None); } if (!CommonUtils.IsSameEntryId(folderRec.EntryId, folderRec2.EntryId)) { MrsTracer.Service.Warning("Root folder IDs don't match on source and destination mailboxes. Restarting the move.", new object[0]); return(false); } return(true); }
public override FolderMap GetSourceFolderMap(GetFolderMapFlags flags) { base.SourceMailboxWrapper.LoadFolderMap(flags, delegate { List <FolderRecWrapper> list = new List <FolderRecWrapper>(this.hierarchyFolderEntryIds.Count); foreach (byte[] entryId in this.hierarchyFolderEntryIds) { byte[] sessionSpecificEntryId = base.SourceMailbox.GetSessionSpecificEntryId(entryId); using (ISourceFolder folder = base.SourceMailbox.GetFolder(sessionSpecificEntryId)) { list.Add(new FolderRecWrapper(folder.GetFolderRec(null, GetFolderRecFlags.None))); } } return(new PublicFolderMap(list)); }); return(base.SourceMailboxWrapper.FolderMap); }
protected override void BeforeDataCopy() { base.MailboxMerger.SourceHierarchy.EnumerateFolderHierarchy(EnumHierarchyFlags.NormalFolders | EnumHierarchyFlags.RootFolder, delegate(FolderRecWrapper folderRec, FolderMap.EnumFolderContext context) { FolderMapping folderMapping = (FolderMapping)folderRec; if (!folderMapping.IsIncluded) { return; } using (ISourceFolder folder = base.MailboxMerger.SourceMailbox.GetFolder(folderMapping.EntryId)) { if (folder != null) { FolderRec folderRec2 = folder.GetFolderRec(base.MailboxMerger.GetAdditionalFolderPtags(), GetFolderRecFlags.None); base.MailboxMerger.CatchupFolder(folderRec2, folder); } } }); base.MailboxMerger.ICSSyncState.ProviderState = base.MailboxMerger.SourceMailbox.GetMailboxSyncState(); base.MailboxMerger.SaveICSSyncState(true); }
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; } }
protected override void CatchupFolderHierarchy() { if (!this.PrimaryHierarchyMbxWrapper.Mailbox.IsConnected()) { this.PrimaryHierarchyMbxWrapper.Mailbox.Connect(MailboxConnectFlags.None); } FolderRecDataFlags folderRecDataFlags = FolderRecDataFlags.SearchCriteria; if (!base.CachedRequestJob.SkipFolderPromotedProperties) { folderRecDataFlags |= FolderRecDataFlags.PromotedProperties; } if (!base.CachedRequestJob.SkipFolderViews) { folderRecDataFlags |= FolderRecDataFlags.Views; } if (!base.CachedRequestJob.SkipFolderRestrictions) { folderRecDataFlags |= FolderRecDataFlags.Restrictions; } List <WellKnownFolder> list = this.folderMover.SourceMailbox.DiscoverWellKnownFolders(0); List <WellKnownFolder> destinationWellKnownFolders = this.folderMover.DestMailbox.DiscoverWellKnownFolders(0); foreach (byte[] array in this.foldersToMove) { using (IFolder folder = ((ISourceMailbox)this.PrimaryHierarchyMbxWrapper.Mailbox).GetFolder(array)) { using (IDestinationFolder folder2 = this.folderMover.DestMailbox.GetFolder(this.folderMover.DestMailbox.GetSessionSpecificEntryId(array))) { if (folder2 == null) { if (folder == null) { MrsTracer.Service.Debug("Folder {0} unavailable at both source and destination mailbox during catchup", new object[] { HexConverter.ByteArrayToHexString(array) }); } else { List <FolderRecWrapper> list2 = new List <FolderRecWrapper>(); byte[] entryId = array; for (;;) { using (ISourceFolder folder3 = this.folderMover.SourceMailbox.GetFolder(entryId)) { if (folder3 != null) { FolderRecWrapper folderRecWrapper = new FolderRecWrapper(folder3.GetFolderRec(null, GetFolderRecFlags.None)); if (folderRecWrapper.ParentId != null) { list2.Insert(0, folderRecWrapper); bool flag = false; foreach (WellKnownFolder wellKnownFolder in list) { if (CommonUtils.IsSameEntryId(wellKnownFolder.EntryId, folderRecWrapper.ParentId)) { flag = true; break; } } if (!flag) { entryId = folderRecWrapper.ParentId; continue; } } } } break; } foreach (FolderRecWrapper folderRecWrapper2 in list2) { byte[] entryId2 = folderRecWrapper2.FolderRec.EntryId; byte[] parentId = folderRecWrapper2.FolderRec.ParentId; byte[] sessionSpecificEntryId = this.folderMover.DestMailbox.GetSessionSpecificEntryId(entryId2); bool flag2 = false; byte[] destinationFolderIdFromSourceFolderId = AuxFolderMoveJob.GetDestinationFolderIdFromSourceFolderId(list, destinationWellKnownFolders, this.folderMover.DestMailbox, parentId, out flag2); using (IDestinationFolder folder4 = this.folderMover.DestMailbox.GetFolder(sessionSpecificEntryId)) { if (folder4 == null) { using (ISourceFolder folder5 = this.folderMover.SourceMailbox.GetFolder(entryId2)) { if (folder5 == null) { MrsTracer.Service.Warning("Source folder '{0}' {1} disappeared, skipping", new object[] { folderRecWrapper2.FolderName, folderRecWrapper2.EntryId }); break; } folderRecWrapper2.EnsureDataLoaded(folder5, folderRecDataFlags, this.folderMover); this.folderMover.TranslateFolderData(folderRecWrapper2); CreateFolderFlags createFolderFlags = CreateFolderFlags.None; folderRecWrapper2.FolderRec.EntryId = sessionSpecificEntryId; folderRecWrapper2.FolderRec.ParentId = destinationFolderIdFromSourceFolderId; byte[] array2; this.folderMover.CreateFolder(null, folderRecWrapper2, createFolderFlags, out array2); folderRecWrapper2.FolderRec.EntryId = entryId2; folderRecWrapper2.FolderRec.ParentId = parentId; } } } } } } } } } base.SyncStage = SyncStage.CreatingInitialSyncCheckpoint; base.OverallProgress = 15; base.TimeTracker.CurrentState = RequestState.CreatingInitialSyncCheckpoint; base.SaveState(SaveStateFlags.Regular, delegate(TransactionalRequestJob moveRequest) { moveRequest.RestartFromScratch = false; }); base.ScheduleWorkItem(new Action(base.CatchupFolders), WorkloadType.Unknown); }
public static void LookupBadMessagesInMailbox(ISourceMailbox mailbox, List <MessageRec> messages, out EntryIdMap <MessageRec> lookedUpMsgs, out EntryIdMap <FolderRec> folderRecs) { EntryIdMap <EntryIdMap <MessageRec> > entryIdMap = new EntryIdMap <EntryIdMap <MessageRec> >(); folderRecs = new EntryIdMap <FolderRec>(); lookedUpMsgs = new EntryIdMap <MessageRec>(); foreach (MessageRec messageRec in messages) { EntryIdMap <MessageRec> entryIdMap2; if (!entryIdMap.TryGetValue(messageRec.FolderId, out entryIdMap2)) { entryIdMap2 = new EntryIdMap <MessageRec>(); entryIdMap.Add(messageRec.FolderId, entryIdMap2); } entryIdMap2[messageRec.EntryId] = null; } MrsTracer.Common.Debug("Looking up {0} messages in {1} folders.", new object[] { messages.Count, entryIdMap.Count }); foreach (KeyValuePair <byte[], EntryIdMap <MessageRec> > keyValuePair in entryIdMap) { using (ISourceFolder folder = mailbox.GetFolder(keyValuePair.Key)) { if (folder == null) { MrsTracer.Common.Warning("Folder {0} disappeared.", new object[] { TraceUtils.DumpEntryId(keyValuePair.Key) }); } else { FolderRec folderRec = folder.GetFolderRec(null, GetFolderRecFlags.None); folderRecs[folderRec.EntryId] = folderRec; EntryIdMap <MessageRec> value = keyValuePair.Value; MrsTracer.Common.Debug("Looking up {0} messages in folder '{1}'.", new object[] { value.Count, folderRec.FolderName }); int num = 0; if (mailbox.IsCapabilitySupported(MRSProxyCapabilities.SimpleExport)) { List <byte[]> keysToLookup = new List <byte[]>(value.Keys); List <MessageRec> list = folder.LookupMessages(PropTag.EntryId, keysToLookup, BadMessageRec.BadItemPtags); if (list == null) { goto IL_230; } using (List <MessageRec> .Enumerator enumerator3 = list.GetEnumerator()) { while (enumerator3.MoveNext()) { MessageRec messageRec2 = enumerator3.Current; lookedUpMsgs[messageRec2.EntryId] = messageRec2; num++; } goto IL_230; } } List <MessageRec> list2 = folder.EnumerateMessages(EnumerateMessagesFlags.RegularMessages, BadMessageRec.BadItemPtags); foreach (MessageRec messageRec3 in list2) { if (value.ContainsKey(messageRec3.EntryId)) { lookedUpMsgs[messageRec3.EntryId] = messageRec3; num++; } } IL_230: MrsTracer.Common.Debug("Found {0} messages.", new object[] { num }); } } } MrsTracer.Common.Debug("Looked up {0} messages.", new object[] { lookedUpMsgs.Count }); }