Exemple #1
0
        private void ProcessContactFolders(int processedABs, int totalABs)
        {
            ArrayList toDeleteFolders = new ArrayList();

            foreach (IResource contactFolder in Folder.GetFolders(FolderType.Contact).ValidResources)
            {
                if (ShuttingDown)
                {
                    break;
                }
                OutlookSession.ProcessJobs();
                processedABs++;
                int percentage = (processedABs * 100) / totalABs;
                Settings.UpdateProgress(percentage, "Indexing Address Books", processedABs.ToString());

                PairIDs folderIDs = PairIDs.Get(contactFolder);
                if (folderIDs == null)
                {
                    toDeleteFolders.Add(contactFolder);
                    continue;
                }
                string abName = OutlookAddressBook.GetProposedName(contactFolder.GetPropText(Core.Props.Name), folderIDs.EntryId);
                Core.ResourceAP.QueueJob(new OutlookAddressBookReName(folderIDs.EntryId, abName));

                if (!Folder.IsIgnoreImport(contactFolder))
                {
                    ProcessContactFolder(folderIDs, abName);
                }
                else
                {
                    IResource AB = Core.ResourceStore.FindUniqueResource(STR.AddressBook, PROP.EntryID, folderIDs.EntryId);
                    if (AB != null)
                    {
                        new ResourceProxy(AB).DeleteAsync();
                    }
                }
            }
            foreach (IResource contactFolder in toDeleteFolders)   // delete corrupted 'MAPIFolder' resources
            {
                new ResourceProxy(contactFolder).DeleteAsync();
            }
        }
Exemple #2
0
        private static IEFolder FindTaskFolderFromResourceStore()
        {
            IResourceList taskFolders =
                Core.ResourceStore.FindResources(STR.MAPIFolder, PROP.ContainerClass, FolderType.Task);

            taskFolders.Sort(new SortSettings(ResourceProps.Id, false));
            foreach (IResource resource in taskFolders.ValidResources)
            {
                PairIDs folderIDs = PairIDs.Get(resource);
                if (folderIDs != null)
                {
                    IEFolder taskFolder = OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                    if (taskFolder != null)
                    {
                        return(taskFolder);
                    }
                }
            }
            return(null);
        }
Exemple #3
0
        protected override void ExecuteAction(IResourceList selectedResources)
        {
            Trace.WriteLine(">>> CreateFolderAction.ExecuteAction");
            PairIDs folderIDs = PairIDs.Get(selectedResources[0]);

            try
            {
                IEFolder folder =
                    OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    IEFolder subFolder = folder.CreateSubFolder(_folderName);
                    if (subFolder != null)
                    {
                        using ( subFolder )
                        {}
                    }
                }
            }
            catch (COMException exception)
            {
                Tracer._TraceException(exception);
                MsgBox.Error("Outlook Plugin", "Cannot create new folder.\n" +
                             "Reason is: folder with such name already exists.");
            }
            catch (System.UnauthorizedAccessException exception)
            {
                Tracer._TraceException(exception);
                MsgBox.Error("Outlook Plugin", "Cannot create new folder.\n" + exception.Message);
            }
            Trace.WriteLine("<<< CreateFolderAction.ExecuteAction");
        }
Exemple #4
0
        public void ResourceNodeSelected(IResource folder)
        {
            bool displayUnread = folder.HasProp(Core.Props.DisplayUnread);

            if (_lastFolderID != folder.Id || displayUnread != _lastDisplayUnread)
            {
                Trace.WriteLine(">>> OutlookUIHandler.ResourceNodeSelected");
                _currentResourceList = CreateResourceList(folder);
                _lastFolderID        = folder.Id;
                _lastDisplayUnread   = displayUnread;
                if (displayUnread)
                {
                    _currentResourceList = _currentResourceList.Intersect(
                        Core.ResourceStore.FindResourcesWithProp(SelectionType.LiveSnapshot, null, "IsUnread"), true);
                }
            }
            _displayMailsInFolderAction.DisplayResourceList(folder, _currentResourceList);
            PairIDs folderIDs = PairIDs.Get(folder);

            if (folderIDs != null)
            {
                OutlookSession.OutlookProcessor.QueueJob(JobPriority.Immediate, new RefreshFolderDelegate(RefreshFolder), folderIDs, folder);
            }
        }
Exemple #5
0
 public override void DeleteResource(IResource res)
 {
     Guard.NullArgument(res, "res");
     DeleteMail(res, PairIDs.Get(res), true);
 }
Exemple #6
0
        protected void ExecuteActionImpl(IResourceList selectedResources)
        {
            Tracer._Trace("Execute action: MoveFolderToFolderAction");
            if (_selectedFolder == null || _targetFolder == null)
            {
                return;
            }

            IEFolder destFolder =
                OutlookSession.OpenFolder(_selectedFolder.EntryId, _selectedFolder.StoreId);

            if (destFolder == null)
            {
                return;
            }

            using ( destFolder )
            {
                for (int i = 0; i < selectedResources.Count; i++)
                {
                    PairIDs folderIDs = PairIDs.Get(selectedResources[i]);
                    if (folderIDs == null)
                    {
                        continue;
                    }
                    IResource parentFolder    = Folder.GetParent(selectedResources[i]);
                    PairIDs   parentFolderIDs = PairIDs.Get(parentFolder);
                    if (parentFolderIDs == null)
                    {
                        continue;
                    }

                    IEFolder ieFolder =
                        OutlookSession.OpenFolder(parentFolderIDs.EntryId, parentFolderIDs.StoreId);
                    if (ieFolder == null)
                    {
                        continue;
                    }
                    using ( ieFolder )
                    {
                        Tracer._Trace("Move folder: " + folderIDs.EntryId.GetHashCode() + "/" + folderIDs.EntryId);
                        try
                        {
                            ieFolder.MoveFolder(folderIDs.EntryId, destFolder);
                        }
                        catch (COMException exception)
                        {
                            Tracer._TraceException(exception);
                            if (exception.ErrorCode == (unchecked ((int)0x8004010F)))
                            {
                                StandartJobs.MessageBox("Folder is not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040604)))
                            {
                                StandartJobs.MessageBox("Collision. Probably target folder has subfolder with the same name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040119)) || exception.ErrorCode == (unchecked ((int)0x8004dff2)))
                            {
                                StandartJobs.MessageBox("Unspecified error. Can't move or copt folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                StandartJobs.MessageBox(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
 public void DoMove(IResource targetFolder, IResourceList selectedResources)
 {
     SetFolder(PairIDs.Get(targetFolder), targetFolder);
     OutlookSession.OutlookProcessor.QueueJob(JobPriority.Immediate, "Move subfolder to another parent folder",
                                              new ResourceListDelegate(ExecuteActionImpl), selectedResources);
 }
Exemple #8
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");
        }
Exemple #9
0
        public void RemoveDeletedMailsFromIndex()
        {
            try
            {
                int             count    = 0;
                MailInIndexEnum mailEnum = _mailsInOldIndex.GetEnumerator();
                int             total    = mailEnum.Count;
//                _tracer.Trace( "Start RemoveDeletedMailsFromIndex" );
//                _tracer.Trace( "RemoveDeletedMailsFromIndex : mail to remove " + total.ToString() );
                int curTickCount = Environment.TickCount;
                for (int i = 0; i < total; i++)
                {
                    OutlookSession.ProcessJobs();

                    if (OutlookSession.OutlookProcessor.ShuttingDown)
                    {
                        break;
                    }
                    if (_idle && Settings.IdleModeManager.CheckInterruptIdle())
                    {
                        break;
                    }
                    int percentage = (total == 0)
                        ? 100
                        : ++count * 100 / total;
                    if (percentage > 100)
                    {
                        percentage = 100;
                    }

                    if (Environment.TickCount - curTickCount > 500)
                    {
                        string statusText = "Synchronizing mails(" + count + "/" + total + ")...";
                        Settings.UpdateProgress(percentage, statusText, string.Empty);
                        curTickCount = Environment.TickCount;
                    }

                    IResource resMail = mailEnum.GetResource(i);
                    if (resMail == null || !Guard.IsResourceLive(resMail))
                    {
//                        _tracer.Trace( "RemoveDeletedMailsFromIndex : resMail == null" );
                        continue;
                    }
                    PairIDs messageIDs = PairIDs.Get(resMail);
                    if (messageIDs == null)
                    {
                        if (!resMail.HasProp(PROP.EmbeddedMessage))
                        {
                            new ResourceProxy(resMail).DeleteAsync();
                        }
                        continue;
                    }

                    string    storeID     = messageIDs.StoreId;
                    string    folderID    = null;
                    IEMessage mapiMessage =
                        OutlookSession.OpenMessage(messageIDs.EntryId, storeID);
                    if (mapiMessage != null)
                    {
                        using ( mapiMessage )
                        {
                            folderID = mapiMessage.GetBinProp(MAPIConst.PR_PARENT_ENTRYID);
                        }
                    }
                    FolderDescriptor folder = null;
                    if (folderID != null)
                    {
                        folder = FolderDescriptor.Get(folderID, storeID);
                    }
                    MailSyncToFolder.LinkOrDelete(folder, resMail);
                    OutlookSession.ProcessJobs();
                }
            }
            finally
            {
                _mailsInOldIndex.Clear();
            }
            OutlookSession.ProcessJobs();
        }
Exemple #10
0
 public FolderDescriptor(IResource folder)
 {
     Init(PairIDs.Get(folder),
          folder.GetPropText(Core.Props.Name),
          Folder.GetContainerClass(folder), Folder.GetStoreSupportMask(folder), Folder.GetConentCount(folder));
 }