コード例 #1
0
ファイル: SearchFolderWrap.cs プロジェクト: ProjectECS/ECS
        private void InitSearchFolder()
        {
            const string SOURCE = CLASS_NAME + "InitSearchFolder";
            RDOStore store = null;
            RDOFolder searchRoot = null;
            RDOFolder ipmRoot = null;
            try
            {
                //don't repeat a search that's in process
                var rdoSession = RedemptionLoader.new_RDOSession();
                rdoSession.MAPIOBJECT = Globals.ThisAddIn.Session.MAPIOBJECT;
                store = rdoSession.GetStoreFromID(StoreId);
                Logger.Verbose("InitSearchFolder", "initiating search in " + store.Name);
                //get the SearchFolders collection
                searchRoot = store.SearchRootFolder;

                var folders = searchRoot.Folders;
                //look for existing folder
                _searchFolder = (RDOSearchFolder) folders[Key] ;
                if (_searchFolder != null)
                {
                    Logger.Verbose(SOURCE, "found existing search folder for " + Key);
                }
                else
                {
                    //create the search folder
                    Logger.Verbose(SOURCE, "creating new search folder for " + Key);
                    _searchFolder = folders.AddSearchFolder(Key);
                }
                if (_searchFolder == null)
                {
                    Logger.Error(SOURCE, "unable to get or create search folder " + Key);
                    return;
                }
                //make sure it's initialized correctly
                ipmRoot = store.IPMRootFolder;
                //set the criteria
                var criteria = _searchFolder.SearchCriteria;
                var rstrAnd = (RestrictionAnd)criteria.SetKind(RestrictionKind.RES_AND);
                //pointer - could be at start, middle or end of string
                var rstrPointer = (RestrictionContent)rstrAnd.Add(RestrictionKind.RES_CONTENT);
                rstrPointer.lpProp = Pointer;
                var tag = _searchFolder.GetIDsFromNames(ThisAddIn.PS_INTERNET_HEADERS, Resources.content_header)
                    | ThisAddIn.PT_STRING8;
                rstrPointer.ulPropTag = tag;
                rstrPointer.ulFuzzyLevel =
                    ContentFuzzyLevel.FL_SUBSTRING | ContentFuzzyLevel.FL_IGNORECASE;
                //sender
                var rstrSender = (RestrictionContent)rstrAnd.Add(RestrictionKind.RES_CONTENT);
                rstrSender.lpProp = Sender;
                rstrSender.ulPropTag = (int)MAPITags.PR_SENDER_EMAIL_ADDRESS;
                rstrSender.ulFuzzyLevel = ContentFuzzyLevel.FL_IGNORECASE;
                //server
                var rstrServer = (RestrictionContent)rstrAnd.Add(RestrictionKind.RES_CONTENT);
                rstrServer.lpProp = Server;
                tag = _searchFolder.GetIDsFromNames(ThisAddIn.PS_INTERNET_HEADERS, Resources.server_header)
                    | ThisAddIn.PT_STRING8;
                rstrServer.ulPropTag = tag;
                rstrServer.ulFuzzyLevel = ContentFuzzyLevel.FL_IGNORECASE;
                //port
                var rstrPort = (RestrictionContent)rstrAnd.Add(RestrictionKind.RES_CONTENT);
                rstrPort.lpProp = Port;
                tag = _searchFolder.GetIDsFromNames(ThisAddIn.PS_INTERNET_HEADERS, Resources.port_header)
                    | ThisAddIn.PT_STRING8;
                rstrPort.ulPropTag = tag;
                rstrPort.ulFuzzyLevel = ContentFuzzyLevel.FL_IGNORECASE;

                //set the search container as the mailbox
                _searchFolder.SearchContainers.Add(ipmRoot);
                _searchFolder.IsRecursiveSearch = true;
                Logger.Verbose(SOURCE, "adding handler for UpdatedMessageSearchComplete");
                //set up a handler
                _searchFolder.OnSearchComplete +=
                    UpdatedMessageSearchComplete;
                _searchFolder.Start();
            }
            catch (Exception ex)
            {
                Logger.Error(SOURCE, ex.ToString());
            }
            finally
            {
                //Utils.ReleaseObject(stores);
                Utils.ReleaseObject(store);
                Utils.ReleaseObject(searchRoot);
                Utils.ReleaseObject(ipmRoot);
            }
        }
コード例 #2
0
ファイル: StoreWrap.cs プロジェクト: ProjectECS/ECS
        private void LaunchInitialSearch()
        {
            const string SOURCE = CLASS_NAME + "LaunchInitialSearch";
            RDOFolder searchRoot = null;
            RDOFolder ipmRoot = null;
            try
            {
                Logger.Verbose("InitSearchFolder", "initiating search in " + Store.Name);
                //get the SearchFolders collection
                searchRoot = Store.SearchRootFolder;

                var folders = searchRoot.Folders;
                //look for existing folder
                const string NAME = "ECS Message Update";
                _searchFolder = (RDOSearchFolder)folders[NAME];
                if (_searchFolder != null)
                {
                    Logger.Verbose(SOURCE, "found existing search folder for " + Store.Name);
                }
                else
                {
                    //create the search folder
                    Logger.Verbose(SOURCE, "creating new search folder for " + Store.Name);
                    _searchFolder = folders.AddSearchFolder(NAME);
                }
                if (_searchFolder == null)
                {
                    Logger.Error(SOURCE, "unable to get or create search folder " + Store.Name);
                    return;
                }
                //make sure it's initialized correctly
                ipmRoot = Store.IPMRootFolder;
                //set the criteria
                var criteria = _searchFolder.SearchCriteria;
                var rstrAnd = (RestrictionAnd)criteria.SetKind(RestrictionKind.RES_AND);
                //subject
                var rstrSubject = (RestrictionContent)rstrAnd.Add(RestrictionKind.RES_CONTENT);
                rstrSubject.lpProp = ThisAddIn.UPDATE_SUBJECT;
                rstrSubject.ulPropTag = (int)MAPITags.PR_SUBJECT;
                rstrSubject.ulFuzzyLevel = ContentFuzzyLevel.FL_IGNORECASE;
                //unread
                var rstrUnread = (RestrictionBitmask) rstrAnd.Add(RestrictionKind.RES_BITMASK);
                rstrUnread.relBMR = BitmaskBMR.BMR_EQZ;
                rstrUnread.ulMask = 1; //MSGFLAG_READ
                rstrUnread.ulPropTag = (int) MAPITags.PR_MESSAGE_FLAGS;
                //set the search container as the mailbox
                _searchFolder.SearchContainers.Add(ipmRoot);
                _searchFolder.IsRecursiveSearch = true;
                //set up a handler
                _searchFolder.OnSearchComplete +=
                    OnSearchComplete;
                _searchFolder.Start();
            }
            catch (Exception ex)
            {
                Logger.Error(SOURCE, ex.ToString());
            }
            finally
            {
                Utils.ReleaseObject(searchRoot);
                Utils.ReleaseObject(ipmRoot);
            }
        }