internal static void UpgradeElcFolder(bool userIsOnRetentionPolcyTags, MailboxSession mailboxSession, StoreId folderId, Dictionary <Guid, AdTagData> allAdTags) { using (Folder folder = Folder.Bind(mailboxSession, folderId, ProvisionedFolderReader.ElcFolderProps)) { ElcMailboxHelper.UpgradeElcFolder(userIsOnRetentionPolcyTags, mailboxSession, folder, allAdTags); ProvisionedFolderCreator.SaveELCFolder(folder, false); } }
internal static bool RemoveElcFolder(bool userIsOnRetentionPolcyTags, MailboxSession mailboxSession, StoreId folderId, Dictionary <Guid, AdTagData> allAdTags, out UpgradeStatus status) { status = UpgradeStatus.None; Stack <ElcMailboxHelper.FolderNode> stack = new Stack <ElcMailboxHelper.FolderNode>(50); ElcMailboxHelper.FolderNode folderNode = new ElcMailboxHelper.FolderNode(folderId, null); stack.Push(folderNode); while (stack.Count > 0) { ElcMailboxHelper.FolderNode folderNode2 = stack.Peek(); if (folderNode2.ChildCount == -1) { using (Folder folder = Folder.Bind(mailboxSession, folderNode2.FolderId, ProvisionedFolderReader.ElcFolderProps)) { folderNode2.ChildCount = folder.ItemCount + folder.SubfolderCount; using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, ProvisionedFolderReader.ElcFolderProps)) { for (;;) { object[][] rows = queryResult.GetRows(100); if (rows.Length <= 0) { break; } foreach (object[] array in rows) { stack.Push(new ElcMailboxHelper.FolderNode((VersionedId)array[0], folderNode2)); } } } if (ElcMailboxHelper.IsElcFolder(folder)) { status |= ElcMailboxHelper.UpgradeElcFolder(userIsOnRetentionPolcyTags, mailboxSession, folder, allAdTags); ProvisionedFolderCreator.SaveELCFolder(folder, false); } continue; } } if (folderNode2.ChildCount == 0) { if (folderNode2.Parent != null) { folderNode2.Parent.ChildCount--; } mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[] { folderNode2.FolderId }); } stack.Pop(); } return(folderNode.ChildCount == 0); }
internal VersionedId[] CreateOrganizationalFolders(string[] folderNames) { OptInFolders.< > c__DisplayClass2 CS$ < > 8__locals1 = new OptInFolders.< > c__DisplayClass2(); CS$ < > 8__locals1.folderNames = folderNames; if (CS$ < > 8__locals1.folderNames == null) { throw new ArgumentNullException(); } if (CS$ < > 8__locals1.folderNames.Length == 0) { throw new ArgumentException("The number of input folders cannot be zero."); } if (CS$ < > 8__locals1.folderNames.Length > 1000) { throw new ArgumentException("The number of input folders exceeded allowable limit."); } List <VersionedId> list = new List <VersionedId>(); int folderIndex; for (folderIndex = 0; folderIndex < CS$ < > 8__locals1.folderNames.GetLength(0); folderIndex++) { int length = Array.FindAll <string>(CS$ < > 8__locals1.folderNames, (string matchedFolderName) => string.Compare(CS$ < > 8__locals1.folderNames[folderIndex], matchedFolderName, StringComparison.OrdinalIgnoreCase) == 0).GetLength(0); if (length > 1) { OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Input folder list contains duplicate entry of '{0}'.", CS$ < > 8__locals1.folderNames[folderIndex]); throw new ELCDuplicateFolderNamesArgumentException(CS$ < > 8__locals1.folderNames[folderIndex]); } } this.ConfirmCanActAsOwner(); OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "WindowsPrincipal validation for mailbox '{0}' successful.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()); using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(this.mailboxToAccess, CultureInfo.InvariantCulture, "Client=ELC;Action=Create Managed Folders")) { if (this.budget != null) { mailboxSession.AccountingObject = this.budget; } Folder folder = null; try { List <AdFolderData> adFoldersFromFolderNames = this.GetAdFoldersFromFolderNames(CS$ < > 8__locals1.folderNames); MailboxFolderData mailboxFolderData = null; OptInFolders.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "Need to create '{0}' Managed Custom Folders for mailbox '{1}'.", adFoldersFromFolderNames.Count, this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()); List <MailboxFolderData> list2; ProvisionedFolderReader.GetProvisionedFoldersFromMailbox(mailboxSession, true, out mailboxFolderData, out list2); if (list2 != null && list2.Count != 0) { using (List <AdFolderData> .Enumerator enumerator = adFoldersFromFolderNames.GetEnumerator()) { while (enumerator.MoveNext()) { AdFolderData folderToCreate = enumerator.Current; int num = list2.FindIndex((MailboxFolderData mbxFolder) => mbxFolder.ElcFolderGuid == folderToCreate.Folder.Guid); if (num >= 0) { OptInFolders.Tracer.TraceDebug <string, SmtpAddress>((long)this.GetHashCode(), "Folder '{0}' exists in mailbox '{1}'.", folderToCreate.Folder.FolderName, this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress); throw new ELCOrgFolderExistsException(folderToCreate.Folder.FolderName); } } } } VersionedId versionedId = (mailboxFolderData == null) ? null : mailboxFolderData.Id; if (versionedId == null) { string elcRootUrl = AdFolderReader.GetElcRootUrl(this.budget); folder = ProvisionedFolderCreator.CreateELCRootFolder(mailboxSession, elcRootUrl); if (folder == null) { OptInFolders.Tracer.TraceError <SmtpAddress>((long)this.GetHashCode(), "{0}: Unable to create the ELC root folder in the mailbox.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress); throw new ELCRootFailureException(Strings.descFailedToCreateELCRoot(mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()), null); } versionedId = folder.Id; } if (versionedId == null) { OptInFolders.Tracer.TraceDebug <SmtpAddress>((long)this.GetHashCode(), "Unable to create the Managed Folders root folder in mailbox '{0}'.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress); throw new ELCRootFailureException(Strings.descFailedToCreateELCRoot(this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()), null); } try { if (folder == null) { folder = Folder.Bind(mailboxSession, versionedId); } } catch (ObjectNotFoundException innerException) { OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Failed to bind to the Managed Folders root folder in mailbox '{0}'.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()); throw new ELCRootFailureException(Strings.descCannotBindToElcRootFolder(versionedId.ToString(), this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()), innerException); } foreach (AdFolderData adFolderInfo in adFoldersFromFolderNames) { ProvisionedFolderCreator.CreateOneELCFolderInMailbox(adFolderInfo, mailboxSession, folder); } list = this.GetIdsFromFolderNames(mailboxSession, CS$ < > 8__locals1.folderNames); } finally { if (folder != null) { folder.Dispose(); folder = null; } } } return(list.ToArray()); }
internal static string CreateOneELCFolderInMailbox(AdFolderData adFolderInfo, MailboxSession itemStore, Folder elcRootFolder) { Folder folder = null; ELCFolder folder2 = adFolderInfo.Folder; string text = itemStore.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(); string text2 = (folder2.FolderType == ElcFolderType.ManagedCustomFolder) ? folder2.FolderName : folder2.FolderType.ToString(); string result; try { if (folder2.FolderType != ElcFolderType.ManagedCustomFolder) { ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Need to provision a default folder '{0}' in mailbox '{1}'.", text2, text); try { folder = ElcMailboxHelper.GetDefaultFolder(itemStore, folder2); } catch (ObjectNotFoundException innerException) { ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Default folder '{0}' does not exist in mailbox '{1}'.", text2, text); throw new ELCDefaultFolderNotFoundException(text2, text, innerException); } ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Default folder '{0}' exists in mailbox '{1}' and will be provisioned.", text2, text); result = '/' + ProvisionedFolderCreator.NormalizeFolderName(text2); } else { ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Creating organizational folder '{0}' in mailbox '{1}'.", text2, text); folder = Folder.Create(itemStore, elcRootFolder.Id, StoreObjectType.Folder, folder2.FolderName, CreateMode.OpenIfExists); ProvisionedFolderCreator.SaveELCFolder(folder, true); folder.Load(); result = string.Concat(new object[] { '/', ProvisionedFolderCreator.NormalizeFolderName(elcRootFolder.DisplayName), '/', ProvisionedFolderCreator.NormalizeFolderName(text2) }); } ELCFolderFlags elcfolderFlags = ELCFolderFlags.None; ulong num = folder2.StorageQuota.IsUnlimited ? 0UL : folder2.StorageQuota.Value.ToKB(); if (folder2.FolderType == ElcFolderType.ManagedCustomFolder) { elcfolderFlags = ELCFolderFlags.Provisioned; if (adFolderInfo.LinkedToTemplate) { elcfolderFlags |= ELCFolderFlags.Protected; } if (folder.ItemCount == 0 && !folder.HasSubfolders) { elcfolderFlags |= ELCFolderFlags.TrackFolderSize; } if (num > 0UL) { elcfolderFlags |= ELCFolderFlags.Quota; } } if (folder2.MustDisplayCommentEnabled) { elcfolderFlags |= ELCFolderFlags.MustDisplayComment; } ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.AdminFolderFlags, elcfolderFlags); ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCPolicyIds, folder2.Guid.ToString()); string localizedFolderComment = folder2.GetLocalizedFolderComment(itemStore.MailboxOwner.PreferredCultures); if (!string.IsNullOrEmpty(localizedFolderComment)) { ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCFolderComment, localizedFolderComment); } else { ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCFolderComment, Globals.BlankComment); } if (folder2.FolderType == ElcFolderType.ManagedCustomFolder && num > 0UL) { ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.FolderQuota, (int)num); } ProvisionedFolderCreator.SaveELCFolder(folder, true); if (folder2.FolderType == ElcFolderType.All) { ProvisionedFolderCreator.CreateAllOthersConfigMsg(adFolderInfo.Folder, itemStore); } ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Successfully created/provisioned folder '{0}' in mailbox '{1}'.", text2, text); } finally { if (folder != null) { folder.Dispose(); folder = null; } } return(result); }