private bool ShouldSubmit(MessageItem message)
        {
            if (this.IsScheduleMessage(message))
            {
                base.Context.TraceDebug("Delegate action: Message will be forwarded.");
                return(true);
            }
            ProxyAddress originalSender = RuleUtil.GetOriginalSender(base.Context.Message);

            if (originalSender == null || originalSender is InvalidProxyAddress)
            {
                base.Context.TraceDebug("Delegate action: Sent-Representing properties are not valid, message will not be forwarded.");
                return(false);
            }
            base.Context.TraceDebug <ProxyAddress>("Delegate action: Message will be sent representing {0}.", originalSender);
            Result <ADRawEntry> result = base.Context.RecipientCache.FindAndCacheRecipient(originalSender);

            if (result.Data == null)
            {
                if (ProviderError.NotFound == result.Error)
                {
                    base.Context.TraceError("Delegate action: Sender doesn't exist in AD.");
                }
                else
                {
                    base.Context.TraceError <ProviderError>("Delegate action: Sender look up failed: {0}", result.Error);
                }
                base.Context.TraceDebug("Delegate action: Message will not be forwarded.");
                return(false);
            }
            base.Context.TraceDebug("Delegate action: Message will be forwarded.");
            return(true);
        }
        public override void Execute()
        {
            MessageItem             deliveredMessage         = base.Context.DeliveredMessage;
            StorePropertyDefinition propertyDefinitionForTag = base.Context.GetPropertyDefinitionForTag(this.value.PropTag);

            if (!RuleUtil.IsMultiValueTag(this.value.PropTag))
            {
                base.Context.TraceDebug <PropTag, object>("Setting single value property '{0}' to '{1}'", this.value.PropTag, this.value.Value ?? "null");
                deliveredMessage[propertyDefinitionForTag] = this.value.Value;
                return;
            }
            Array array = this.value.Value as Array;

            if (RuleUtil.IsNullOrEmpty(array))
            {
                base.Context.TraceDebug <PropTag>("Clearing the existing multi-value property '{0}' since new value specified in rule was null or empty.", this.value.PropTag);
                deliveredMessage[propertyDefinitionForTag] = this.value.Value;
                return;
            }
            Array array2 = deliveredMessage.TryGetProperty(propertyDefinitionForTag) as Array;

            if (RuleUtil.IsNullOrEmpty(array2))
            {
                base.Context.TraceDebug <PropTag, int>("Setting multi-value property '{0}' to {1} elements, since no existing value were found.", this.value.PropTag, array.Length);
                deliveredMessage[propertyDefinitionForTag] = array;
                return;
            }
            Type  elementType = array2.GetType().GetElementType();
            Array array3      = Array.CreateInstance(elementType, array2.Length + array.Length);

            array2.CopyTo(array3, 0);
            array.CopyTo(array3, array2.Length);
            base.Context.TraceDebug <PropTag, int>("Setting multi-value property '{0}' to {1} elements, which contains the concatenated array of existing and new values.", this.value.PropTag, array3.Length);
            deliveredMessage[propertyDefinitionForTag] = array3;
        }
Exemple #3
0
        internal unsafe static int CompareBytes(Guid x, Guid y)
        {
            Guid *px = &x;
            Guid *py = &y;

            return(RuleUtil.CompareBytes((byte *)px, (byte *)py, sizeof(Guid)));
        }
Exemple #4
0
        internal unsafe static int CompareBytes(long x, long y)
        {
            long *px = &x;
            long *py = &y;

            return(RuleUtil.CompareBytes((byte *)px, (byte *)py, 8));
        }
 public override void Execute()
 {
     if (!this.ShouldExecuteOnThisStage)
     {
         return;
     }
     if (base.Context.DetectLoop())
     {
         string[] valueOrDefault = base.Context.Message.GetValueOrDefault <string[]>(MessageItemSchema.XLoop, null);
         if (valueOrDefault == null || valueOrDefault.Length != 1)
         {
             return;
         }
         base.Context.TraceDebug("Sending to Delegates even though loop was detected due to 1 XLoop header in the message.");
     }
     base.Context.TraceDebug("Delegate action: Creating message to forward.");
     using (MessageItem messageItem = RuleMessageUtils.CreateDelegateForward(base.Context.Message, base.Context.StoreSession.PreferedCulture, base.Context.DefaultDomainName, base.Context.XLoopValue, base.Context))
     {
         if (this.ShouldSubmit(messageItem))
         {
             this.SetDelegateProperties(messageItem);
             if (base.Context.PropertiesForDelegateForward != null)
             {
                 foreach (KeyValuePair <PropertyDefinition, object> keyValuePair in base.Context.PropertiesForDelegateForward)
                 {
                     base.Context.TraceDebug <PropertyDefinition, object>("Delegate action: setting {0} to {1}", keyValuePair.Key, keyValuePair.Value ?? "(null)");
                     messageItem.SetOrDeleteProperty(keyValuePair.Key, keyValuePair.Value);
                 }
             }
             messageItem.AutoResponseSuppress = AutoResponseSuppress.All;
             RuleUtil.SetRecipients(base.Context, messageItem, null, this.recipients, true);
             base.SubmitMessage(messageItem);
         }
     }
 }
Exemple #6
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);
        }
Exemple #7
0
 private void CreateWorkItemForReply(FolderEvaluationResult result, RuleAction.Reply action, int actionIndex)
 {
     if (RuleUtil.IsSameUser(this.context, this.context.RecipientCache, this.context.Sender, this.context.Recipient))
     {
         this.context.TraceDebug("Do not generate reply to self.");
         return;
     }
     if (ObjectClass.IsDsn(this.context.Message.ClassName) || ObjectClass.IsMdn(this.context.Message.ClassName))
     {
         this.context.TraceDebug("Do not generate reply for Dsn or Mdn messages");
         return;
     }
     if ((this.context.Message.AutoResponseSuppress & AutoResponseSuppress.AutoReply) != AutoResponseSuppress.None)
     {
         this.context.TraceDebug("Do not generate reply since Auto-Reply is being suppressed on current message");
         return;
     }
     if (ObjectClass.IsApprovalMessage(this.context.Message.ClassName))
     {
         this.context.TraceDebug("Do not generate reply to approval message.");
         return;
     }
     if (this.context.LimitChecker.DoesExceedAutoReplyLimit())
     {
         return;
     }
     result.AddWorkItem(new ReplyWorkItem(this.context, action.ReplyTemplateMessageEntryID, action.ReplyTemplateGuid, action.Flags, actionIndex));
 }
Exemple #8
0
 private static void ValidatePropertyRestriction(Restriction.PropertyRestriction restriction)
 {
     if (!RestrictionEvaluator.IsSupportedOperation(restriction.Op))
     {
         throw new InvalidRuleException(string.Format("Operation {0} is not supported", restriction.Op));
     }
     if (RuleUtil.IsMultiValueTag(restriction.PropValue.PropTag))
     {
         if (restriction.MultiValued)
         {
             throw new InvalidRuleException("At most one tag can be multi-valued");
         }
         if (restriction.Op != Restriction.RelOp.Equal && restriction.Op != Restriction.RelOp.NotEqual)
         {
             throw new InvalidRuleException("Restriction has multi-valued value only support Equal or NotEqual operation");
         }
     }
     if (!RuleUtil.IsSameType(restriction.PropTag, restriction.PropValue.PropTag))
     {
         throw new InvalidRuleException("Tag and value are of different type");
     }
     if (RuleUtil.IsBooleanTag(restriction.PropTag) && restriction.Op != Restriction.RelOp.Equal && restriction.Op != Restriction.RelOp.NotEqual)
     {
         throw new InvalidRuleException("Boolean tag only support Equal or NotEqual operation");
     }
     RestrictionEvaluator.ValidateRestrictionValue(restriction.PropValue);
 }
Exemple #9
0
 private void WriteFolder(Folder folder)
 {
     this.writer.WriteStartElement("Folder");
     if (folder != null)
     {
         Rule[]    rules = null;
         Exception exception;
         if (RuleUtil.TryRunStoreCode(delegate
         {
             MapiFolder mapiFolder = folder.MapiFolder;
             rules = mapiFolder.GetRules(new PropTag[0]);
         }, out exception))
         {
             this.writer.WriteAttributeString("FolderName", folder.DisplayName);
             this.writer.WriteAttributeString("Rules", rules.Length.ToString());
             for (int i = 0; i < rules.Length; i++)
             {
                 Rule rule = rules[i];
                 this.WriteRule(rule, i);
             }
         }
         else
         {
             this.WriteExceptionElement("Getting rules from folder: " + folder.DisplayName, exception);
         }
     }
     this.writer.WriteEndElement();
 }
Exemple #10
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);
 }
Exemple #11
0
        private void WriteMoveCopyAction(RuleAction.MoveCopy moveCopy)
        {
            Exception exception;

            if (!RuleUtil.TryRunStoreCode(delegate
            {
                StoreObjectId folderId = StoreObjectId.FromProviderSpecificId(moveCopy.FolderEntryID, StoreObjectType.Folder);
                try
                {
                    Folder folder = this.folders.FirstOrDefault((Folder candidate) => candidate.StoreObjectId.Equals(folderId));
                    if (folder == null)
                    {
                        folder = Folder.Bind(this.session, folderId);
                        this.folders.Add(folder);
                    }
                    this.writer.WriteAttributeString("FolderName", folder.DisplayName);
                }
                catch (ObjectNotFoundException)
                {
                    this.writer.WriteAttributeString("FolderName", ServerStrings.RuleWriterObjectNotFound);
                }
            }, out exception))
            {
                this.WriteExceptionElement("Opening target folder for rule action.", exception);
            }
            this.WriteBinaryData("FolderEntry", moveCopy.FolderEntryID);
            this.WriteBinaryData("StoreEntry", moveCopy.StoreEntryID);
        }
        protected static RecipientItemType GetRecipientType(RuleEvaluationContextBase context)
        {
            RecipientItemType result = RecipientItemType.Unknown;
            string            text   = context.PropertyBag[StoreObjectSchema.ItemClass] as string;

            if (!string.IsNullOrEmpty(text) && ObjectClass.IsReport(text))
            {
                result = RecipientItemType.To;
            }
            else
            {
                RecipientCollection recipients = context.Message.Recipients;
                for (int i = 0; i < recipients.Count; i++)
                {
                    if (recipients[i].Participant.RoutingType != null && recipients[i].Participant.EmailAddress != null)
                    {
                        ProxyAddress addressToResolve = ProxyAddress.Parse(recipients[i].Participant.RoutingType, recipients[i].Participant.EmailAddress);
                        if (RuleUtil.IsSameUser(context, context.RecipientCache, addressToResolve, context.Recipient))
                        {
                            result = recipients[i].RecipientItemType;
                            break;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #13
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);
        }
Exemple #14
0
 private static void ValidateRestrictionValue(PropValue value)
 {
     if (value.Value == null)
     {
         throw new InvalidRuleException("Value stored in restriction is null");
     }
     RuleUtil.CheckValueType(value.Value, value.PropTag);
 }
Exemple #15
0
 internal static bool EqualsStoreId(StoreId idX, StoreId idY)
 {
     if (idX == null)
     {
         return(idY == null);
     }
     return(idY != null && RuleUtil.GetObjectId(idX).Equals(RuleUtil.GetObjectId(idY)));
 }
 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;
 }
Exemple #17
0
 protected override object CalculatePropertyValue(PropTag tag)
 {
     if (tag == PropTag.SearchKey)
     {
         return(RuleUtil.SearchKeyFromParticipant(this.recipient.Participant));
     }
     return(null);
 }
Exemple #18
0
 public static byte[] SearchKeyFromParticipant(Participant participant)
 {
     if (null == participant)
     {
         return(null);
     }
     return(RuleUtil.SearchKeyFromAddress(participant.RoutingType, participant.EmailAddress));
 }
Exemple #19
0
 internal static void MarkRuleInError(Rule rule, MapiFolder mapiFolder)
 {
     rule.StateFlags |= RuleStateFlags.Error;
     RuleUtil.RunMapiCode(ServerStrings.ModifyRuleInStore, new ActionParams(RuleUtil.ModifyRule), new object[]
     {
         rule,
         mapiFolder
     });
 }
Exemple #20
0
 internal static void DisableRule(Rule rule, MapiFolder mapiFolder)
 {
     rule.StateFlags &= ~RuleStateFlags.Enabled;
     RuleUtil.RunMapiCode(ServerStrings.ModifyRuleInStore, new ActionParams(RuleUtil.ModifyRule), new object[]
     {
         rule,
         mapiFolder
     });
 }
Exemple #21
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;
 }
Exemple #22
0
 private void CreateWorkItemForDelegate(FolderEvaluationResult result, RuleAction.Delegate action, int actionIndex)
 {
     if (RuleUtil.IsNullOrEmpty(action.Recipients))
     {
         this.context.TraceError("Delegate recipient list is empty");
         return;
     }
     result.AddWorkItem(new DelegateWorkItem(this.context, action.Recipients, actionIndex));
 }
Exemple #23
0
        internal static bool EqualsEntryId(byte[] x, byte[] y)
        {
            if (RuleUtil.EqualsByteArray(x, y))
            {
                return(true);
            }
            Participant participant  = RuleUtil.GetParticipant(x);
            Participant participant2 = RuleUtil.GetParticipant(y);

            return(!(participant == null) && !(participant2 == null) && participant.AreAddressesEqual(participant2));
        }
Exemple #24
0
        private void UpdateDeliveredMessage()
        {
            base.Context.TraceDebug("Deferred action: Updating delivered message.");
            MessageItem deliveredMessage = base.Context.DeliveredMessage;

            if (!RuleUtil.IsNullOrEmpty(this.MoveToFolderEntryId) && !RuleUtil.IsNullOrEmpty(this.MoveToStoreEntryId))
            {
                deliveredMessage[ItemSchema.MoveToStoreEntryId]  = this.MoveToStoreEntryId;
                deliveredMessage[ItemSchema.MoveToFolderEntryId] = this.MoveToFolderEntryId;
            }
            deliveredMessage[ItemSchema.HasDeferredActionMessage] = true;
        }
Exemple #25
0
        private void CreateWorkItemForOofReply(FolderEvaluationResult result, RuleAction.OOFReply action, int actionIndex)
        {
            string className = this.context.Message.ClassName;

            if (ObjectClass.IsDsn(className) || ObjectClass.IsMdn(className))
            {
                this.context.TraceDebug("Do not generate OOF reply for Dsn or Mdn messages");
                return;
            }
            if ((this.context.Message.AutoResponseSuppress & AutoResponseSuppress.OOF) != AutoResponseSuppress.None)
            {
                this.context.TraceDebug("Do not generate OOF reply when Oof Reply is being suppressed");
                return;
            }
            if (ObjectClass.IsOfClass(className, "IPM.Note.Rules.ExternalOofTemplate.Microsoft") || ObjectClass.IsOfClass(className, "IPM.Note.Rules.OofTemplate.Microsoft"))
            {
                this.context.TraceDebug("Do not generate OOF reply for Oof Message");
                return;
            }
            if (ObjectClass.IsOutlookRecall(className) || ObjectClass.IsOfClass(className, "IPM.Recall.Report.Failure") || ObjectClass.IsOfClass(className, "IPM.Recall.Report.Success"))
            {
                this.context.TraceDebug("Do not generate OOF reply for outlook recall Message");
                return;
            }
            if (null == this.context.Message.Sender)
            {
                this.context.TraceDebug("Do not generate OOF reply for an unknown sender");
                return;
            }
            string routingType = this.context.Message.Sender.RoutingType;

            if (string.IsNullOrEmpty(routingType) || (!(routingType == "SMTP") && !(routingType == "EX") && !routingType.Equals("X400")))
            {
                this.context.TraceDebug <string>("Do not generate OOF reply for address type {0}", routingType ?? "<null>");
                return;
            }
            if (RuleUtil.IsNullOrEmpty(action.ReplyTemplateMessageEntryID))
            {
                this.context.TraceError("Replay template message id is empty");
                return;
            }
            bool?valueAsNullable = this.context.Message.GetValueAsNullable <bool>(ItemSchema.DelegatedByRule);

            if (valueAsNullable != null && valueAsNullable.Value)
            {
                this.context.TraceDebug("Do not generate OOF reply for messages delegated by rule.");
                return;
            }
            result.AddWorkItem(new OofReplyWorkItem(this.context, action.ReplyTemplateMessageEntryID, actionIndex));
        }
 public object this[PropTag tag]
 {
     get
     {
         tag = RuleUtil.NormalizeTag(tag);
         object obj = this.CalculatePropertyValue(tag);
         if (obj == null)
         {
             obj = this.GetPropertyValue(tag);
         }
         RuleUtil.CheckValueType(obj, tag);
         return(obj);
     }
 }
Exemple #27
0
 internal static void RunMapiCode(LocalizedString context, ActionParams action, params object[] arguments)
 {
     try
     {
         action(arguments);
     }
     catch (MapiRetryableException e)
     {
         RuleUtil.TranslateThrow(e, context);
     }
     catch (MapiPermanentException e2)
     {
         RuleUtil.TranslateThrow(e2, context);
     }
 }
Exemple #28
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");
     }
 }
Exemple #29
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);
        }
Exemple #30
0
 internal static object RunMapiCode(LocalizedString context, ActionWithReturnValue action)
 {
     try
     {
         return(action());
     }
     catch (MapiRetryableException e)
     {
         RuleUtil.TranslateThrow(e, context);
     }
     catch (MapiPermanentException e2)
     {
         RuleUtil.TranslateThrow(e2, context);
     }
     return(null);
 }