public static FolderHierarchyChangeDetector.MailboxChangesManifest RunICSManifestSync(bool catchup, FolderHierarchyChangeDetector.SyncHierarchyManifestState hierState, MailboxSession mailboxSession, ISyncLogger syncLogger = null) { if (syncLogger == null) { syncLogger = TracingLogger.Singleton; } syncLogger.TraceDebug <SmtpAddress, bool>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Checking for folder hierarhcy changes for Mailbox: {0}. Catchup? {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, catchup); MapiStore _ContainedMapiStore = mailboxSession.__ContainedMapiStore; FolderHierarchyChangeDetector.MailboxChangesManifest mailboxChangesManifest = new FolderHierarchyChangeDetector.MailboxChangesManifest(); FolderHierarchyChangeDetector.ManifestHierarchyCallback iMapiManifestCallback = new FolderHierarchyChangeDetector.ManifestHierarchyCallback(catchup, mailboxChangesManifest); try { using (MapiFolder ipmSubtreeFolder = _ContainedMapiStore.GetIpmSubtreeFolder()) { SyncConfigFlags syncConfigFlags = SyncConfigFlags.ManifestHierReturnDeletedEntryIds; int serverVersion = mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion; if ((serverVersion >= Server.E14MinVersion && serverVersion < Server.E15MinVersion) || (long)serverVersion >= FolderHierarchyChangeDetector.E15MinVersionSupportsOnlySpecifiedPropsForHierarchy) { syncConfigFlags |= SyncConfigFlags.OnlySpecifiedProps; } using (MapiHierarchyManifestEx mapiHierarchyManifestEx = ipmSubtreeFolder.CreateExportHierarchyManifestEx(syncConfigFlags, hierState.IdsetGiven, hierState.CnsetSeen, iMapiManifestCallback, FolderHierarchyChangeDetector.PropsToFetch, null)) { while (mapiHierarchyManifestEx.Synchronize() != ManifestStatus.Done) { } byte[] idSetGiven; byte[] cnetSeen; mapiHierarchyManifestEx.GetState(out idSetGiven, out cnetSeen); syncLogger.TraceDebug <SmtpAddress, int, int>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Updating ICS state for mailbox: '{0}'. Change Count: {1}, Delete Count: {2}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, mailboxChangesManifest.ChangedFolders.Count, mailboxChangesManifest.DeletedFolders.Count); hierState.Update(idSetGiven, cnetSeen); } } } catch (MapiPermanentException arg) { syncLogger.TraceDebug <SmtpAddress, MapiPermanentException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiPermanentException when determining folder ICS changes for mailbox: {0}. Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg); return(null); } catch (MapiRetryableException arg2) { syncLogger.TraceDebug <SmtpAddress, MapiRetryableException>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderHierarchyChangeDetector.RunICSManifestSync] Caught MapiRetryableException when determining folder ICS changes for mailbox: {0}. Exception: {1}", mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress, arg2); return(null); } return(mailboxChangesManifest); }