3

我正在编写一个应用程序,它必须获取可以与规则匹配的项目。

//new messages goes here
void items_ItemAdd(object Item)
    {
        //all rules
        Rules rules = Application.Session.DefaultStore.GetRules();

        Outlook.MailItem mail = (Outlook.MailItem)Item;

        if (mail != null)
        {
            // I need to find out if mail matches with one of the rule. And handle in an appropriate way.
        }
    }
4

1 回答 1

1

检查哪些规则适用于哪些项目的唯一方法是手动枚举每个规则条件排除规则例外MailItem) 。规则引擎通过执行您定义的每个规则来工作Rule.Execute- 它不提供预览受影响项目的机制。

这是一个(未经测试的)示例,用于参考如何匹配包含主题规则olConditionSubject)。您还需要处理其他规则条件类型

if (mail != null)
{
    foreach (Outlook.Rule rule in rules)
    {
       foreach (Outlook.RuleCondition condition in rule.Conditions)
       {
         if (condition is TextRuleCondition)
         {
            Outlook.TextRuleCondition trc = condition as Outlook.TextRuleCondition;
            if (trc.ConditionType == Outlook.OlRuleConditionType.olConditionSubject)
            {
              // TODO: handle Rule.Exceptions conditions
              bool containsSubject = mail.Subject.Contains(trc.Text);
            }
         }
       }
    }
}
于 2012-07-12T13:52:56.267 回答