Beispiel #1
0
        private static ProxyAddress GetLegacyProxyAddress(IRuleEvaluationContext context, byte[] entryId)
        {
            if (entryId.Length == 0)
            {
                context.TraceDebug("GetLegacyProxyAddress: entry ID is zero-length");
                return(null);
            }
            ParticipantEntryId participantEntryId = ParticipantEntryId.TryFromEntryId(entryId);

            context.TraceDebug <string>("GetLegacyProxyAddress: entry ID is {0}", participantEntryId.GetType().Name);
            Participant.Builder builder = new Participant.Builder();
            builder.SetPropertiesFrom(participantEntryId);
            Participant participant  = builder.ToParticipant();
            string      routingType  = participant.RoutingType;
            string      emailAddress = participant.EmailAddress;

            if (routingType != "EX" || string.IsNullOrEmpty(emailAddress))
            {
                context.TraceDebug <string, string>("GetLegacyProxyAddress: returning null, address is {0}:{1}", routingType ?? "(null)", emailAddress ?? "(null)");
                return(null);
            }
            ProxyAddress proxyAddress = ProxyAddress.Parse(routingType, emailAddress);

            if (proxyAddress is InvalidProxyAddress)
            {
                context.TraceDebug <string>("GetLegacyProxyAddress: legacyDN {0} is not valid", emailAddress);
                return(null);
            }
            context.TraceDebug <string>("GetLegacyProxyAddress: returning EX:{0}", emailAddress);
            return(proxyAddress);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
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);
 }
Beispiel #4
0
        internal static bool SetRecipients(IRuleEvaluationContext context, MessageItem message, IList <ProxyAddress> senderAddresses, AdrEntry[] recipients, bool promoteToEnvelope)
        {
            message.Recipients.Clear();
            int num = 0;

            foreach (AdrEntry entry in recipients)
            {
                Participant participant = RuleUtil.ParticipantFromAddressEntry(entry);
                if (participant != null)
                {
                    if (promoteToEnvelope && RuleUtil.IsRecipientSameAsSender(senderAddresses, participant.EmailAddress))
                    {
                        context.TraceDebug <string>("Skipping recipient {0} because that was the original sender.", participant.EmailAddress);
                    }
                    else
                    {
                        context.TraceDebug <Participant>("Adding recipient {0}.", participant);
                        Recipient recipient = message.Recipients.Add(participant);
                        recipient[ItemSchema.Responsibility] = promoteToEnvelope;
                        num++;
                    }
                }
            }
            return(num > 0);
        }
 public DelegateWorkItem(IRuleEvaluationContext context, AdrEntry[] recipients, int actionIndex) : base(context, actionIndex)
 {
     if (RuleUtil.IsNullOrEmpty(recipients))
     {
         throw new ArgumentException("Delegate recipient list is empty");
     }
     this.recipients = recipients;
 }
Beispiel #6
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>();
 }
Beispiel #7
0
 public ForwardWorkItem(IRuleEvaluationContext context, AdrEntry[] recipients, RuleAction.Forward.ActionFlags flags, int actionIndex) : base(context, actionIndex)
 {
     if (RuleUtil.IsNullOrEmpty(recipients))
     {
         throw new ArgumentException("Forward recipient list is empty");
     }
     this.flags      = flags;
     this.recipients = recipients;
 }
Beispiel #8
0
        private static bool CompareValueWithMultiValue(IRuleEvaluationContext context, PropTag tag, Restriction.RelOp op, object messageValue, object ruleValueObject)
        {
            Array array = (Array)ruleValueObject;
            bool  flag  = false;

            foreach (object y in array)
            {
                flag = context.CompareSingleValue(tag, Restriction.RelOp.Equal, messageValue, y);
                if (flag)
                {
                    break;
                }
            }
            if (op == Restriction.RelOp.NotEqual)
            {
                flag = !flag;
            }
            return(flag);
        }
Beispiel #9
0
        internal static bool IsSameUser(IRuleEvaluationContext context, IADRecipientCache recipientCache, ProxyAddress addressToResolve, ProxyAddress addressToCompare)
        {
            if (addressToResolve == null || addressToResolve is InvalidProxyAddress)
            {
                return(false);
            }
            if (addressToCompare == null || addressToCompare is InvalidProxyAddress)
            {
                return(false);
            }
            if (addressToResolve.Equals(addressToCompare))
            {
                return(true);
            }
            ADRawEntry data = recipientCache.FindAndCacheRecipient(addressToResolve).Data;

            if (data == null)
            {
                context.TraceDebug <string>("Message recipient {0} did not resolve, IsSameUser returning false.", addressToResolve.ToString());
                return(false);
            }
            string text = (string)data[ADRecipientSchema.LegacyExchangeDN];

            if (text != null && addressToCompare.ValueString.Equals(text, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)data[ADRecipientSchema.EmailAddresses];

            if (proxyAddressCollection == null)
            {
                return(false);
            }
            foreach (ProxyAddress proxyAddress in proxyAddressCollection)
            {
                if (addressToCompare.ValueString.Equals(proxyAddress.ValueString, StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #10
0
        internal static bool IsMemberOf(IRuleEvaluationContext context, byte[] recipientEntryId, byte[] groupEntryId)
        {
            ProxyAddress legacyProxyAddress = RuleUtil.GetLegacyProxyAddress(context, recipientEntryId);

            if (legacyProxyAddress == null)
            {
                context.TraceDebug("IsMemberOf: unable to get legacy DN for recipient.");
                return(false);
            }
            ProxyAddress legacyProxyAddress2 = RuleUtil.GetLegacyProxyAddress(context, groupEntryId);

            if (legacyProxyAddress2 == null)
            {
                context.TraceDebug("IsMemberOf: unable to get address for group, this rule is in error.");
                throw new InvalidRuleException(ServerStrings.FolderRuleErrorInvalidGroup(BitConverter.ToString(groupEntryId)));
            }
            context.TraceDebug <string, string>("IsMemberOf: Recipient=\"{0}\" Group=\"{1}\"", legacyProxyAddress.AddressString, legacyProxyAddress2.AddressString);
            Result <ADRawEntry> result = context.RecipientCache.FindAndCacheRecipient(legacyProxyAddress);

            if (result.Data == null)
            {
                context.TraceDebug("Recipient doesn't exist in AD");
                context.RecordError(ServerStrings.FolderRuleErrorGroupDoesNotResolve(legacyProxyAddress.ToString()));
                return(false);
            }
            bool result2;

            try
            {
                IsMemberOfResolver <string> isMemberOfResolver = context.IsMemberOfResolver;
                bool flag = isMemberOfResolver.IsMemberOf(context.RecipientCache.ADSession, result.Data.Id, legacyProxyAddress2.AddressString);
                context.TraceDebug <bool>("IsMemberOf: {0}", flag);
                result2 = flag;
            }
            catch (AddressBookTransientException exception)
            {
                context.RecordError(exception, ServerStrings.FolderRuleStageEvaluation);
                result2 = false;
            }
            return(result2);
        }
Beispiel #11
0
        internal static bool SetRecipients(IRuleEvaluationContext context, MessageItem message, IList <ProxyAddress> senderAddresses, RecipientCollection recipients, bool promoteToEnvelope)
        {
            int num = 0;

            message.Recipients.Clear();
            foreach (Recipient recipient in recipients)
            {
                if (promoteToEnvelope && RuleUtil.IsRecipientSameAsSender(senderAddresses, recipient.Participant.EmailAddress))
                {
                    context.TraceDebug <string>("Skipping recipient {0} because that was the original sender.", recipient.Participant.EmailAddress);
                }
                else
                {
                    context.TraceDebug <string>("Adding recipient {0}.", recipient.Participant.ToString());
                    Recipient recipient2 = message.Recipients.Add(recipient.Participant, recipient.RecipientItemType);
                    recipient2[ItemSchema.Responsibility] = promoteToEnvelope;
                    num++;
                }
            }
            return(num > 0);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        private static bool CompareMultiValueWithValue(IRuleEvaluationContext context, PropTag tag, Restriction.RelOp op, object messageValueObject, object ruleValue)
        {
            Array array = (Array)messageValueObject;
            bool  flag  = false;

            foreach (object x in array)
            {
                flag = context.CompareSingleValue(tag, op, x, ruleValue);
                if (flag)
                {
                    if (op != Restriction.RelOp.NotEqual)
                    {
                        break;
                    }
                }
                else if (op == Restriction.RelOp.NotEqual)
                {
                    break;
                }
            }
            return(flag);
        }
Beispiel #14
0
 public TagWorkItem(IRuleEvaluationContext context, PropValue value, int actionIndex) : base(context, actionIndex)
 {
     this.value = value;
 }
Beispiel #15
0
 public WorkItem(IRuleEvaluationContext context, int actionIndex)
 {
     this.context     = context;
     this.rule        = this.context.CurrentRule;
     this.actionIndex = actionIndex;
 }
Beispiel #16
0
 public RuleEvaluator(IRuleEvaluationContext context)
 {
     this.context = context;
 }
Beispiel #17
0
 public OofHistory(byte[] senderAddress, byte[] globalRuleId, IRuleEvaluationContext context)
 {
     this.senderAddress = senderAddress;
     this.globalRuleId  = globalRuleId;
     this.context       = context;
 }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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;
            }
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
 protected RuleLoader(IRuleEvaluationContext context)
 {
     this.context = context;
 }
 public MailboxEvaluationResult(IRuleEvaluationContext context)
 {
     this.context       = context;
     this.folderResults = new List <FolderEvaluationResult>();
     this.targetFolder  = this.context.CurrentFolder;
 }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        public static List <Rule> LoadRules(IRuleEvaluationContext context)
        {
            RuleLoader ruleLoader = new RuleLoader(context);

            return(ruleLoader.Load());
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
 public OofReplyWorkItem(IRuleEvaluationContext context, byte[] messageTemplateEntryId, int actionIndex) : base(context, actionIndex)
 {
     this.messageTemplateEntryId = messageTemplateEntryId;
 }
Beispiel #30
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);
        }