Exemplo n.º 1
0
        private static string GetFolderLegacyDistinguishedName(MapiEntryId abEntryId, MapiFolder folder)
        {
            string result;

            try
            {
                if (null == abEntryId)
                {
                    if (folder == null)
                    {
                        throw new ArgumentNullException("folder");
                    }
                    PropValue prop = folder.GetProp(PropTag.AddressBookEntryId);
                    if (PropType.Error == prop.PropType)
                    {
                        return(null);
                    }
                    abEntryId = new MapiEntryId(prop.GetBytes());
                }
                result = MapiMessageStoreSession.GetLegacyDNFromAddressBookEntryId(abEntryId);
            }
            catch (MapiPermanentException)
            {
                result = null;
            }
            catch (MapiRetryableException)
            {
                result = null;
            }
            return(result);
        }
Exemplo n.º 2
0
        public StoreId CreateFolder(string folderName, string folderDescription, StoreId parentFolderId, CreateMode mode, out Guid contentMailboxGuid)
        {
            StoreId result;

            using (PublicFolderConnectionLimitsTracker.Instance.GetToken(this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn))
            {
                StoreSession storeSession = null;
                object       thisObject   = null;
                bool         flag         = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    using (MapiStore hierarchyStore = this.GetHierarchyStore())
                    {
                        using (MapiFolder mapiFolder = (MapiFolder)hierarchyStore.OpenEntry(this.GetDestinationSpecificEntryId(hierarchyStore, parentFolderId)))
                        {
                            using (MapiFolder mapiFolder2 = mapiFolder.CreateFolder(folderName, folderDescription, mode == CreateMode.OpenIfExists))
                            {
                                contentMailboxGuid = RPCPrimaryHierarchyProvider.GetMailboxGuidFromPersonalizedLegacyDN(mapiFolder2.GetReplicaServers()[0]);
                                result             = StoreObjectId.FromProviderSpecificId(mapiFolder2.GetProp(PropTag.EntryId).GetBytes(), StoreObjectType.Folder);
                            }
                        }
                    }
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        internal static MailboxStoreObject Bind(StoreSession session, MapiStore mapiStore, ICollection <PropertyDefinition> requestedProperties, bool getMappingSignature, bool overridePropertyList)
        {
            ICollection <PropertyDefinition> collection = InternalSchema.Combine <PropertyDefinition>(overridePropertyList ? new PropertyTagPropertyDefinition[]
            {
                MailboxSchema.MailboxType,
                MailboxSchema.MailboxTypeDetail
            } : MailboxSchema.Instance.AutoloadProperties, requestedProperties);
            PersistablePropertyBag persistablePropertyBag = null;
            CoreMailboxObject      coreMailboxObject      = null;
            MailboxStoreObject     mailboxStoreObject     = null;
            bool flag = false;
            MailboxStoreObject result;

            try
            {
                byte[] array = null;
                if (getMappingSignature)
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                        {
                            array = (rootFolder.GetProp(PropTag.MappingSignature).Value as byte[]);
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                }
                if (array != null)
                {
                    session.MappingSignature = Convert.ToBase64String(array);
                }
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiStore, collection);
                coreMailboxObject      = new CoreMailboxObject(session, persistablePropertyBag, null, null, collection);
                mailboxStoreObject     = new MailboxStoreObject(coreMailboxObject);
                flag   = true;
                result = mailboxStoreObject;
            }
            finally
            {
                if (!flag)
                {
                    if (mailboxStoreObject != null)
                    {
                        mailboxStoreObject.Dispose();
                        mailboxStoreObject = null;
                    }
                    if (coreMailboxObject != null)
                    {
                        coreMailboxObject.Dispose();
                        coreMailboxObject = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        private static MapiFolderPath GetFolderPath(MapiEntryId folderEntryId, MapiFolder mapiFolder, MapiStore mapiStore)
        {
            MapiFolderPath result;

            try
            {
                if (null == folderEntryId)
                {
                    if (mapiFolder == null)
                    {
                        throw new ArgumentNullException("mapiFolder");
                    }
                    PropValue prop = mapiFolder.GetProp(PropTag.EntryId);
                    if (PropType.Error == prop.PropType)
                    {
                        return(null);
                    }
                    folderEntryId = new MapiEntryId(prop.GetBytes());
                }
                if (mapiStore == null)
                {
                    throw new ArgumentNullException("mapiStore");
                }
                MapiEntryId operand;
                using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                {
                    operand = new MapiEntryId(rootFolder.GetProp(PropTag.EntryId).GetBytes());
                }
                MapiEntryId    operand2         = new MapiEntryId(mapiStore.GetIpmSubtreeFolderEntryId());
                MapiEntryId    operand3         = new MapiEntryId(mapiStore.GetNonIpmSubtreeFolderEntryId());
                MapiFolderPath mapiFolderPath   = null;
                MapiEntryId    mapiEntryId      = folderEntryId;
                MapiEntryId    mapiEntryId2     = null;
                string         parentFolderName = null;
                while (!(operand2 == mapiEntryId))
                {
                    if (operand3 == mapiEntryId || operand == mapiEntryId)
                    {
                        mapiFolderPath = MapiFolderPath.GenerateFolderPath("NON_IPM_SUBTREE", mapiFolderPath, true);
                    }
                    else
                    {
                        using (MapiFolder mapiFolder2 = (MapiFolder)mapiStore.OpenEntry((byte[])mapiEntryId))
                        {
                            PropValue[] props = mapiFolder2.GetProps(new PropTag[]
                            {
                                PropTag.ParentEntryId,
                                PropTag.DisplayName
                            });
                            if (PropType.Error == props[0].PropType || PropType.Error == props[1].PropType)
                            {
                                return(null);
                            }
                            mapiEntryId2     = new MapiEntryId(props[0].GetBytes());
                            parentFolderName = props[1].GetString();
                        }
                        if (!(mapiEntryId2 == mapiEntryId))
                        {
                            mapiFolderPath = MapiFolderPath.GenerateFolderPath(parentFolderName, mapiFolderPath, false);
                            mapiEntryId    = mapiEntryId2;
                            continue;
                        }
                    }
IL_19C:
                    return(mapiFolderPath);
                }
                mapiFolderPath = MapiFolderPath.GenerateFolderPath("IPM_SUBTREE", mapiFolderPath, true);
                goto IL_19C;
            }
            catch (MapiPermanentException)
            {
                result = null;
            }
            catch (MapiRetryableException)
            {
                result = null;
            }
            return(result);
        }
Exemplo n.º 5
0
        private static MapiFolder RetrieveParentMapiFolder(MapiStore store, FolderId identity, ref MapiFolder folder)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            Folder.CheckRequirementsOnIdentityToContinue(identity);
            MapiFolder mapiFolder = null;
            bool       flag       = false;
            bool       flag2      = false;
            MapiFolder result;

            try
            {
                byte[] array = null;
                if (null == identity.MapiEntryId)
                {
                    if (identity.LegacyDistinguishedName != null)
                    {
                        array = store.GetFolderEntryId(identity.LegacyDistinguishedName);
                    }
                }
                else
                {
                    array = (byte[])identity.MapiEntryId;
                }
                if (array != null)
                {
                    if (folder == null)
                    {
                        folder = (MapiFolder)store.OpenEntry(array);
                        flag   = true;
                    }
                    mapiFolder = (MapiFolder)store.OpenEntry(folder.GetProp(PropTag.ParentEntryId).GetBytes());
                }
                else if (null != identity.MapiFolderPath)
                {
                    MapiFolderPath parent = identity.MapiFolderPath.Parent;
                    if (null == parent)
                    {
                        mapiFolder = store.GetRootFolder();
                    }
                    else
                    {
                        mapiFolder = Folder.GetFolderByPath(store, parent);
                    }
                }
                flag2  = true;
                result = mapiFolder;
            }
            finally
            {
                if (!flag2)
                {
                    if (flag && folder != null)
                    {
                        folder.Dispose();
                        folder = null;
                    }
                    if (mapiFolder != null)
                    {
                        mapiFolder.Dispose();
                        mapiFolder = null;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity, ref MapiFolder parent, Folder.IdentityConstructor idCtor, out FolderId realId)
        {
            realId = null;
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            Folder.CheckRequirementsOnIdentityToContinue(identity);
            MapiFolder mapiFolder = null;
            bool       flag       = false;
            bool       flag2      = false;
            MapiFolder result;

            try
            {
                byte[]         array      = null;
                MapiEntryId    entryId    = null;
                MapiFolderPath folderPath = null;
                string         legacyDn   = null;
                if (null == identity.MapiEntryId)
                {
                    if (identity.LegacyDistinguishedName != null)
                    {
                        legacyDn = identity.LegacyDistinguishedName;
                        array    = store.GetFolderEntryId(identity.LegacyDistinguishedName);
                    }
                }
                else
                {
                    array = (byte[])identity.MapiEntryId;
                }
                if (array != null)
                {
                    entryId    = new MapiEntryId(array);
                    mapiFolder = (MapiFolder)store.OpenEntry(array);
                    if (parent == null)
                    {
                        parent = (MapiFolder)store.OpenEntry(mapiFolder.GetProp(PropTag.ParentEntryId).GetBytes());
                        flag   = true;
                    }
                }
                else if (null != identity.MapiFolderPath)
                {
                    folderPath = identity.MapiFolderPath;
                    if (parent == null)
                    {
                        mapiFolder = Folder.GetFolderByPath(store, identity.MapiFolderPath, out parent);
                        flag       = true;
                    }
                    else
                    {
                        mapiFolder = Folder.GetFolderByPath(store, parent, identity.MapiFolderPath);
                    }
                }
                if (idCtor != null)
                {
                    realId = idCtor(entryId, folderPath, legacyDn);
                }
                flag2  = true;
                result = mapiFolder;
            }
            finally
            {
                if (!flag2)
                {
                    if (mapiFolder != null)
                    {
                        mapiFolder.Dispose();
                        mapiFolder = null;
                    }
                    if (flag && parent != null)
                    {
                        parent.Dispose();
                        parent = null;
                    }
                }
            }
            return(result);
        }