コード例 #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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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;
            }
        }