func sendAuthenticationStart()

in NIOSMTP/NIOSMTP/SendEmailHandler.swift [72:99]


    func sendAuthenticationStart(context: ChannelHandlerContext) {
        func goAhead() {
            self.send(context: context, command: .beginAuthentication)
            self.currentlyWaitingFor = .okForOurAuthBegin
        }

        switch self.serverConfiguration.tlsConfiguration {
        case .regularTLS, .startTLS:
            // Let's make sure we actually have a TLS handler. This code is here purely to make sure we don't have a
            // bug in the code base that would lead to sending any sensitive data without TLS (unless the user asked
            // us to do so.)
            context.channel.pipeline.handler(type: NIOSSLClientHandler.self).map { (_: NIOSSLClientHandler) in
                // we don't actually care about the NIOSSLClientHandler but we must be sure it's there.
                goAhead()
            }.whenFailure { error in
                if NetworkImplementation.best == .transportServices && self.serverConfiguration.tlsConfiguration == .regularTLS {
                    // If we're using NIOTransportServices and regular TLS, then TLS must have been configured ahead
                    // of time, we can't check it here.
                } else {
                    preconditionFailure("serious NIOSMTP bug: TLS handler should be present in " +
                        "\(self.serverConfiguration.tlsConfiguration) but SSL handler \(error)")
                }
            }
        case .insecureNoTLS:
            // sad times here, plaintext
            goAhead()
        }
    }