コード例 #1
0
 public FolderEvaluationResult(IRuleEvaluationContext context, List <Rule> rules)
 {
     this.context      = context;
     this.targetFolder = context.CurrentFolder;
     this.hasOofRules  = RuleLoader.HasOofRule(rules);
     this.ruleSet      = new FolderEvaluationResult.RuleSet(this, rules);
     this.workItems    = new List <WorkItem>();
 }
コード例 #2
0
 private bool CanSkipRule(Rule rule)
 {
     if (rule.Actions == null)
     {
         this.context.TraceDebug <string>("Skipping rule with no actions: \"{0}.\"", rule.Name);
         return(true);
     }
     if (!this.context.IsOof && RuleLoader.IsOofRule(rule))
     {
         this.context.TraceDebug <string>("Skipping OOF rule: \"{0}.\"", rule.Name);
         return(true);
     }
     if ((rule.StateFlags & RuleStateFlags.TempDisabled) != (RuleStateFlags)0)
     {
         if (!this.context.ShouldExecuteDisabledAndInErrorRules)
         {
             this.context.TraceDebug <string>("Skipping temporarily disabled rule: \"{0}.\"", rule.Name);
             return(true);
         }
         this.context.TraceDebug <string>("Including temporarily disabled rule: \"{0}\" for test message", rule.Name);
     }
     if ((rule.StateFlags & RuleStateFlags.LegacyOofRule) != (RuleStateFlags)0)
     {
         this.context.TraceDebug <string>("Skipping legacy OOF rule \"{0}.\"", rule.Name);
         return(true);
     }
     if ((rule.StateFlags & RuleStateFlags.Enabled) == (RuleStateFlags)0 && (rule.StateFlags & RuleStateFlags.OnlyWhenOOFEx) == (RuleStateFlags)0)
     {
         if (!this.context.ShouldExecuteDisabledAndInErrorRules)
         {
             this.context.TraceDebug <string>("Skipping disabled rule \"{0}.\"", rule.Name);
             return(true);
         }
         this.context.TraceDebug <string>("Including disabled rule: \"{0}\" for test message", rule.Name);
     }
     if ((rule.StateFlags & RuleStateFlags.Error) != (RuleStateFlags)0)
     {
         if (!this.context.ShouldExecuteDisabledAndInErrorRules)
         {
             this.context.TraceDebug <string>("Skipping rule \"{0},\" it is in error.", rule.Name);
             return(true);
         }
         this.context.TraceDebug <string>("Including in error rule: \"{0}\" for test message", rule.Name);
     }
     if (this.IsSafeMessage() && RuleLoader.IsJunkEmailRule(rule))
     {
         this.context.TraceDebug <string>("Skipping junk email rule \"{0}\" for this trusted message.", rule.Name);
         return(true);
     }
     return(false);
 }
コード例 #3
0
 internal static bool HasOofRule(List <Rule> rules)
 {
     if (rules == null)
     {
         return(false);
     }
     foreach (Rule rule in rules)
     {
         if (RuleLoader.IsOofRule(rule))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
        private void EnforceRulesQuota(List <Rule> rules)
        {
            int    num           = -1;
            Folder currentFolder = this.context.CurrentFolder;
            bool   flag          = false;
            ulong  rulesQuota    = this.GetRulesQuota();
            object obj           = currentFolder.TryGetProperty(FolderSchema.FolderRulesSize);
            ulong  num2;

            if (obj is PropertyError)
            {
                num2 = this.GetFolderRulesSize(currentFolder);
            }
            else
            {
                num2 = (ulong)((long)((int)obj));
            }
            for (int i = rules.Count - 1; i >= 0; i--)
            {
                if (num2 < rulesQuota)
                {
                    return;
                }
                Rule rule = rules[i];
                if (!rule.IsExtended && !RuleLoader.IsDisabled(rule))
                {
                    if (!flag && RuleLoader.IsOofRule(rule))
                    {
                        if (num == -1)
                        {
                            num = i;
                        }
                    }
                    else
                    {
                        this.context.TraceDebug <string>("EnforceRulesQuota. Disabling and mark in error rule {0}", rule.Name);
                        this.context.DisableAndMarkRuleInError(rule, rule.Actions[0].ActionType, 0, DeferredError.RuleError.FolderOverQuota);
                    }
                    num2 = this.GetFolderRulesSize(currentFolder);
                }
                if (i == 0 && !flag && num2 >= rulesQuota && num != -1)
                {
                    flag = true;
                    i    = num + 1;
                }
            }
        }
コード例 #5
0
 public IEnumerator <Rule> GetEnumerator()
 {
     foreach (Rule rule in this.rules)
     {
         if (this.evaluationResult.ExitExecution)
         {
             if (RuleLoader.IsOofRule(rule))
             {
                 yield return(rule);
             }
         }
         else
         {
             yield return(rule);
         }
     }
     yield break;
 }
コード例 #6
0
        private FolderEvaluationResult EvaluateRulesOnCurrentFolder()
        {
            FolderEvaluationResult folderEvaluationResult = null;
            string stage = ServerStrings.FolderRuleStageLoading;

            try
            {
                RuleUtil.FaultInjection((FaultInjectionLid)3353750845U);
                List <Rule> list = this.context.LoadRules();
                if (list == null)
                {
                    return(null);
                }
                stage = ServerStrings.FolderRuleStageEvaluation;
                folderEvaluationResult = new FolderEvaluationResult(this.context, list);
                if (this.context.SharedPropertiesBetweenAgents == null)
                {
                    this.context.SharedPropertiesBetweenAgents = new Dictionary <PropertyDefinition, object>();
                }
                foreach (Rule rule in folderEvaluationResult.Rules)
                {
                    this.context.CurrentRule = rule;
                    if (this.EvaluateRule(rule, folderEvaluationResult))
                    {
                        if ((rule.StateFlags & RuleStateFlags.ExitAfterExecution) != (RuleStateFlags)0)
                        {
                            this.context.TraceDebug <string>("Encountered exit level rule {0} ", rule.Name);
                            folderEvaluationResult.ExitExecution = true;
                            this.context.SharedPropertiesBetweenAgents[ItemSchema.IsStopProcessingRuleApplicable] = true;
                        }
                        if (RuleLoader.IsJunkEmailRule(rule))
                        {
                            this.context.TraceDebug <string>("Processed junk email rule {0} ", rule.Name);
                            this.context.SharedPropertiesBetweenAgents[SharedProperties.ItemMovedByJunkMailRule] = folderEvaluationResult.IsMessageMoved;
                            break;
                        }
                        if (RuleLoader.IsNeverClutterOverrideRule(rule))
                        {
                            this.context.SharedPropertiesBetweenAgents[ItemSchema.InferenceNeverClutterOverrideApplied] = true;
                        }
                        this.context.SharedPropertiesBetweenAgents[ItemSchema.ItemMovedByConversationAction] = this.context.ShouldSkipMoveRule;
                        this.context.SharedPropertiesBetweenAgents[ItemSchema.ItemMovedByRule] = folderEvaluationResult.IsMessageMoved;
                        if (!folderEvaluationResult.ShouldContinue)
                        {
                            this.context.TraceDebug("Terminate rules processing on current folder");
                            break;
                        }
                    }
                }
                this.context.CurrentRule = null;
            }
            catch (StoragePermanentException exception)
            {
                this.context.RecordError(exception, stage);
            }
            catch (ExchangeDataException exception2)
            {
                this.context.RecordError(exception2, stage);
            }
            catch (MapiPermanentException exception3)
            {
                this.context.RecordError(exception3, stage);
            }
            catch (DataValidationException exception4)
            {
                this.context.RecordError(exception4, stage);
            }
            finally
            {
                this.context.CurrentRule = null;
            }
            return(folderEvaluationResult);
        }
コード例 #7
0
        private void CreateWorkItemForForward(FolderEvaluationResult result, RuleAction.Forward action, int actionIndex)
        {
            if (ObjectClass.IsDsn(this.context.Message.ClassName) || ObjectClass.IsMdn(this.context.Message.ClassName))
            {
                this.context.TraceDebug("Do not forward for Dsn or Mdn messages");
                return;
            }
            if (this.context.Message.Sensitivity == Sensitivity.Private)
            {
                this.context.TraceDebug("Do not forward private message");
                return;
            }
            object obj = this.context.Message.TryGetProperty(MessageItemSchema.RecipientReassignmentProhibited);

            if (obj is bool && (bool)obj)
            {
                this.context.TraceDebug("Do not forward message is recipient reassignment is prohibited");
                return;
            }
            if ((this.context.Message.AutoResponseSuppress & AutoResponseSuppress.AutoReply) != AutoResponseSuppress.None && RuleLoader.IsOofRule(this.context.CurrentRule))
            {
                this.context.TraceDebug("Do not forward message is auto reply is suppressed");
                return;
            }
            if (RuleUtil.IsNullOrEmpty(action.Recipients))
            {
                this.context.TraceError("Forward recipient list is empty");
                return;
            }
            if (!this.context.LimitChecker.CheckAndIncrementForwardeeCount(action.Recipients.Length))
            {
                this.context.TraceDebug(string.Concat(new object[]
                {
                    "Rule ",
                    this.context.CurrentRule.Name,
                    " is forwarding to ",
                    action.Recipients.Length,
                    " additional recipients, which reached the accumulated forwardee limit, evaluation skipped."
                }));
                return;
            }
            result.AddWorkItem(new ForwardWorkItem(this.context, action.Recipients, action.Flags, actionIndex));
        }
コード例 #8
0
 public virtual List <Rule> LoadRules()
 {
     return(RuleLoader.LoadRules(this));
 }
コード例 #9
0
        public static List <Rule> LoadRules(IRuleEvaluationContext context)
        {
            RuleLoader ruleLoader = new RuleLoader(context);

            return(ruleLoader.Load());
        }