コード例 #1
0
 internal ContentRestrictionData(Restriction.ContentRestriction r)
 {
     this.Flags       = (int)r.Flags;
     this.PropTag     = (int)r.PropTag;
     this.MultiValued = r.MultiValued;
     this.Value       = DataConverter <PropValueConverter, PropValue, PropValueData> .GetData(r.PropValue);
 }
コード例 #2
0
        internal static List <SmtpAddress> LoadNeverClutterList(Rule rule)
        {
            List <SmtpAddress> list = new List <SmtpAddress>();

            if (rule != null)
            {
                Restriction.OrRestriction orRestriction = rule.Condition as Restriction.OrRestriction;
                if (orRestriction != null)
                {
                    foreach (Restriction restriction in orRestriction.Restrictions)
                    {
                        Restriction.ContentRestriction contentRestriction = restriction as Restriction.ContentRestriction;
                        if (contentRestriction != null && contentRestriction.PropTag == PropTag.SenderSmtpAddress)
                        {
                            string      @string = contentRestriction.PropValue.GetString();
                            SmtpAddress item    = new SmtpAddress(@string);
                            if (item.IsValidAddress)
                            {
                                list.Add(item);
                            }
                        }
                    }
                }
            }
            return(list);
        }
コード例 #3
0
        // Token: 0x060002E9 RID: 745 RVA: 0x00012288 File Offset: 0x00010488
        private QueryFilter TranslateContentRestriction(Restriction.ContentRestriction restriction)
        {
            MatchOptions matchOptions;

            if ((restriction.Flags & ContentFlags.SubString) == ContentFlags.SubString)
            {
                matchOptions = MatchOptions.SubString;
            }
            else
            {
                if ((restriction.Flags & ContentFlags.Prefix) != ContentFlags.Prefix)
                {
                    throw new NspiException(NspiStatus.TooComplex, "restriction.Flags not SubString or Prefix");
                }
                matchOptions = MatchOptions.Prefix;
            }
            object obj  = this.ConvertValue(restriction.PropValue);
            string text = obj as string;

            if (text != null)
            {
                return(new TextFilter(QueryFilterBuilder.PropTagToPropertyDefinition(restriction.PropTag), text, matchOptions, MatchFlags.Default));
            }
            byte[] array = obj as byte[];
            if (array != null)
            {
                return(new BinaryFilter(QueryFilterBuilder.PropTagToPropertyDefinition(restriction.PropTag), array, matchOptions, MatchFlags.Default));
            }
            throw new NspiException(NspiStatus.TooComplex, "Unknown PropValue");
        }
コード例 #4
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");
     }
 }
コード例 #5
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);
        }
コード例 #6
0
 protected static Restriction CreateORStringContentRestriction(string[] values, PropTag propertyTag, ContentFlags flags)
 {
     if (values.Length > 1)
     {
         Restriction[] array = new Restriction.ContentRestriction[values.Length];
         for (int i = 0; i < values.Length; i++)
         {
             array[i] = Restriction.Content(propertyTag, values[i], flags);
         }
         return(Restriction.Or(array));
     }
     if (values.Length == 1)
     {
         return(Condition.CreateStringContentRestriction(propertyTag, values[0], flags));
     }
     return(null);
 }
コード例 #7
0
 protected static Restriction CreateSubjectOrBodyRestriction(string[] values)
 {
     Restriction[] array = new Restriction.ContentRestriction[values.Length * 2];
     if (values.Length > 0)
     {
         int i   = 0;
         int num = 0;
         while (i < values.Length)
         {
             array[num]     = Condition.CreateStringContentRestriction(PropTag.Subject, values[i], ContentFlags.SubString | ContentFlags.IgnoreCase);
             array[num + 1] = Condition.CreateStringContentRestriction(PropTag.Body, values[i], ContentFlags.SubString | ContentFlags.IgnoreCase);
             i++;
             num += 2;
         }
         return(Restriction.Or(array));
     }
     return(null);
 }
コード例 #8
0
        private static void DumpRestriction(StringBuilder sb, Restriction restriction)
        {
            if (restriction == null)
            {
                return;
            }
            sb.Append("(");
            Restriction.ResType type = restriction.Type;
            switch (type)
            {
            case Restriction.ResType.And:
            {
                Restriction.AndRestriction andRestriction = (Restriction.AndRestriction)restriction;
                sb.Append("AND ");
                foreach (Restriction restriction2 in andRestriction.Restrictions)
                {
                    GetFolderRestriction.DumpRestriction(sb, restriction2);
                }
                break;
            }

            case Restriction.ResType.Or:
            {
                Restriction.OrRestriction orRestriction = (Restriction.OrRestriction)restriction;
                sb.Append("OR ");
                foreach (Restriction restriction3 in orRestriction.Restrictions)
                {
                    GetFolderRestriction.DumpRestriction(sb, restriction3);
                }
                break;
            }

            case Restriction.ResType.Not:
            {
                Restriction.NotRestriction notRestriction = (Restriction.NotRestriction)restriction;
                sb.Append("NOT ");
                GetFolderRestriction.DumpRestriction(sb, notRestriction.Restriction);
                break;
            }

            case Restriction.ResType.Content:
            {
                Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction;
                sb.AppendFormat("CONTENT flags:{0} mv:{1} propTag:{2:X} propValue:(", contentRestriction.Flags, contentRestriction.MultiValued, contentRestriction.PropTag);
                GetFolderRestriction.DumpPropValue(sb, contentRestriction.PropValue);
                sb.Append(")");
                break;
            }

            case Restriction.ResType.Property:
            {
                Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction;
                sb.AppendFormat("PROPERTY Op:{0}, propTag:{1:X} propValue:", propertyRestriction.Op, propertyRestriction.PropTag);
                GetFolderRestriction.DumpPropValue(sb, propertyRestriction.PropValue);
                break;
            }

            case Restriction.ResType.CompareProps:
            {
                Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction;
                sb.AppendFormat("COMPPROPS Op:{0} propTag1:{1:X} propTag2:{2:X}", comparePropertyRestriction.Op, comparePropertyRestriction.TagLeft, comparePropertyRestriction.TagRight);
                break;
            }

            case Restriction.ResType.BitMask:
            {
                Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction;
                sb.AppendFormat("BITMASK Bmr:{0} Mask:{1:X} propTag:{2:X}", bitMaskRestriction.Bmr, bitMaskRestriction.Mask, bitMaskRestriction.Tag);
                break;
            }

            case Restriction.ResType.Size:
            {
                Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction;
                sb.AppendFormat("SIZE propTag:{0:X} Op:{1} size:{2}", sizeRestriction.Tag, sizeRestriction.Op, sizeRestriction.Size);
                break;
            }

            case Restriction.ResType.Exist:
            {
                Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction;
                sb.AppendFormat("EXIST propTag:{0:X}", existRestriction.Tag);
                break;
            }

            case Restriction.ResType.SubRestriction:
            {
                Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction;
                sb.Append("SUBRESTRICTION ");
                GetFolderRestriction.DumpRestriction(sb, subRestriction.Restriction);
                break;
            }

            case Restriction.ResType.Comment:
            {
                Restriction.CommentRestriction commentRestriction = (Restriction.CommentRestriction)restriction;
                sb.AppendFormat("COMMENT values:{0} ", commentRestriction.Values.Length);
                foreach (PropValue v in commentRestriction.Values)
                {
                    GetFolderRestriction.DumpPropValue(sb, v);
                }
                GetFolderRestriction.DumpRestriction(sb, commentRestriction.Restriction);
                break;
            }

            case Restriction.ResType.Count:
            {
                Restriction.CountRestriction countRestriction = (Restriction.CountRestriction)restriction;
                sb.AppendFormat("COUNT {0} ", countRestriction.Count);
                GetFolderRestriction.DumpRestriction(sb, countRestriction.Restriction);
                break;
            }

            default:
                switch (type)
                {
                case Restriction.ResType.True:
                    sb.Append("TRUE");
                    break;

                case Restriction.ResType.False:
                    sb.Append("FALSE");
                    break;

                default:
                    sb.AppendFormat("<UNKNOWN RESTYPE:{0}>", restriction.Type);
                    break;
                }
                break;
            }
            sb.Append(")");
        }
コード例 #9
0
        internal static Restriction ConvertFromMapiRestriction(Restriction restriction, int codePage)
        {
            if (restriction == null)
            {
                return(null);
            }
            switch (restriction.Type)
            {
            case Restriction.ResType.And:
                return(new AndRestriction((from r in ((Restriction.AndRestriction)restriction).Restrictions
                                           select ConvertHelper.ConvertFromMapiRestriction(r, codePage)).ToArray <Restriction>()));

            case Restriction.ResType.Or:
                return(new OrRestriction((from r in ((Restriction.OrRestriction)restriction).Restrictions
                                          select ConvertHelper.ConvertFromMapiRestriction(r, codePage)).ToArray <Restriction>()));

            case Restriction.ResType.Not:
                return(new NotRestriction(ConvertHelper.ConvertFromMapiRestriction((Restriction.NotRestriction)restriction, codePage)));

            case Restriction.ResType.Content:
            {
                Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction;
                return(new ContentRestriction((FuzzyLevel)contentRestriction.Flags, ConvertHelper.ConvertFromMapiPropTag(contentRestriction.PropTag), new PropertyValue?(ConvertHelper.ConvertFromMapiPropValue(contentRestriction.PropValue, codePage))));
            }

            case Restriction.ResType.Property:
            {
                Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction;
                RelationOperator relop       = ConvertHelper.ConvertFromMapiRelOp(propertyRestriction.Op);
                PropertyTag      propertyTag = ConvertHelper.ConvertFromMapiPropTag(propertyRestriction.PropTag);
                PropertyValue    value       = ConvertHelper.ConvertFromMapiPropValue(propertyRestriction.PropValue, codePage);
                return(new PropertyRestriction(relop, propertyTag, new PropertyValue?(value)));
            }

            case Restriction.ResType.CompareProps:
            {
                Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction;
                return(new ComparePropsRestriction(ConvertHelper.ConvertFromMapiRelOp(comparePropertyRestriction.Op), ConvertHelper.ConvertFromMapiPropTag(comparePropertyRestriction.TagLeft), ConvertHelper.ConvertFromMapiPropTag(comparePropertyRestriction.TagRight)));
            }

            case Restriction.ResType.BitMask:
            {
                Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction;
                return(new BitMaskRestriction(ConvertHelper.ConvertFromMapiRelBmr(bitMaskRestriction.Bmr), ConvertHelper.ConvertFromMapiPropTag(bitMaskRestriction.Tag), (uint)bitMaskRestriction.Mask));
            }

            case Restriction.ResType.Size:
            {
                Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction;
                return(new SizeRestriction(ConvertHelper.ConvertFromMapiRelOp(sizeRestriction.Op), ConvertHelper.ConvertFromMapiPropTag(sizeRestriction.Tag), (uint)sizeRestriction.Size));
            }

            case Restriction.ResType.Exist:
            {
                Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction;
                return(new ExistsRestriction(ConvertHelper.ConvertFromMapiPropTag(existRestriction.Tag)));
            }

            case Restriction.ResType.SubRestriction:
            {
                Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction;
                return(new SubRestriction((SubRestrictionType)subRestriction.Type, ConvertHelper.ConvertFromMapiRestriction(subRestriction.Restriction, codePage)));
            }

            default:
                throw new NspiException(NspiStatus.InvalidParameter, string.Format("Invalid MAPI restriction type: {0}", restriction));
            }
        }
コード例 #10
0
 internal void WriteRestriction(Restriction restriction)
 {
     if (restriction is Restriction.BitMaskRestriction)
     {
         Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction;
         this.WriteInt(6);
         this.WriteInt((int)bitMaskRestriction.Bmr);
         this.WriteInt((int)bitMaskRestriction.Tag);
         this.WriteInt(bitMaskRestriction.Mask);
         return;
     }
     if (restriction is Restriction.AndRestriction)
     {
         this.WriteInt(0);
         Restriction.AndRestriction andRestriction = (Restriction.AndRestriction)restriction;
         this.WriteInt(andRestriction.Restrictions.Length);
         foreach (Restriction restriction2 in andRestriction.Restrictions)
         {
             this.WriteRestriction(restriction2);
         }
         return;
     }
     if (restriction is Restriction.OrRestriction)
     {
         this.WriteInt(1);
         Restriction.OrRestriction orRestriction = (Restriction.OrRestriction)restriction;
         this.WriteInt(orRestriction.Restrictions.Length);
         foreach (Restriction restriction3 in orRestriction.Restrictions)
         {
             this.WriteRestriction(restriction3);
         }
         return;
     }
     if (restriction is Restriction.NotRestriction)
     {
         Restriction.NotRestriction notRestriction = (Restriction.NotRestriction)restriction;
         this.WriteInt(2);
         this.WriteRestriction(notRestriction.Restriction);
         return;
     }
     if (restriction is Restriction.ContentRestriction)
     {
         Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction;
         this.WriteInt(3);
         this.WriteInt((int)contentRestriction.Flags);
         this.WriteInt((int)contentRestriction.PropTag);
         this.WritePropValue(contentRestriction.PropValue.PropTag, contentRestriction.PropValue.Value);
         return;
     }
     if (restriction is Restriction.PropertyRestriction)
     {
         Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction;
         this.WriteInt(4);
         this.WriteInt((int)propertyRestriction.Op);
         this.WriteInt((int)propertyRestriction.PropTag);
         this.WritePropValue(propertyRestriction.PropValue.PropTag, propertyRestriction.PropValue.Value);
         return;
     }
     if (restriction is Restriction.ComparePropertyRestriction)
     {
         Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction;
         this.WriteInt(5);
         this.WriteInt((int)comparePropertyRestriction.Op);
         this.WriteInt((int)comparePropertyRestriction.TagLeft);
         this.WriteInt((int)comparePropertyRestriction.TagRight);
         return;
     }
     if (restriction is Restriction.ExistRestriction)
     {
         Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction;
         this.WriteInt(8);
         this.WriteInt((int)existRestriction.Tag);
         return;
     }
     if (restriction is Restriction.AttachmentRestriction)
     {
         Restriction.AttachmentRestriction attachmentRestriction = (Restriction.AttachmentRestriction)restriction;
         this.WriteInt(9);
         this.WriteInt(236126221);
         this.WriteRestriction(attachmentRestriction.Restriction);
         return;
     }
     if (restriction is Restriction.RecipientRestriction)
     {
         Restriction.RecipientRestriction recipientRestriction = (Restriction.RecipientRestriction)restriction;
         this.WriteInt(9);
         this.WriteInt(236060685);
         this.WriteRestriction(recipientRestriction.Restriction);
         return;
     }
     throw new ArgumentException(ServerStrings.ExUnknownRestrictionType, "restriction");
 }
コード例 #11
0
ファイル: RuleWriter.cs プロジェクト: YHZX2013/exchange_diff
        private void WriteRestriction(Restriction restriction)
        {
            this.writer.WriteStartElement("Restriction");
            if (restriction != null)
            {
                Restriction.ResType type = restriction.Type;
                this.writer.WriteAttributeString("Type", type.ToString());
                Restriction.ResType resType = type;
                switch (resType)
                {
                case Restriction.ResType.And:
                    this.WriteRestrictions("And", ((Restriction.AndRestriction)restriction).Restrictions);
                    break;

                case Restriction.ResType.Or:
                    this.WriteRestrictions("Or", ((Restriction.OrRestriction)restriction).Restrictions);
                    break;

                case Restriction.ResType.Not:
                    this.writer.WriteStartElement("Not");
                    this.WriteRestriction(((Restriction.NotRestriction)restriction).Restriction);
                    this.writer.WriteEndElement();
                    break;

                case Restriction.ResType.Content:
                {
                    Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction;
                    this.writer.WriteAttributeString("ContentFlags", RuleWriter.EnumToString(contentRestriction.Flags));
                    this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(contentRestriction.PropTag));
                    this.writer.WriteAttributeString("MultiValued", contentRestriction.MultiValued.ToString());
                    this.WritePropValue(contentRestriction.PropValue);
                    break;
                }

                case Restriction.ResType.Property:
                {
                    Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction;
                    this.writer.WriteAttributeString("Operation", propertyRestriction.Op.ToString());
                    this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(propertyRestriction.PropTag));
                    this.writer.WriteAttributeString("MultiValued", propertyRestriction.MultiValued.ToString());
                    this.WritePropValue(propertyRestriction.PropValue);
                    break;
                }

                case Restriction.ResType.CompareProps:
                {
                    Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction;
                    this.writer.WriteAttributeString("Operation", comparePropertyRestriction.Op.ToString());
                    this.writer.WriteAttributeString("PropTagLeft", RuleWriter.EnumToString(comparePropertyRestriction.TagLeft));
                    this.writer.WriteAttributeString("PropTagRight", RuleWriter.EnumToString(comparePropertyRestriction.TagRight));
                    break;
                }

                case Restriction.ResType.BitMask:
                {
                    Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction;
                    this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(bitMaskRestriction.Tag));
                    this.writer.WriteAttributeString("Operation", bitMaskRestriction.Bmr.ToString());
                    this.writer.WriteAttributeString("Mask", bitMaskRestriction.Mask.ToString("X08"));
                    break;
                }

                case Restriction.ResType.Size:
                {
                    Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction;
                    this.writer.WriteAttributeString("Operation", sizeRestriction.Op.ToString());
                    this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(sizeRestriction.Tag));
                    this.writer.WriteAttributeString("Size", sizeRestriction.Size.ToString("X08"));
                    break;
                }

                case Restriction.ResType.Exist:
                {
                    Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction;
                    this.writer.WriteAttributeString("PropTag", RuleWriter.EnumToString(existRestriction.Tag));
                    break;
                }

                case Restriction.ResType.SubRestriction:
                {
                    Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction;
                    this.writer.WriteAttributeString("SubType", subRestriction.GetType().Name);
                    this.WriteRestriction(subRestriction.Restriction);
                    break;
                }

                case Restriction.ResType.Comment:
                {
                    Restriction.CommentRestriction commentRestriction = (Restriction.CommentRestriction)restriction;
                    this.WritePropValues("Comment", commentRestriction.Values);
                    this.WriteRestriction(commentRestriction.Restriction);
                    break;
                }

                case Restriction.ResType.Count:
                {
                    Restriction.CountRestriction countRestriction = (Restriction.CountRestriction)restriction;
                    this.writer.WriteAttributeString("Count", countRestriction.Count.ToString());
                    this.WriteRestriction(countRestriction.Restriction);
                    break;
                }

                default:
                    switch (resType)
                    {
                    }
                    this.writer.WriteAttributeString("Error", "Unsupported restriction type: " + type.ToString());
                    break;
                }
            }
            this.writer.WriteEndElement();
        }