Esempio n. 1
0
        /// <summary>
        ///   Tries to parse the textual representation of a SenderID record
        /// </summary>
        /// <param name="s"> Textual representation to check </param>
        /// <param name="value"> Parsed SenderID record in case of successful parsing </param>
        /// <returns> true in case of successful parsing </returns>
        public static bool TryParse(string s, out SenderIDRecord value)
        {
            if (String.IsNullOrEmpty(s))
            {
                value = null;
                return(false);
            }

            string[] terms = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (terms.Length < 1)
            {
                value = null;
                return(false);
            }

            int version;
            int minor;
            List <SenderIDScope> scopes;

            if (!TryParsePrefix(terms[0], out version, out minor, out scopes))
            {
                value = null;
                return(false);
            }

            List <SpfTerm> parsedTerms;

            if (TryParseTerms(terms, out parsedTerms))
            {
                value =
                    new SenderIDRecord
                {
                    Version      = version,
                    MinorVersion = minor,
                    Scopes       = scopes,
                    Terms        = parsedTerms
                };
                return(true);
            }
            else
            {
                value = null;
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///   Tries to parse the textual representation of a SenderID record
        /// </summary>
        /// <param name="s"> Textual representation to check </param>
        /// <param name="value"> Parsed SenderID record in case of successful parsing </param>
        /// <returns> true in case of successful parsing </returns>
        public static bool TryParse(string s, out SenderIDRecord value)
        {
            if (String.IsNullOrEmpty(s))
            {
                value = null;
                return false;
            }

            string[] terms = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (terms.Length < 1)
            {
                value = null;
                return false;
            }

            int version;
            int minor;
            List<SenderIDScope> scopes;
            if (!TryParsePrefix(terms[0], out version, out minor, out scopes))
            {
                value = null;
                return false;
            }

            List<SpfTerm> parsedTerms;
            if (TryParseTerms(terms, out parsedTerms))
            {
                value =
                    new SenderIDRecord
                    {
                        Version = version,
                        MinorVersion = minor,
                        Scopes = scopes,
                        Terms = parsedTerms
                    };
                return true;
            }
            else
            {
                value = null;
                return false;
            }
        }