// Token: 0x06000246 RID: 582 RVA: 0x0000A13C File Offset: 0x0000833C
        public static bool IsValidDomain(string address, int offset, bool checkLength, bool allowUTF8 = false)
        {
            if (string.IsNullOrEmpty(address) || (checkLength && address.Length - offset > 255))
            {
                return(false);
            }
            MimeAddressParser.ValidationStage validationStage = MimeAddressParser.ValidationStage.DOMAIN;
            int  num  = 0;
            int  num2 = 0;
            int  num3 = 0;
            bool flag = false;
            int  num4 = 0;

            while (offset < address.Length && validationStage != MimeAddressParser.ValidationStage.ERROR)
            {
                char c = address[offset];
                offset++;
                switch (validationStage)
                {
                case MimeAddressParser.ValidationStage.DOMAIN:
                    if (c == '[')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL;
                        continue;
                    }
                    if ((c < '\u0080' && MimeScan.IsAlphaOrDigit((byte)c)) || (c >= '\u0080' && allowUTF8) || c == '-' || c == '_')
                    {
                        num4            = offset;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_SUB;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_SUB:
                    if (c == '.')
                    {
                        if (checkLength && offset - num4 > 63)
                        {
                            return(false);
                        }
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_DOT;
                        continue;
                    }
                    else if ((c < '\u0080' && MimeScan.IsAlphaOrDigit((byte)c)) || (c >= '\u0080' && allowUTF8) || c == '-' || c == '_')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_SUB;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_DOT:
                    if ((c < '\u0080' && MimeScan.IsAlphaOrDigit((byte)c)) || (c >= '\u0080' && allowUTF8) || c == '-' || c == '_')
                    {
                        num4            = offset;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_SUB;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL:
                    if (c < '\u0080' && MimeScan.IsDigit((byte)c))
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4;
                        num             = 1;
                        num2            = 1;
                        num3            = (int)(c - '0');
                        continue;
                    }
                    if (c == 'I' || c == 'i')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_I;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4:
                    if (c < '\u0080' && MimeScan.IsDigit((byte)c) && num2 < 3)
                    {
                        num2++;
                        num3 = num3 * 10 + (int)(c - '0');
                        if (num3 <= 255)
                        {
                            validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4;
                            continue;
                        }
                    }
                    else
                    {
                        if (c == '.')
                        {
                            validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4_DOT;
                            continue;
                        }
                        if (c == ']' && num == 4)
                        {
                            validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_END;
                            continue;
                        }
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4_DOT:
                    if (c < '\u0080' && MimeScan.IsDigit((byte)c) && num < 4)
                    {
                        num++;
                        num2            = 1;
                        num3            = (int)(c - '0');
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_I:
                    if (c == 'P' || c == 'p')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IP;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IP:
                    if (c == 'v' || c == 'V')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV:
                    if (c == '6')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6:
                    if (c == ':')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_:
                    if (c < '\u0080' && MimeScan.IsHex((byte)c))
                    {
                        flag            = false;
                        num             = 1;
                        num2            = 1;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP;
                        continue;
                    }
                    if (c == ':')
                    {
                        num             = 0;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_STARTCOLON;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_STARTCOLON:
                    if (c == ':')
                    {
                        flag            = true;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COMP;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP:
                    if (c < '\u0080' && MimeScan.IsHex((byte)c) && num2 < 4)
                    {
                        num2++;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP;
                        continue;
                    }
                    if (c == ':')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COLON;
                        continue;
                    }
                    if (c == ']' && ((!flag && num == 8) || (flag && num <= 6)))
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_END;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_V4GRP:
                    if (c < '\u0080' && MimeScan.IsDigit((byte)c) && num2 < 3)
                    {
                        num2++;
                        num3            = num3 * 10 + (int)(c - '0');
                        validationStage = ((num3 <= 255) ? MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_V4GRP : MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP);
                        continue;
                    }
                    if (c < '\u0080' && MimeScan.IsHex((byte)c) && num2 < 4)
                    {
                        num2++;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP;
                        continue;
                    }
                    if (c == ':')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COLON;
                        continue;
                    }
                    if (c == '.')
                    {
                        num             = 1;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV4_DOT;
                        continue;
                    }
                    if (c == ']' && flag && num <= 6)
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_END;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COLON:
                    if ((c < '\u0080' && MimeScan.IsDigit((byte)c) && !flag && num == 6) || (flag && num <= 4))
                    {
                        num++;
                        num2            = 1;
                        num3            = (int)(c - '0');
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_V4GRP;
                        continue;
                    }
                    if ((c < '\u0080' && MimeScan.IsHex((byte)c) && !flag && num < 8) || (flag && num < 6))
                    {
                        num++;
                        num2            = 1;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP;
                        continue;
                    }
                    if (c == ':' && !flag && num <= 6)
                    {
                        flag            = true;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COMP;
                        continue;
                    }
                    break;

                case MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_COMP:
                    if (c < '\u0080' && MimeScan.IsHex((byte)c) && num < 6)
                    {
                        num++;
                        num2            = 1;
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_IPV6_GRP;
                        continue;
                    }
                    if (c == ']')
                    {
                        validationStage = MimeAddressParser.ValidationStage.DOMAIN_LITERAL_END;
                        continue;
                    }
                    break;
                }
                validationStage = MimeAddressParser.ValidationStage.ERROR;
            }
            return(validationStage == MimeAddressParser.ValidationStage.DOMAIN_LITERAL_END || (validationStage == MimeAddressParser.ValidationStage.DOMAIN_SUB && (!checkLength || offset - num4 < 63)));
        }