예제 #1
0
 public EnhancedStatusCodeImpl(string code)
 {
     if (!EnhancedStatusCodeImpl.IsValid(code))
     {
         throw new FormatException(string.Format("This enhanced status code ({0}) isn't properly formatted. Enhanced status codes are in the form of x.y.z where the first digit must be 2, 4, or 5.", code));
     }
     this.code = code;
 }
예제 #2
0
        public static bool TryParse(string line, int startIndex, out EnhancedStatusCodeImpl enhancedStatusCode)
        {
            enhancedStatusCode = null;
            int length;

            if (!EnhancedStatusCodeImpl.CodeLength(line, startIndex, out length))
            {
                return(false);
            }
            enhancedStatusCode      = new EnhancedStatusCodeImpl();
            enhancedStatusCode.code = line.Substring(startIndex, length);
            return(true);
        }
예제 #3
0
        private static SmtpResponseParser.ValidationResult ValidateLine(string line, string statusCode, ref string enhancedStatusCode)
        {
            bool flag = false;

            if (line.Length < 3)
            {
                return(SmtpResponseParser.ValidationResult.Error);
            }
            if (string.CompareOrdinal(statusCode, 0, line, 0, 3) != 0)
            {
                return(SmtpResponseParser.ValidationResult.Error);
            }
            if (line.Length == 3)
            {
                enhancedStatusCode = string.Empty;
                return(SmtpResponseParser.ValidationResult.LastLine);
            }
            if (line[3] == ' ')
            {
                flag = true;
            }
            else if (line[3] != '-')
            {
                return(SmtpResponseParser.ValidationResult.Error);
            }
            int num = 0;

            if (!string.IsNullOrEmpty(enhancedStatusCode))
            {
                EnhancedStatusCodeImpl enhancedStatusCodeImpl;
                string text = EnhancedStatusCodeImpl.TryParse(line, 4, out enhancedStatusCodeImpl) ? enhancedStatusCodeImpl.Value : null;
                if (string.IsNullOrEmpty(text) || !text.Equals(enhancedStatusCode, StringComparison.Ordinal))
                {
                    enhancedStatusCode = string.Empty;
                }
                num = enhancedStatusCode.Length;
            }
            for (int i = 4 + num; i < line.Length; i++)
            {
                if (line[i] < '\u0001' || line[i] > '\u007f')
                {
                    return(SmtpResponseParser.ValidationResult.Error);
                }
            }
            if (!flag)
            {
                return(SmtpResponseParser.ValidationResult.HasMoreLines);
            }
            return(SmtpResponseParser.ValidationResult.LastLine);
        }
예제 #4
0
        private static bool ParseResponseArray(List <string> lines, out string[] result)
        {
            result = null;
            if (lines == null || lines.Count == 0)
            {
                return(false);
            }
            if (!SmtpResponseParser.IsValidStatusCode(lines[0]))
            {
                return(false);
            }
            string text = lines[0].Substring(0, 3);
            EnhancedStatusCodeImpl enhancedStatusCodeImpl;
            string text2 = EnhancedStatusCodeImpl.TryParse(lines[0], 4, out enhancedStatusCodeImpl) ? enhancedStatusCodeImpl.Value : string.Empty;

            if (!SmtpResponseParser.ValidateLines(lines, text, ref text2))
            {
                return(false);
            }
            int num = 4;

            if (!string.IsNullOrEmpty(text2))
            {
                num += text2.Length;
                if (num < lines[0].Length && lines[0][num] == ' ')
                {
                    num++;
                }
            }
            List <string> list = new List <string>(lines.Count);

            for (int i = 0; i < lines.Count; i++)
            {
                string text3 = (lines[i].Length > num) ? lines[i].Substring(num) : string.Empty;
                if (!string.IsNullOrEmpty(text3))
                {
                    list.Add(text3);
                }
            }
            if (list.Count == 0 && lines.Count > 1)
            {
                return(false);
            }
            result    = new string[list.Count + 2];
            result[0] = text;
            result[1] = text2;
            list.CopyTo(result, 2);
            return(true);
        }
예제 #5
0
        public override bool Equals(object obj)
        {
            EnhancedStatusCodeImpl enhancedStatusCodeImpl = obj as EnhancedStatusCodeImpl;

            return(enhancedStatusCodeImpl != null && this == enhancedStatusCodeImpl);
        }
예제 #6
0
        public static bool IsValid(string status)
        {
            int num;

            return(EnhancedStatusCodeImpl.CodeLength(status, 0, out num) && num == status.Length);
        }
예제 #7
0
 public static bool TryParse(string code, out EnhancedStatusCodeImpl enhancedStatusCode)
 {
     return(EnhancedStatusCodeImpl.TryParse(code, 0, out enhancedStatusCode));
 }