Esempio n. 1
0
 internal static bool TryCreateAction(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, TimeSpan timeInterval, string path, out InterceptorAgentAction action, out LocalizedString warning, out LocalizedString error)
 {
     action  = null;
     error   = LocalizedString.Empty;
     warning = LocalizedString.Empty;
     if (!InterceptorAgentAction.IsValidRuleBehavior(behavior))
     {
         error = Strings.InterceptorErrorInvalidBehavior(behavior.ToString(), string.Join(", ", InterceptorAgentAction.AllActions));
         return(false);
     }
     if (behavior == InterceptorAgentRuleBehavior.TransientReject || behavior == InterceptorAgentRuleBehavior.PermanentReject)
     {
         return(InterceptorHelper.TryCreateRejectAction(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out action, out error));
     }
     if ((responseCodeModified || responseTextModified) && !InterceptorAgentAction.IsRejectingBehavior(behavior))
     {
         warning = Strings.InterceptorWarningCustomResponseCodeTextWithoutRejectAction;
     }
     if (behavior == InterceptorAgentRuleBehavior.Delay || behavior == InterceptorAgentRuleBehavior.Defer)
     {
         if (timeInterval <= TimeSpan.Zero || timeInterval >= TimeSpan.FromMilliseconds(2147483647.0))
         {
             error = Strings.InterceptorErrorTimeIntervalInvalid(timeInterval);
             return(false);
         }
         action = new InterceptorAgentAction(behavior, timeInterval);
     }
     else if (InterceptorAgentAction.IsArchivingBehavior(behavior))
     {
         if (!string.IsNullOrEmpty(path))
         {
             if (Path.GetInvalidPathChars().Any((char ch) => path.Contains(ch)))
             {
                 error = Strings.InterceptorErrorPathInvalidCharacters(path);
                 return(false);
             }
         }
         if (!string.IsNullOrEmpty(path) && Path.IsPathRooted(path))
         {
             error = Strings.InterceptorErrorRootedPathNotAllowed(path);
             return(false);
         }
         SmtpResponse response;
         if (!InterceptorHelper.CreateRejectSmtpResponse(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out response, out error))
         {
             return(false);
         }
         action = new InterceptorAgentAction(behavior, path, response);
     }
     else
     {
         action = new InterceptorAgentAction(behavior);
     }
     if (!string.IsNullOrEmpty(path) && !InterceptorAgentAction.IsArchivingBehavior(behavior))
     {
         warning = Strings.InterceptorWarningPathIgnored;
     }
     return(true);
 }
Esempio n. 2
0
        internal static LocalizedString GetArchivedItemRetentionMessage(InterceptorAgentRuleBehavior action, string ruleName, string relativePath, int retentionPeriod)
        {
            string text = Path.Combine(InterceptorAgentSettings.ArchivePath, ((ushort)(action & InterceptorAgentRuleBehavior.Archive) == 32) ? InterceptorAgentSettings.ArchivedMessagesDirectory : InterceptorAgentSettings.ArchivedMessageHeadersDirectory);

            if (!string.IsNullOrEmpty(relativePath))
            {
                text = Path.Combine(text, relativePath);
            }
            return(Strings.InterceptorWarningArchivedItemsLifeTime(ruleName, text, retentionPeriod));
        }
Esempio n. 3
0
        private static bool TryCreateRejectAction(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, out InterceptorAgentAction action, out LocalizedString error)
        {
            action = null;
            SmtpResponse response;

            if (!InterceptorHelper.CreateRejectSmtpResponse(behavior, customResponseCode, responseCodeModified, customResponseText, responseTextModified, out response, out error))
            {
                return(false);
            }
            action = new InterceptorAgentAction(behavior, response);
            return(true);
        }
Esempio n. 4
0
        internal static bool ValidateEventActionPairs(InterceptorAgentEvent evt, InterceptorAgentRuleBehavior action, out LocalizedString error)
        {
            error = LocalizedString.Empty;
            foreach (KeyValuePair <InterceptorAgentRuleBehavior, InterceptorAgentEvent> keyValuePair in InterceptorAgentRule.InvalidActionEventPairs)
            {
                if ((ushort)(evt & keyValuePair.Value) != 0 && action == keyValuePair.Key)
                {
                    InterceptorAgentEvent validEventsMask = ~keyValuePair.Value;
                    IEnumerable <string>  values          = from InterceptorAgentEvent val in Enum.GetValues(typeof(InterceptorAgentEvent))
                                                            where (ushort)(val & validEventsMask) != 0
                                                            select val.ToString();

                    error = Strings.InterceptorErrorInvalidEventActionPair((evt & keyValuePair.Value).ToString(), keyValuePair.Key.ToString(), string.Join(", ", values));
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 5
0
 internal static bool TryGetStatusCodeForModifiedRejectAction(InterceptorAgentRuleBehavior modifiedBehavior, InterceptorAgentRuleBehavior originalBehavior, string originalCustomResponseCode, out string newCustomResponseCode)
 {
     newCustomResponseCode = string.Empty;
     if (originalBehavior == InterceptorAgentRuleBehavior.TransientReject || originalBehavior == InterceptorAgentRuleBehavior.PermanentReject)
     {
         if (modifiedBehavior == InterceptorAgentRuleBehavior.TransientReject && SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusCode.Equals(originalCustomResponseCode))
         {
             newCustomResponseCode = SmtpResponse.InterceptorTransientlyRejectedMessage.StatusCode;
             return(true);
         }
         if (modifiedBehavior == InterceptorAgentRuleBehavior.PermanentReject && SmtpResponse.InterceptorTransientlyRejectedMessage.StatusCode.Equals(originalCustomResponseCode))
         {
             newCustomResponseCode = SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusCode;
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
        private static bool CreateRejectSmtpResponse(InterceptorAgentRuleBehavior behavior, string customResponseCode, bool responseCodeModified, string customResponseText, bool responseTextModified, out SmtpResponse smtpResponse, out LocalizedString error)
        {
            smtpResponse = SmtpResponse.Empty;
            error        = LocalizedString.Empty;
            bool flag  = (ushort)(behavior & InterceptorAgentRuleBehavior.TransientReject) != 0;
            bool flag2 = (ushort)(behavior & InterceptorAgentRuleBehavior.PermanentReject) != 0;

            if (!flag && !flag2)
            {
                return(true);
            }
            if (responseCodeModified || responseTextModified)
            {
                if (responseCodeModified)
                {
                    if (string.IsNullOrEmpty(customResponseCode) || customResponseCode.Length != 3)
                    {
                        error = Strings.InterceptorErrorCustomResponseCodeInvalid(customResponseCode);
                        return(false);
                    }
                    int num;
                    if (!int.TryParse(customResponseCode, NumberStyles.Integer, CultureInfo.InvariantCulture, out num))
                    {
                        error = Strings.InterceptorErrorCustomResponseCodeInvalid(customResponseCode);
                        return(false);
                    }
                    string text;
                    if (flag)
                    {
                        if (num > 499 || num < 400)
                        {
                            error = Strings.InterceptorErrorCustomResponseCodeMustMatchRejectAction(num, behavior.ToString(), 4);
                            return(false);
                        }
                        text = SmtpResponse.InterceptorTransientlyRejectedMessage.StatusText[0];
                    }
                    else
                    {
                        if (num > 599 || num < 500)
                        {
                            error = Strings.InterceptorErrorCustomResponseCodeMustMatchRejectAction(num, behavior.ToString(), 5);
                            return(false);
                        }
                        text = SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusText[0];
                    }
                    if (responseTextModified)
                    {
                        if (!InterceptorHelper.TryValidateCustomResponseText(customResponseText, out error))
                        {
                            return(false);
                        }
                        text = customResponseText;
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendFormat("{0}.{1}.{2}", customResponseCode[0], customResponseCode[1], customResponseCode[2]);
                    smtpResponse = new SmtpResponse(customResponseCode, stringBuilder.ToString(), new string[]
                    {
                        text
                    });
                }
                else
                {
                    if (!InterceptorHelper.TryValidateCustomResponseText(customResponseText, out error))
                    {
                        return(false);
                    }
                    if (flag)
                    {
                        smtpResponse = new SmtpResponse(SmtpResponse.InterceptorTransientlyRejectedMessage.StatusCode, SmtpResponse.InterceptorTransientlyRejectedMessage.EnhancedStatusCode, new string[]
                        {
                            customResponseText
                        });
                    }
                    else
                    {
                        smtpResponse = new SmtpResponse(SmtpResponse.InterceptorPermanentlyRejectedMessage.StatusCode, SmtpResponse.InterceptorPermanentlyRejectedMessage.EnhancedStatusCode, new string[]
                        {
                            customResponseText
                        });
                    }
                }
                return(true);
            }
            if (flag)
            {
                smtpResponse = SmtpResponse.InterceptorTransientlyRejectedMessage;
                return(true);
            }
            smtpResponse = SmtpResponse.InterceptorPermanentlyRejectedMessage;
            return(true);
        }
Esempio n. 7
0
        protected override void InternalValidate()
        {
            bool flag  = base.Fields.IsModified("Event");
            bool flag2 = base.Fields.IsModified("Action");
            bool flag3 = base.Fields.IsModified("Condition");
            bool flag4 = base.Fields.IsModified("CustomResponseCode");
            bool flag5 = base.Fields.IsModified("CustomResponseText");
            bool flag6 = base.Fields.IsModified("Description");
            bool flag7 = base.Fields.IsModified("TimeInterval");
            bool flag8 = base.Fields.IsModified("Path");

            this.xmlNeedsUpdating = (flag2 || flag || flag3 || flag4 || flag5 || flag7 || flag6 || flag8 || base.Fields.IsModified("Identity"));
            if (base.Fields.IsModified("ExpireTime") && DateTime.UtcNow > this.ExpireTime.ToUniversalTime())
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorExpireTimePassed(this.ExpireTime.ToString("G"))), ErrorCategory.InvalidData, "ExpireTime");
            }
            this.DataObject = (InterceptorRule)this.ResolveDataObject();
            if (this.xmlNeedsUpdating)
            {
                try
                {
                    this.rule = InterceptorAgentRule.CreateRuleFromXml(this.DataObject.Xml);
                    this.rule.SetPropertiesFromAdObjet(this.DataObject);
                }
                catch (FormatException exception)
                {
                    base.WriteError(exception, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
                catch (InvalidOperationException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
            }
            if (this.rule.RuleVersion > InterceptorAgentRule.Version)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorModifyingNewerVersion(this.rule.RuleVersion.ToString())), ErrorCategory.InvalidOperation, null);
            }
            if (flag2 || flag)
            {
                InterceptorAgentRuleBehavior action = flag2 ? this.Action : this.rule.Action.Action;
                InterceptorAgentEvent        interceptorAgentEvent = flag ? this.Event : this.rule.Events;
                LocalizedString localizedString;
                if (!InterceptorHelper.ValidateEventActionPairs(interceptorAgentEvent, action, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = interceptorAgentEvent;
                string customResponseCode;
                if (flag2 && !flag4 && InterceptorHelper.TryGetStatusCodeForModifiedRejectAction(this.Action, this.rule.Action.Action, this.rule.Action.Response.StatusCode, out customResponseCode))
                {
                    this.CustomResponseCode = customResponseCode;
                    flag4 = base.Fields.IsModified("CustomResponseCode");
                }
            }
            if (flag3)
            {
                LocalizedString localizedString;
                List <InterceptorAgentCondition> conditions;
                if (!InterceptorHelper.TryCreateConditions(this.Condition, out conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Condition);
                    return;
                }
                InterceptorAgentEvent evt = flag ? this.Event : this.rule.Events;
                if (!InterceptorHelper.ValidateEventConditionPairs(evt, conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Conditions = conditions;
            }
            if (flag)
            {
                LocalizedString localizedString;
                if (!flag3 && !InterceptorHelper.ValidateEventConditionPairs(this.Event, this.rule.Conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = this.Event;
            }
            if (flag6)
            {
                this.rule.Description = this.Description;
            }
            this.SetAction(flag4, flag5, flag2, flag8, flag7);
            this.ResolveTargets();
        }