コード例 #1
0
        internal ImapConnection(ImapConnectionOptions options) :
            base(options.Host, options.Port, true, options.AllowInvalidRemoteCertificates)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            ConnectionType = options.ConnectionType;
            ComputeDefaultValues();
        }
コード例 #2
0
        private async Task <bool> UpgradeToSecureConnection()
        {
            var commandResult = await ExecuteCommand(ImapCommands.StartTLS());

            var upgradeSuccess = commandResult.Contains(ImapResponse.OK_TLS_NEGOTIATION);

            if (upgradeSuccess)
            {
                ConnectionType = ImapConnectionType.SSL_TLS;
                _stream        = GetStream();
                return(true);
            }
            else
            {
                throw new Exception("Could not upgrade IMAP non SSL connection using STARTTLS handshake");
            }
        }
コード例 #3
0
        private void ComputeDefaultValues()
        {
            switch (ConnectionType)
            {
            case ImapConnectionType.AUTO when Port == 993:
                ConnectionType = ImapConnectionType.SSL_TLS;
                break;

            case ImapConnectionType.AUTO when Port == 143:
                ConnectionType = ImapConnectionType.STARTTLS;
                break;
            }

            if (ConnectionType == ImapConnectionType.AUTO)
            {
                throw new Exception($"Port {Port} is not a valid imap port when using automatic configuration");
            }
        }