Example #1
0
        private void EnumerateTasks(FolderDescriptor folder, IEFolder mapiFolder)
        {
            OnFolderFetched(folder.Name);

            IEMessages messages = mapiFolder.GetMessages();

            if (messages != null)
            {
                using ( messages )
                {
                    int count = messages.GetCount();
                    for (int i = 0; i < count; i++)
                    {
                        IEMessage message = messages.OpenMessage(i);
                        if (message != null)
                        {
                            using ( message )
                            {
                                string entryID = OutlookSession.GetMessageID(message);
                                TaskDescriptor.Do(folder, message, entryID);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void ProcessContactFolder(PairIDs folderIDs, string abName)
        {
            IEFolder folder = null;

            try
            {
                folder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception exception)
            {
                if (exception is COMException &&
                    ((COMException)exception).ErrorCode != (unchecked ((int)0x80040111)))       //ClassFactory cannot supply requested class
                {
                    return;
                }
                Core.ReportException(exception, ExceptionReportFlags.AttachLog);
                return;
            }
            if (folder == null)
            {
                return;
            }
            using ( folder )
            {
                OutlookAddressBook AB = new OutlookAddressBook(abName, folderIDs, true);
                AB.RunAB();
                IEMessages messages = folder.GetMessages();
                if (messages == null)
                {
                    return;
                }
                using ( messages )
                {
                    int mesCount = messages.GetCount();
                    for (int i = 0; i < mesCount; i++)
                    {
                        if (ShuttingDown)
                        {
                            break;
                        }
                        OutlookSession.ProcessJobs();
                        IEMessage message = messages.OpenMessage(i);
                        if (message == null)
                        {
                            continue;
                        }
                        using ( message )
                        {
                            string mesEntryID = OutlookSession.GetMessageID(message);
                            Core.ResourceAP.QueueJob(new ContactDescriptor(message, mesEntryID, mesEntryID, AB));
                        }
                    }
                }
            }
        }
Example #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);
                    }
                }
            }
        }
Example #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);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        private void ProcessMailModifyImpl(MAPIFullNtf ntf, IEMessage message, FolderDescriptor folderDescriptor)
        {
            string messageClass = MessageType.GetMessageClass(message);

            if (MessageType.InterpretAsMail(messageClass))
            {
                string entryId = OutlookSession.GetMessageID(message);
                if (OutlookSession.IsMailExported(entryId))
                {
                    return;
                }
                new MailDescriptor(folderDescriptor, entryId, message, MailDescriptor.UpdateState).QueueJob(JobPriority.AboveNormal);
            }
            else if (MessageType.InterpretAsContact(messageClass))
            {
                string realEntryId = message.GetBinProp(MAPIConst.PR_ENTRYID);
                if (OutlookSession.IsMailExported(realEntryId))
                {
                    return;
                }
                ContactDescriptorWrapper.Do(folderDescriptor, realEntryId, realEntryId);
            }
            else if (MessageType.InterpretAsTask(messageClass))
            {
                _tracer.Trace("Task was modified");
                string realEntryId = message.GetBinProp(MAPIConst.PR_ENTRYID);
                if (OutlookSession.IsMailExported(realEntryId))
                {
                    return;
                }
                TaskDescriptor.Do(JobPriority.AboveNormal, folderDescriptor, message, realEntryId);
            }
            else
            {
                ntf = ntf;
//                _tracer.Trace( "Unknown item of class " + messageClass + " was modified" );
            }
        }
Example #6
0
        public static void DoJobImpl(MAPINtf ntf, IEMessage message, FolderDescriptor folderDescriptor)
        {
            string entryId      = OutlookSession.GetMessageID(message);
            string messageClass = MessageType.GetMessageClass(message);

            if (MessageType.InterpretAsMail(messageClass))
            {
                new MailDescriptor(folderDescriptor, entryId, message).QueueJob(JobPriority.AboveNormal);
            }
            else if (MessageType.InterpretAsContact(messageClass))
            {
                ContactDescriptorWrapper.Do(JobPriority.AboveNormal, folderDescriptor, entryId, entryId);
            }
            else if (MessageType.InterpretAsTask(messageClass))
            {
                Tracer._Trace("Task was added");
                TaskDescriptor.Do(JobPriority.AboveNormal, folderDescriptor, message, entryId);
            }
            else
            {
                Tracer._Trace("Unknown item of class " + messageClass + " was added");
            }
        }
Example #7
0
        private void OnNewMailImpl(MAPINtf ntf)
        {
            Trace("[New] *Email* - OnNewMailImpl");
            if (CheckStorageIgnored(_storeID))
            {
                Trace("OnNewMailImpl: storage is ignored");
                return;
            }
            FolderDescriptor folderDescriptor = FolderDescriptor.Get(ntf.ParentID, _storeID);

            if (folderDescriptor == null)
            {
                Trace("OnNewMailImpl: folderDescriptor == null");
                return;
            }

            if (folderDescriptor.ContainerClass == FolderType.IMAP)
            {
                IEFolder folder = OutlookSession.OpenFolder(ntf.ParentID, _storeID);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    if (!ProcessMailAddNtf.ProcessIMAPMessage(folder, ntf.EntryID))
                    {
                        return;
                    }
                }
            }

            IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID);

            if (message == null)
            {
                Trace("OnNewMailImpl: cannot open mapi message");
                return;
            }
            using ( message )
            {
                try
                {
                    string entryId = OutlookSession.GetMessageID(message);
                    if (OutlookSession.IsMailExported(entryId))
                    {
                        Trace("OnNewMailImpl: mail is exported at the moment");
                        return;
                    }
                    new NewMailDescriptor(folderDescriptor, entryId, message).QueueJob(JobPriority.AboveNormal);
                }
                catch (System.Threading.ThreadAbortException ex)
                {
                    Tracer._TraceException(ex);
                }
                catch (Exception exception)
                {
                    Core.ReportBackgroundException(exception);
                }
            }
        }