private static bool EvaluateAttachmentRestriction(Restriction.AttachmentRestriction restriction, IRuleEvaluationContext context) { context.TraceFunction("AttachmentRestriction"); context.NestedLevel++; bool flag = false; foreach (AttachmentHandle handle in context.Message.AttachmentCollection) { using (Attachment attachment = context.Message.AttachmentCollection.Open(handle)) { context.TraceFunction <string>("Attachment {0}", attachment.DisplayName); using (IRuleEvaluationContext attachmentContext = context.GetAttachmentContext(attachment)) { if (RestrictionEvaluator.Evaluate(restriction.Restriction, attachmentContext)) { flag = true; break; } } } } context.NestedLevel--; context.TraceFunction <bool>("AttachmentRestriction evaluates to {0}", flag); return(flag); }
private static bool EvaluatePropertyRestriction(Restriction.PropertyRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidatePropertyRestriction(restriction); PropTag propTag = restriction.PropTag; if (restriction.MultiValued) { propTag = RuleUtil.GetMultiValuePropTag(propTag); } context.TraceFunction <PropTag, Restriction.RelOp, object>("PropertyRestriction [{0}] {1} [{2}]", propTag, restriction.Op, restriction.PropValue.Value); object obj = context[propTag]; bool flag; if (obj == null) { flag = false; } else if (restriction.MultiValued) { flag = RestrictionEvaluator.CompareMultiValueWithValue(context, RuleUtil.GetSingleValuePropTag(restriction.PropTag), restriction.Op, obj, restriction.PropValue.Value); } else if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag)) { flag = RestrictionEvaluator.CompareValueWithMultiValue(context, restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } else { flag = context.CompareSingleValue(restriction.PropTag, restriction.Op, obj, restriction.PropValue.Value); } context.TraceFunction <bool, object>("PropertyRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }
private static bool EvaluateContentRestriction(Restriction.ContentRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateContentRestriction(restriction); PropTag propTag = restriction.PropTag; if (restriction.MultiValued) { propTag = RuleUtil.GetMultiValuePropTag(propTag); } context.TraceFunction <PropTag, ContentFlags, object>("ContentRestriction tag [{0}] flags [{1}] value [{2}]", propTag, restriction.Flags, restriction.PropValue.Value); object obj = context[propTag]; bool flag; if (obj == null) { flag = false; } else if (restriction.MultiValued) { flag = RestrictionEvaluator.MatchMultiValueWithPattern(context, restriction.PropTag, obj, restriction.PropValue.Value, restriction.Flags); } else if (RuleUtil.IsTextProp(restriction.PropTag)) { flag = RestrictionEvaluator.MatchString(context.LimitChecker, context.CultureInfo, (string)obj, (string)restriction.PropValue.Value, restriction.Flags); } else { if (!RuleUtil.IsBinaryProp(restriction.PropTag)) { throw new InvalidRuleException(string.Format("Content restriction can't be used on tag {0}", restriction.PropTag)); } flag = RestrictionEvaluator.MatchByteArray(context.LimitChecker, (byte[])obj, (byte[])restriction.PropValue.Value, restriction.Flags); } context.TraceFunction <bool, object>("ContentRestriction Evaluated to {0} with property value [{1}]", flag, obj); if (!flag && propTag == PropTag.SenderSearchKey) { object obj2 = context[PropTag.SenderSmtpAddress]; if (obj2 != null) { string @string = CTSGlobals.AsciiEncoding.GetString((byte[])restriction.PropValue.Value); ContentFlags contentFlags = ContentFlags.SubString | ContentFlags.IgnoreCase; context.TraceFunction("No match found in SenderSearchKey, searching for string in SenderSmtpAddress..."); context.TraceFunction <PropTag, ContentFlags, string>("ContentRestriction tag [{0}] flags [{1}] value [{2}]", PropTag.SenderSmtpAddress, contentFlags, @string); flag = RestrictionEvaluator.MatchString(context.LimitChecker, context.CultureInfo, (string)obj2, @string, contentFlags); } } return(flag); }
private static bool EvaluateComparePropertyRestriction(Restriction.ComparePropertyRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateComparePropertyRestriction(restriction); object obj = context[restriction.TagLeft]; object obj2 = context[restriction.TagRight]; context.TraceFunction <PropTag, Restriction.RelOp, PropTag>("ComparePropertyRestriction [{0}] {1} [{2}]", restriction.TagLeft, restriction.Op, restriction.TagRight); bool flag = false; if (obj != null && obj2 != null) { flag = context.CompareSingleValue(restriction.TagLeft, restriction.Op, obj, obj2); } context.TraceFunction <object, Restriction.RelOp, object, bool>("[{0}] {1} [{2}] evaluated to {3}", obj, restriction.Op, obj2, flag); return(flag); }
private static bool EvaluateExistRestriction(Restriction.ExistRestriction restriction, IRuleEvaluationContext context) { object obj = context[restriction.Tag]; bool flag = obj != null; context.TraceFunction <PropTag, bool>("ExistRestriction on tag [{0}] evaluted to {1}", restriction.Tag, flag); return(flag); }
private static bool EvaluateNotRestriction(Restriction.NotRestriction restriction, IRuleEvaluationContext context) { context.NestedLevel++; bool flag = !RestrictionEvaluator.Evaluate(restriction.Restriction, context); context.NestedLevel--; context.TraceFunction <bool>("NotRestriction evaluated to {0}", flag); return(flag); }
private static bool EvaluateSizeRestriction(Restriction.SizeRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateSizeRestriction(restriction); context.TraceFunction <PropTag, Restriction.RelOp, int>("SizeRestriction [{0}] {1} [{2}]", restriction.Tag, restriction.Op, restriction.Size); PropType type = restriction.Tag.ValueType(); int num = 0; bool flag = false; object obj = null; if (RuleUtil.GetPropTypeSize(type, out num)) { flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, num.CompareTo(restriction.Size)); } else if (RuleUtil.IsMultiValueTag(restriction.Tag)) { obj = context[restriction.Tag]; object[] array = obj as object[]; if (array != null) { foreach (object value in array) { int size = RuleUtil.GetSize(value); if (RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size.CompareTo(restriction.Size))) { flag = true; break; } } } } else { obj = context[restriction.Tag]; int size2 = RuleUtil.GetSize(obj); flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size2.CompareTo(restriction.Size)); } context.TraceFunction <bool, object>("SizeRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }
private static bool EvaluateRecipientRestriction(Restriction.RecipientRestriction restriction, IRuleEvaluationContext context) { context.TraceFunction("RecipientRestriction"); context.NestedLevel++; bool flag = false; foreach (Recipient recipient in context.Message.Recipients) { using (IRuleEvaluationContext recipientContext = context.GetRecipientContext(recipient)) { context.TraceFunction <string>("Recipient {0}", recipient.Participant.DisplayName); if (RestrictionEvaluator.Evaluate(restriction.Restriction, recipientContext)) { flag = true; break; } } } context.NestedLevel--; context.TraceFunction <bool>("RecipientRestriction evaluates to {0}", flag); return(flag); }
private static bool EvaluateOrRestriction(Restriction.OrRestriction restriction, IRuleEvaluationContext context) { context.NestedLevel++; bool flag = false; foreach (Restriction restriction2 in restriction.Restrictions) { if (RestrictionEvaluator.Evaluate(restriction2, context)) { flag = true; break; } } context.NestedLevel--; context.TraceFunction <bool>("OrRestriction evaluated to {0}", flag); return(flag); }
private static bool EvaluateBitMaskRestriction(Restriction.BitMaskRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateBitMaskRestriction(restriction); object obj = context[restriction.Tag]; if (obj is int) { int num = (int)obj; bool flag; if ((num & restriction.Mask) != 0) { flag = (restriction.Bmr == Restriction.RelBmr.NotEqualToZero); } else { flag = (restriction.Bmr == Restriction.RelBmr.EqualToZero); } context.TraceFunction <object, Restriction.RelBmr, int, bool>("BitMaskRestriction [{0}] {1} [{2}] evaluates to {3}", obj, restriction.Bmr, restriction.Mask, flag); return(flag); } context.TraceError <object>("Invalid BitMaskRestriction value: {0}", obj); return(false); }
public static bool Evaluate(Restriction restriction, IRuleEvaluationContext context) { if (restriction == null) { context.TraceDebug <string>("Empty restriction evaluated to true in rule {0}", context.CurrentRule.Name); return(true); } Restriction.ResType type = restriction.Type; switch (type) { case Restriction.ResType.And: return(RestrictionEvaluator.EvaluateAndRestriction((Restriction.AndRestriction)restriction, context)); case Restriction.ResType.Or: return(RestrictionEvaluator.EvaluateOrRestriction((Restriction.OrRestriction)restriction, context)); case Restriction.ResType.Not: return(RestrictionEvaluator.EvaluateNotRestriction((Restriction.NotRestriction)restriction, context)); case Restriction.ResType.Content: return(RestrictionEvaluator.EvaluateContentRestriction((Restriction.ContentRestriction)restriction, context)); case Restriction.ResType.Property: return(RestrictionEvaluator.EvaluatePropertyRestriction((Restriction.PropertyRestriction)restriction, context)); case Restriction.ResType.CompareProps: return(RestrictionEvaluator.EvaluateComparePropertyRestriction((Restriction.ComparePropertyRestriction)restriction, context)); case Restriction.ResType.BitMask: return(RestrictionEvaluator.EvaluateBitMaskRestriction((Restriction.BitMaskRestriction)restriction, context)); case Restriction.ResType.Size: return(RestrictionEvaluator.EvaluateSizeRestriction((Restriction.SizeRestriction)restriction, context)); case Restriction.ResType.Exist: return(RestrictionEvaluator.EvaluateExistRestriction((Restriction.ExistRestriction)restriction, context)); case Restriction.ResType.SubRestriction: if (restriction is Restriction.AttachmentRestriction) { return(RestrictionEvaluator.EvaluateAttachmentRestriction((Restriction.AttachmentRestriction)restriction, context)); } if (restriction is Restriction.RecipientRestriction) { return(RestrictionEvaluator.EvaluateRecipientRestriction((Restriction.RecipientRestriction)restriction, context)); } throw new InvalidRuleException(string.Format("SubRestriction Type {0} is not supported!", restriction.GetType())); case Restriction.ResType.Comment: return(RestrictionEvaluator.EvaluateCommentRestriction((Restriction.CommentRestriction)restriction, context)); case Restriction.ResType.Count: return(RestrictionEvaluator.EvaluateCountRestriction((Restriction.CountRestriction)restriction, context)); default: switch (type) { case Restriction.ResType.True: context.TraceFunction("True Restriction"); return(true); case Restriction.ResType.False: context.TraceFunction("False Restriction"); return(false); default: throw new InvalidRuleException(string.Format("Restriction Type {0} is not supported!", restriction.Type)); } break; } }