Exemple #1
0
        private void _ABList_ResourceChanged(object sender, ResourcePropIndexEventArgs e)
        {
            string    entryID   = e.Resource.GetStringProp(PROP.EntryID);
            IResource resFolder = Folder.Find(entryID);
            PairIDs   pairIDs   = PairIDs.Get(resFolder);

            if (pairIDs == null)
            {
                return;
            }

            IEFolder folder = OutlookSession.OpenFolder(pairIDs.EntryId, pairIDs.StoreId);

            if (folder != null)
            {
                using ( folder )
                {
                    if (!e.Resource.GetPropText(Core.Props.Name).EndsWith("(Outlook)"))
                    {
                        folder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, e.Resource.GetStringProp(Core.Props.Name));
                        folder.SaveChanges();
                    }
                }
            }
        }
Exemple #2
0
 private IResource GetParentFolder()
 {
     if (_folder != null && _parentFolder != null)
     {
         return(Folder.Find(_parentFolder.FolderIDs.EntryId));
     }
     return(null);
 }
Exemple #3
0
        protected override void Execute()
        {
            if (OutlookSession.OutlookProcessor.ShuttingDown)
            {
                return;
            }

            IEFolder folder = OutlookSession.OpenFolder(_ntf.ParentID, _storeID);

            if (folder != null)
            {
                using ( folder )
                {
                    FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder);
                    if (folderDescriptor == null)
                    {
                        return;
                    }
                    IResource resFolder = Folder.Find(folderDescriptor.FolderIDs.EntryId);
                    if (resFolder == null)
                    {
                        return;
                    }

                    bool ignoredFolder = Folder.IsIgnored(resFolder);

                    IEMessage message = OutlookSession.OpenMessage(_ntf.EntryID, _storeID);
                    if (message == null)
                    {
                        return;
                    }
                    using ( message )
                    {
                        string    entryId = OutlookSession.GetMessageID(message);
                        IResource mail    = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.EntryID);
                        if (mail == null && _ntf.OldEntryID != null)
                        {
                            mail = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.OldEntryID);
                        }

                        if (ignoredFolder && mail != null)
                        {
                            Trace.WriteLine("Moved mail ID=" + mail.Id + " to ignored folder");
                            Mail.ForceDelete(mail);
                            return;
                        }
                        if (mail == null)
                        {
                            ProcessMailAddNtf.DoJob(_ntf, _storeID);
                            return;
                        }
                        mail.SetProp(PROP.EntryID, entryId);
                        Folder.LinkMail(resFolder, mail);
                    }
                }
            }
        }
Exemple #4
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);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        private static bool IsDataCorrect(FolderDescriptor folder)
        {
            IResource resource = Folder.Find(folder.FolderIDs.EntryId);

            if (resource == null || !Folder.IsFolderOfType(resource, FolderType.Contact) ||
                Folder.IsIgnoreImport(resource))
            {
                return(false);
            }
            return(true);
        }
Exemple #6
0
 protected override void Execute()
 {
     if (_entryId != null)
     {
         IResource resFolder = Folder.Find(_entryId);
         if (resFolder != null)
         {
             Folder.DeleteFolder(resFolder);
         }
     }
 }
Exemple #7
0
        private static void RemoveWrongGlobalBooks()
        {
            IResourceList gals = RS.GetAllResources(STR.OutlookABDescriptor);

            for (int i = gals.Count - 1; i >= 0; i--)
            {
                IResource gal = gals[i];
                if (Folder.Find(gal.GetPropText(PROP.EntryID)) != null)
                {
                    gal.Delete();
                }
            }
        }
Exemple #8
0
        private void _ABList_ResourceDeleting(object sender, ResourceIndexEventArgs e)
        {
            string    entryID   = e.Resource.GetStringProp(PROP.EntryID);
            IResource container = Folder.Find(entryID);

            if (container == null)
            {
                container = Core.ResourceStore.FindUniqueResource(STR.OutlookABDescriptor, PROP.EntryID, entryID);
            }
            if (container != null)
            {
                Folder.SetIgnoreImport(container, true);
            }
        }
Exemple #9
0
 public static void LinkOrDelete(FolderDescriptor folder, IResource email)
 {
     Guard.NullArgument(email, "email");
     if (folder != null)
     {
         IResource resFolder = Folder.Find(folder.FolderIDs.EntryId);
         if (!Folder.IsIgnored(resFolder))
         {
             if (email.GetLinkProp(PROP.MAPIFolder) != resFolder)
             {
                 Core.ResourceAP.QueueJob("Link Email To Folder", new LinkMailDelegate(LinkMail), resFolder, email);
             }
             return;
         }
     }
     DeleteMail(email);
 }
Exemple #10
0
 public override void OK()
 {
     //  Workaround of OM-13897, calling an OutlookSession in the shutdown
     //  state causes unpredictable results.
     if (Core.State == CoreState.Running)
     {
         _treeView.SaveCheckedState();
         MAPIIDs IDs = OutlookSession.GetInboxIDs();
         if (IDs != null)
         {
             IResource folder = Folder.Find(IDs.EntryID);
             if (folder != null && !Folder.IsIgnored(folder))
             {
                 Core.UIManager.CreateShortcutToResource(folder);
             }
         }
         SettingSaver.Save(Controls);
         Settings.LoadSettings();
     }
 }
Exemple #11
0
        private void LinkToFolder(IResource resMail)
        {
            IResource resFolder = null;

            if (_folder != null)
            {
                resFolder = Folder.Find(_folder.FolderIDs.EntryId);
            }
            if (resFolder != null)
            {
                Folder.LinkMail(resFolder, resMail);
                IResource msgStore = Folder.GetMAPIStorage(resFolder);
                if (msgStore.GetDateProp(PROP.LastReceiveDate) < _receivedTime)
                {
                    msgStore.SetProp(PROP.LastReceiveDate, _receivedTime);
                }
            }
            else
            {
                _tracer.Trace("Can't link mail to folder");
            }
        }
Exemple #12
0
 protected override void Execute()
 {
     if (_folder != null && !String.IsNullOrEmpty(_folder.FolderIDs.EntryId))
     {
         IResource resFolder = Folder.Find(_folder.FolderIDs.EntryId);
         if (resFolder != null)
         {
             if (!Folder.IsParentRoot(resFolder))
             {
                 Folder.SetName(resFolder, _folder.Name);
             }
             if (_isMovedFolder && _parentFolder != null)
             {
                 IResource resParentFolder = Folder.Find(_parentFolder.FolderIDs.EntryId);
                 if (resParentFolder != null)
                 {
                     Folder.SetParent(resFolder, resParentFolder);
                 }
             }
         }
         FolderStructureDescriptor.UpdateContactFolder(_folder);
     }
 }
Exemple #13
0
        private static bool IsDataCorrect(out IResource resFolder, FolderDescriptor folderDescriptor)
        {
            resFolder = null;
            if (OutlookSession.OutlookProcessor.ShuttingDown)
            {
                return(false);
            }

            if (folderDescriptor == null)
            {
                return(false);
            }
            resFolder = Folder.Find(folderDescriptor.FolderIDs.EntryId);
            if (resFolder == null)
            {
                return(false);
            }
            if (Folder.IsIgnored(folderDescriptor))
            {
                return(false);
            }
            return(true);
        }
Exemple #14
0
        public override void UndeleteResource(IResource res)
        {
            Guard.NullArgument(res, "res");
            IResourceList attachments = res.GetLinksOfType(null, PROP.Attachment);

            foreach (IResource attachment in attachments.ValidResources)
            {
                attachment.SetProp(Core.Props.IsDeleted, false);
            }

            IResource folder = null;
            MAPIIDs   IDs    = OutlookSession.GetInboxIDs();

            if (IDs != null)
            {
                folder = Folder.Find(IDs.EntryID);
            }

            if (folder != null)
            {
                MoveMessageToFolderAction action = new MoveMessageToFolderAction(false);
                action.DoMove(folder, res.ToResourceList());
            }
        }
Exemple #15
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 #16
0
        private void EnumerateMail(FolderDescriptor folder, IEFolder mapiFolder)
        {
            try
            {
                OnFolderFetched(folder.Name);
                int indexed = 0;

                IResource resFolder  = Folder.Find(folder.FolderIDs.EntryId);
                DateTime  dtRestrict = GetRestrictDate(resFolder);

                IETable table = null;
                try
                {
                    table = mapiFolder.GetEnumTable(dtRestrict);
                }
                catch (System.UnauthorizedAccessException exception)
                {
                    _tracer.TraceException(exception);
                }
                catch (OutOfMemoryException exception)
                {
                    _tracer.TraceException(exception);
                }
                if (table == null)
                {
                    return;
                }
                using ( table )
                {
                    int count = table.GetRowCount();
                    if (count > 0)
                    {
                        table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false);
                    }
                    for (uint i = 0; i < count; i++)
                    {
                        if (OutlookSession.OutlookProcessor.ShuttingDown)
                        {
                            break;
                        }
                        if (_idle && Settings.IdleModeManager.CheckInterruptIdle())
                        {
                            break;
                        }
                        IERowSet row = row = table.GetNextRow();
                        if (row == null)
                        {
                            continue;
                        }
                        using ( row )
                        {
                            if (row.GetLongProp(6) != 1)
                            {
                                ProcessRow(row, folder, mapiFolder, ref indexed);
                            }
                        }
                    }
                }
                if (Settings.IdleModeManager.CompletedIdle)
                {
                    Folder.SetSeeAllAsync(resFolder);
                }

                _tracer.Trace("Indexed " + indexed + " messages in folder " + folder.Name);
            }
            finally
            {
                OutlookSession.ProcessJobs();
            }
        }
Exemple #17
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;
            }
        }
Exemple #18
0
        protected override void Execute()
        {
            IResource task = GetTaskResource();

            if (task == null)
            {
                Tracer._Trace("TASK IMPORT task not found");
            }
            if (task != null)
            {
                if (_folder.ContainerClass != FolderType.Task)
                {
                    Tracer._Trace("Delete task: id = " + task.Id);
                    task.Delete();
                    return;
                }
            }

            IResource resFolder     = Folder.Find(_folder.FolderIDs.EntryId);
            bool      folderIgnored = (resFolder != null && Folder.IsIgnored(resFolder)) || OutlookSession.IsDeletedItemsFolder(_folder.FolderIDs.EntryId);

            if (folderIgnored)
            {
                if (task != null)
                {
                    task.Delete();
                }
                return;
            }

            bool import = resFolder != null && !Folder.IsIgnoreImport(resFolder);

            if (!import && task == null)
            {
                return;
            }

            if (task == null)
            {
                task = Core.ResourceStore.BeginNewResource(STR.Task);
            }
            else
            {
                task.BeginUpdate();
            }

            string oldEntryID = task.GetStringProp(PROP.EntryID);

            if (oldEntryID == null)
            {
                task.SetProp(PROP.EntryID, _entryID);
            }
            else if (oldEntryID != _entryID)
            {
                throw new ApplicationException("Try to change entryID for task");
            }
            if (resFolder != null)
            {
                Folder.LinkMail(resFolder, task);
            }

            if (!import)
            {
                task.EndUpdate();
                if (Settings.TraceTaskChanges)
                {
                    _tracer.Trace(task);
                }
                return;
            }

            task.SetProp(Core.Props.Subject, _subject);

            SetDateProp(task, Core.Props.Date, _dueDate);
            SetDateProp(task, PROP.StartDate, _startDate);

            if (_reminderActive == 0)
            {
                SetDateProp(task, PROP.RemindDate, DateTime.MinValue);
            }
            else
            {
                SetDateProp(task, PROP.RemindDate, _remindDate);
            }

            task.SetProp(PROP.Status, _status);
            task.SetProp(PROP.Priority, _priority);
            task.SetProp(PROP.Description, _description);
            task.AddLink(PROP.Target, Core.ResourceTreeManager.GetRootForType(STR.Task));
            if (!task.HasProp(PROP.SuperTaskLink))
            {
                task.SetProp(PROP.SuperTaskLink, Core.ResourceTreeManager.GetRootForType(STR.Task));
            }

            if (Settings.SyncTaskCategory)
            {
                CategorySetter.DoJob(_outlookCategories, task);
            }

            bool wereChanges = task.IsChanged();

            task.EndUpdate();
            if (wereChanges && Core.TextIndexManager != null)
            {
                Guard.QueryIndexingWithCheckId(task);
            }
            if (Settings.TraceTaskChanges)
            {
                _tracer.Trace(task);
            }
        }