예제 #1
0
 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);
 }
예제 #2
0
 private static void ValidateContentRestriction(Restriction.ContentRestriction restriction)
 {
     if (!RuleUtil.IsTextProp(restriction.PropTag) && !RuleUtil.IsBinaryProp(restriction.PropTag))
     {
         throw new InvalidRuleException(string.Format("Content Restriction is not supported on tag {0}", restriction.PropTag));
     }
     if (!RuleUtil.IsSameType(restriction.PropTag, restriction.PropValue.PropTag))
     {
         throw new InvalidRuleException("Tag and value are of different type");
     }
     if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag))
     {
         throw new InvalidRuleException("Content Restriction does not support multi-valued value");
     }
 }
예제 #3
0
        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);
        }