示例#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);
 }
示例#2
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);
        }