示例#1
0
        public static FolderDescriptor Get(IEFolder folder)
        {
            Guard.NullArgument(folder, "folder");
            string entryId = OutlookSession.GetFolderID(folder);
            string storeId = folder.GetBinProp(MAPIConst.PR_STORE_ENTRYID);

            return(Get(new PairIDs(entryId, storeId), folder));
        }
示例#2
0
        public static FolderDescriptor Get(string storeID, IEFolder folder)
        {
            Guard.EmptyStringArgument(storeID, "storeID");
            Guard.NullArgument(folder, "folder");
            string entryID = OutlookSession.GetFolderID(folder);

            return(Get(entryID, storeID, folder));
        }
示例#3
0
        public MailDeletedDescriptor(MAPINtf ntf, string storeId)
        {
            Guard.NullArgument(ntf, "ntf");
            Guard.NullArgument(storeId, "storeID");
            IEMessage deletedItem = OutlookSession.OpenMessage(ntf.EntryID, storeId);

            if (deletedItem != null)
            {
                using ( deletedItem )
                {
                    Trace.WriteLine("Successfully opened deleted item resource");
                    string entryId = OutlookSession.GetMessageID(deletedItem);
                    if (String.IsNullOrEmpty(entryId))
                    {
                        throw new ArgumentNullException("entryId", "MailDeletedDescriptor -- NULL entryId string of the existing IEMessage");
                    }

                    FindResourcesByEntryId(entryId);
                }
            }
            else
            {
                FindResourcesByEntryId(ntf.EntryID);
                if (_resourceToDelete != null)
                {
                    return;
                }

                // we've got a short-term entry ID in the notification; we need to scan the parent
                // folder to find the resources which need to be deleted
                IEFolder parentFolder = OutlookSession.OpenFolder(ntf.ParentID, storeId);
                if (parentFolder != null)
                {
                    using ( parentFolder )
                    {
                        string    parentId         = OutlookSession.GetFolderID(parentFolder);
                        IResource parentMAPIFolder = Folder.Find(parentId);
                        if (parentMAPIFolder != null)
                        {
                            if (Folder.IsFolderOfType(parentMAPIFolder, FolderType.Contact))
                            {
                                RemoveContactFromSync(parentId, storeId);
                                return;
                            }

                            //  Deletion from the folder which we ignore anyway
                            //  must not lead to a great performance loss.
                            if (!parentMAPIFolder.HasProp(PROP.IgnoredFolder))
                            {
                                FindResourceToDelete(parentFolder, parentMAPIFolder, storeId);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        private void SynchronizeFolderStructureImpl()
        {
            _tracer.Trace("Start SynchronizeFolderStructureImpl");
            IResourceList folders = Core.ResourceStore.GetAllResources(STR.MAPIFolder);

            foreach (IResource folder in folders.ValidResources)
            {
                string entryID = folder.GetStringProp(PROP.EntryID);
                if (entryID != null)
                {
                    _folders.Add(entryID);
                }
                else
                {
                    new ResourceProxy(folder).DeleteAsync();
                }
            }
            _tracer.Trace("Start enumeration for info stores");

            foreach (IEMsgStore msgStore in OutlookSession.GetMsgStores())
            {
                if (msgStore == null)
                {
                    continue;
                }
                _tracer.Trace("GetRootFolder");

                IEFolder rootFolder = msgStore.GetRootFolder();
                string   storeID    = msgStore.GetBinProp(MAPIConst.PR_STORE_ENTRYID);
                if (IsIgnoredInfoStore(msgStore))
                {
                    _tracer.Trace("MsgStore is ignored");
                    if (rootFolder == null)
                    {
                        continue;
                    }
                    using ( rootFolder )
                    {
                        string    entryID        = OutlookSession.GetFolderID(rootFolder);
                        IResource rootMAPIFolder = Folder.Find(entryID);
                        if (rootMAPIFolder != null)
                        {
                            _tracer.Trace("Delete folder recursive for " + rootMAPIFolder.DisplayName);
                            Core.ResourceAP.QueueJob("Delete folder recursive", new ResourceDelegate(Folder.DeleteFolderRecursive),
                                                     rootMAPIFolder);
                        }
                    }
                }
                else
                {
                    string name = msgStore.GetStringProp(MAPIConst.PR_DISPLAY_NAME);
                    _tracer.Trace("MsgStore name = " + name);
                    SynchronizeFolderRecursive(rootFolder, name, storeID, null);
                }
            }

            _tracer.Trace("Delete folders recursively if necessary");

            foreach (HashSet.Entry entry in _folders)
            {
                IResource folderToDelete =
                    Core.ResourceStore.FindUniqueResource(STR.MAPIFolder, PROP.EntryID, (string)entry.Key);
                if (folderToDelete != null)
                {
                    PairIDs folderIDs = PairIDs.Get(folderToDelete);
                    if (folderIDs != null)
                    {
                        if (OutlookSession.WereProblemWithOpeningStorage(folderIDs.StoreId))
                        {
                            continue;
                        }
                        if (OutlookSession.WereProblemWithOpeningFolder(folderIDs.EntryId))
                        {
                            continue;
                        }
                    }
                    Core.ResourceAP.QueueJob(new ResourceDelegate(Folder.DeleteFolderRecursive),
                                             folderToDelete);
                }
            }
            _folders.Clear();
            _tracer.Trace("Finish SynchronizeFolderStructureImpl");
        }
示例#5
0
        public FolderDeletedDescriptor(MAPINtf ntf, string storeID)
        {
            Guard.NullArgument(ntf, "ntf");
            Guard.EmptyStringArgument(storeID, "storeID");
            _ntf     = ntf;
            _storeID = storeID;

            // The notification contains only the short-term entry ID, and since the
            // folder has already been deleted, it is no longer possible to get the
            // long-term entry ID. Thus, we need to scan the children of the parent of
            // the deleted folder and check if all of them still exist.
            IResource resFolder = Folder.Find(ntf.EntryID);

            if (resFolder == null)
            {
                IEFolder parentFolder =
                    OutlookSession.OpenFolder(ntf.ParentID, storeID);
                if (parentFolder != null)
                {
                    using ( parentFolder )
                    {
                        string    parentId         = OutlookSession.GetFolderID(parentFolder);
                        IResource parentMAPIFolder = Folder.Find(parentId);
                        if (parentMAPIFolder == null)
                        {
                            parentMAPIFolder = Folder.Find(ntf.ParentID);
                        }

                        if (parentMAPIFolder != null)
                        {
                            IResourceList childFolders = parentMAPIFolder.GetLinksTo("MAPIFolder", "Parent");
                            foreach (IResource childFolderRes in childFolders)
                            {
                                IEFolder childFolder = OutlookSession.OpenFolder(childFolderRes.GetStringProp("EntryID"),
                                                                                 storeID);
                                if (childFolder != null)
                                {
                                    childFolder.Dispose();
                                }
                                else
                                {
                                    _entryId = childFolderRes.GetStringProp("EntryID");
                                }
                            }

                            if (_entryId == null)
                            {
                                HashSet set = new HashSet(childFolders.Count);
                                foreach (IResource childFolderRes in childFolders)
                                {
                                    set.Add(childFolderRes.GetStringProp("EntryID"));
                                }

                                IEFolders folders = OutlookSession.GetFolders(parentFolder);
                                if (folders != null)
                                {
                                    using ( folders )
                                    {
                                        for (int i = 0; i < folders.GetCount(); ++i)
                                        {
                                            IEFolder folder = OutlookSession.OpenFolder(folders, i);
                                            if (folder != null)
                                            {
                                                using ( folder )
                                                {
                                                    string entryId = folder.GetBinProp(MAPIConst.PR_ENTRYID);
                                                    if (entryId != null)
                                                    {
                                                        set.Remove(entryId);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                foreach (HashSet.Entry entry in set)
                                {
                                    _entryId = (string)entry.Key;
                                    break;
                                }

                                if (_entryId == null && Retry)
                                {
                                    OutlookSession.OutlookProcessor.QueueJobAt(DateTime.Now.AddMinutes(2), "Delete folder",
                                                                               new MethodInvoker(CreateFolderDeletedDescriptor));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                _entryId = ntf.EntryID;
            }
        }