private static bool MatchMultiValueWithPattern(IRuleEvaluationContext context, PropTag tag, object content, object pattern, ContentFlags flags) { if (RuleUtil.IsTextProp(tag)) { string[] array = (string[])content; string pattern2 = (string)pattern; foreach (string content2 in array) { if (RestrictionEvaluator.MatchString(context.LimitChecker, context.CultureInfo, content2, pattern2, flags)) { return(true); } } } else if (RuleUtil.IsBinaryProp(tag)) { byte[][] array3 = (byte[][])content; byte[] pattern3 = pattern as byte[]; foreach (byte[] content3 in array3) { if (RestrictionEvaluator.MatchByteArray(context.LimitChecker, content3, pattern3, flags)) { return(true); } } } return(false); }
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); }