public static MapiFolder OpenFolderUnderRoot(MapiStore mailbox, string folderName, bool createIfMissing) { MapiFolder result; using (MapiFolder nonIpmSubtreeFolder = mailbox.GetNonIpmSubtreeFolder()) { MapiFolder mapiFolder = null; try { mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName); } catch (MapiExceptionNotFound) { } if (mapiFolder == null && createIfMissing) { MrsTracer.Common.Debug("Folder '{0}' does not exist, creating it.", new object[] { folderName }); try { mapiFolder = nonIpmSubtreeFolder.CreateFolder(folderName, null, false); MrsTracer.Common.Debug("Created '{0}' folder.", new object[] { folderName }); } catch (MapiExceptionCollision) { MrsTracer.Common.Debug("Somebody beat us to creating the folder. Will attempt to open it.", new object[0]); } if (mapiFolder == null) { mapiFolder = nonIpmSubtreeFolder.OpenSubFolderByName(folderName); MrsTracer.Common.Debug("Opened '{0}' folder.", new object[] { folderName }); } } result = mapiFolder; } return(result); }
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); } } } }