private MeasureResult GetResource(Rainmeter.Settings.InstanceSettings Instance)
        {
            string resourceKey = Instance.INI_Value("Resource");

            if (resourceKey.Length == 0)
            {
                return(new ErrorResult(-1, "Resource required"));
            }
            else if (resourceKey.StartsWith("["))
            {
                MeasureResult r;
                if (TryUpdateOtherMeasure(resourceKey, Instance, out r))
                {
                    return(r);
                }
                return(new ErrorResult(-1, "Unknown measure " + resourceKey));
            }
            else if (resourceKey == "Status")
            {
                return(new StatusResult(status, statusMsg));
            }
            else if (resourceKey == "MAPIFolder" || resourceKey == "EmailFolder")
            {
                return(GetMAPIFolders(Instance));
            }
            return(new ErrorResult(-1, "Unknown resource '" + resourceKey + "'"));
        }
        private MeasureResult Evaluate(Rainmeter.Settings.InstanceSettings Instance)
        {
            MeasureResult result = null;

            try
            {
                result = GetResource(Instance);

                result = result.Select(Instance);

                result = result.Filter(Instance);

                string strIndex = Instance.INI_Value("Index");
                if (strIndex.Length > 0)
                {
                    int index = int.Parse(strIndex);
                    result = result.Index(index, Instance);
                }
            }
            catch (Exception e)
            {
                result = new ErrorResult(-1, e.Message);
            }
            finally
            {
                Instance.SetTempValue("Age", 0);
                Instance.SetTempValue("Cached", result);
                Instance.SetTempValue("resetId", OutlookPlugin.resetId);
            }
            return(result);
        }
        public override MeasureResult Filter(Rainmeter.Settings.InstanceSettings Instance)
        {
            List <MAPIFolderResult> list = folders;

            string filter = Instance.INI_Value("Filter");

            if (filter.Length > 0)
            {
                list = list.FindAll(delegate(MAPIFolderResult f)
                {
                    return(f.testFilter(filter, Instance));
                });
            }

            string include = Instance.INI_Value("Include");

            if (include.Length > 0)
            {
                include = include.Replace(".", "\\.").Replace("*", ".*");
                Regex regex = new Regex("^(" + include + ")$");
                list = list.FindAll(delegate(MAPIFolderResult f)
                {
                    return(regex.IsMatch(f.Name));
                });
            }

            string exclude = Instance.INI_Value("Exclude");

            if (exclude.Length > 0)
            {
                exclude = exclude.Replace(".", "\\.").Replace("*", ".*");
                Regex regex = new Regex("^(" + exclude + ")$");
                list = list.FindAll(delegate(MAPIFolderResult f)
                {
                    return(!regex.IsMatch(f.Name));
                });
            }

            if (list == folders)
            {
                return(this);
            }
            return(new MAPIFolderListResult(list));
        }
        protected string virtual_INI_value(Rainmeter.Settings.InstanceSettings Instance, String key)
        {
            string r = Instance.INI_Value(key);

            if (r.Length > 0)
            {
                return(r);
            }
            if (Instance.INI_Value("Override") == "1")
            {
                return("");
            }
            Rainmeter.Settings.InstanceSettings other = (Rainmeter.Settings.InstanceSettings)Instance.GetTempValue("Base", null);
            if (other == null)
            {
                return("");
            }
            return(virtual_INI_value(other, key));
        }
        public override MeasureResult Select(Rainmeter.Settings.InstanceSettings Instance)
        {
            string select = Instance.INI_Value("Select");

            if (select == "Subfolders")
            {
                MAPIFolderListResult result = new MAPIFolderListResult();
                result.AddRoot(folder, false);
                return(result);
            }
            return(base.Select(Instance));
        }
        public override MeasureResult Select(Rainmeter.Settings.InstanceSettings Instance)
        {
            string select = Instance.INI_Value("Select");

            if (select == "Root")
            {
                MAPIFolderListResult result = new MAPIFolderListResult();
                foreach (MAPIFolderResult root in roots)
                {
                    result.Add(root);
                }
                return(result);
            }
            return(this);
        }
        private MeasureResult GetMAPIFolders(Rainmeter.Settings.InstanceSettings Instance)
        {
            MAPIFolderListResult result = new MAPIFolderListResult();
            string rootList             = Instance.INI_Value("Root");

            if (rootList.Length == 0)
            {
                rootList = "Inbox";
            }
            Outlook.NameSpace nsMapi = outlook.GetNamespace("MAPI");
            foreach (string root in rootList.Split('|'))
            {
                if (!root.StartsWith("\\"))
                {
                    switch (root)
                    {
                    case "Inbox":
                        Outlook.MAPIFolder inbox = nsMapi.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                        result.AddRoot(inbox);
                        break;

                    default:
                        return(new ErrorResult(-1, root + " not implemented"));
                    }
                }
                else
                {
                    Outlook.MAPIFolder folder = FindRoot(nsMapi.Folders, root);
                    if (folder == null)
                    {
                        return(new ErrorResult(-1, root + " not found"));
                    }
                    result.AddRoot(folder);
                }
            }
            return(result);
        }