Esempio n. 1
0
        // Parses the domain section of an address.  The domain may be in dot-atom format or surrounded by square
        // brackets in domain-literal format.
        // e.g. <*****@*****.**> or <user@[whatever I want]>
        //
        // Preconditions:
        // - data[index] is just inside of the angle brackets (if any).
        //
        // Postconditions:
        // - data[index] should refer to the '@' symbol
        // - returns the parsed domain, including any square brackets for domain-literals
        //
        // Throws a FormatException:
        // - For invalid un-escaped chars, including Unicode
        // - If the start of the data string is reached
        private static string ParseDomain(string data, ref int index)
        {
            // Skip comments and whitespace
            index = ReadCfwsAndThrowIfIncomplete(data, index);

            // Mark one end of the domain component
            int startingIndex = index;

            // Is the domain component in domain-literal format or dot-atom format?
            if (data[index] == MailBnfHelper.EndSquareBracket)
            {
                index = DomainLiteralReader.ReadReverse(data, index);
            }
            else
            {
                index = DotAtomReader.ReadReverse(data, index);
            }

            string domain = data.Substring(index + 1, startingIndex - index);

            // Skip comments and whitespace
            index = ReadCfwsAndThrowIfIncomplete(data, index);

            return(NormalizeOrThrow(domain));
        }
        public void TryReadDomainLiteral_WithValidDomainLiteralAndEscapedCharacters_ShouldReadCorrectly()
        {
            int index = ValidDomainLiteralEscapedChars.Length - 1;

            Assert.True(DomainLiteralReader.TryReadReverse(ValidDomainLiteralEscapedChars, index, out index, throwExceptionIfFail: true));

            Assert.Equal(-1, index);
        }
        public void TryReadDomainLiteral_WithLongListOfBackslashes_ShouldReadCorrectly()
        {
            int index = ValidDomainBackslashList.Length - 1;

            Assert.True(DomainLiteralReader.TryReadReverse(ValidDomainBackslashList, index, out index, throwExceptionIfFail: true));

            Assert.Equal(-1, index);
        }
Esempio n. 4
0
        public void ReadDomainLiteral_WithValidDomainLiteralAndEscapedCharacters_ShouldReadCorrectly()
        {
            int index = ValidDomainLiteralEscapedChars.Length - 1;

            index = DomainLiteralReader.ReadReverse(ValidDomainLiteralEscapedChars, index);

            Assert.Equal(-1, index);
        }
Esempio n. 5
0
        public void ReadDomainLiteral_WithLongListOfBackslashes_ShouldReadCorrectly()
        {
            int index = ValidDomainBackslashList.Length - 1;

            index = DomainLiteralReader.ReadReverse(ValidDomainBackslashList, index);

            Assert.Equal(-1, index);
        }
Esempio n. 6
0
        public void ReadDomainLiteral_WithValidDomainLiteral_ShouldReadCorrectly()
        {
            int index = ValidDomainLiteral.Length - 1;

            index = DomainLiteralReader.ReadReverse(ValidDomainLiteral, index);

            Assert.Equal(-1, index);
        }
        public void TryReadDomainLiteral_WithInvalidCharacter_ShouldThrow()
        {
            int index = InvalidDomainLiteral.Length - 1;

            Assert.Throws <FormatException>(() => { DomainLiteralReader.TryReadReverse(InvalidDomainLiteral, index, out int _, throwExceptionIfFail: true); });
        }
Esempio n. 8
0
        public void ReadDomainLiteral_WithInvalidCharacter_ShouldThrow()
        {
            int index = InvalidDomainLiteral.Length - 1;

            Assert.Throws <FormatException>(() => { DomainLiteralReader.ReadReverse(InvalidDomainLiteral, index); });
        }