Sends a HELO/EHLO sequence
@todo Implement TLS
@return bool  True if successful, false otherwise
4359
protected function helo()
        {
            // don't try if it was already done
            if ($this->state['helo']) {
                return;
            }
            try {
                $this->expect(self::SMTP_CONNECT_SUCCESS, $this->command_timeouts['helo']);
                $this->ehlo();
                // session started
                $this->state['helo'] = true;
                // are we going for a TLS connection?
                /*
                if ($this->tls == true) {
                    // send STARTTLS, wait 3 minutes
                    $this->send('STARTTLS');
                    $this->expect(self::SMTP_CONNECT_SUCCESS, $this->command_timeouts['tls']);
                    $result = stream_socket_enable_crypto($this->socket, true,
                        STREAM_CRYPTO_METHOD_TLS_CLIENT);
                    if (!$result) {
                        throw new Exception('Cannot enable TLS');
                    }
                }
                */
                return true;
            } catch (Exception $e) {
                // connected, but recieved an unexpected response, so disconnect
                $this->debug('Unexpected response after connecting: ' . $e->getMessage());
                $this->disconnect(false);
                return false;
            }
        }
853310
public function send()
    {
        $stack = $this->getStack();

        if ($stack->count() == 0) {
            return false;
        }

        foreach ($stack as $mail) {

            if (!$mail->send()) {
                $this->errors[] = $mail->ErrorInfo;
            }
        
        }

        if (count($this->errors) > 0) {
            return false;
        }

        return true;
    }
1021465
public function send()
    {
        $this->hash();

        if ($data = $this->handle('beforeExecuteReturn')) {
            return $data;
        }

        if (!empty($this->payload)) {
            $this->serialized_payload = $this->handle('serialize', $this->payload);
        }

        $this->uri = $this->formatEndpoint();

        $this->handle('beforeExecute');

        $exception = false;
        $res       = null;

        try {
            $client = new Client();

            $res = $client->request(
                $this->method,
                $this->uri,
                $this->headers + $this->formatBody() + $this->options
            );

        } catch (Exception $e) {
            $exception = $e;
        }

        if (is_bool($exception) && $res instanceof Response) {
            $body = $this->handle('parse', $res->getBody());

            if ($data = $this->handle('afterExecuteReturn', $body)) {
                return $data;
            }

            $this->handle('afterExecute', $body);

            return $body;
        }

        $msg = null;

        if ($exception instanceof Exception) {
            $msg = $exception->getMessage();

            if ($exception instanceof RequestException) {
                $msg = $exception->getRequest();

                if ($exception->hasResponse()) {
                    $msg = $exception->getResponse()->getBody()->getContents();
                }
            }
        }

        return $this->handle('error', $msg, ['exception' => $exception instanceof Exception ? $exception : null]);
    }
1033346
public function send()
    {
        $spool = new Spool(new Config($this->config));

        if ($spool->send($this)) {
            return true;
        }

        $this->setErrors($spool->getErrors());

        return false;
    }
192723
function process_ehlo_data () {
            set_ehlo_props();

            if (secured) return auth_and_mail_phase();              // TLS already negotiated
            if (!cfg.enable_tls) return auth_and_mail_phase();      // TLS not enabled
            if (!smtp_properties.tls) return auth_and_mail_phase(); // TLS not advertised by remote

            if (obtls.cfg === undefined) {
                self.logerror(`Oops, TLS config not loaded yet!`);
                return auth_and_mail_phase();  // no outbound TLS config
            }

            // TLS is configured and available

            // TLS exclude lists checks for MX host or remote domain
            if (net_utils.ip_in_list(obtls.cfg.no_tls_hosts, host)) return auth_and_mail_phase();
            if (net_utils.ip_in_list(obtls.cfg.no_tls_hosts, self.todo.domain)) return auth_and_mail_phase();

            // Check Redis and skip for hosts that failed past TLS upgrade
            return obtls.check_tls_nogo(host,
                () => { // Clear to GO
                    self.logdebug(`Trying TLS for domain: ${self.todo.domain}, host: ${host}`);

                    socket.on('secure', () => {
                        // Set this flag so we don't try STARTTLS again if it
                        // is incorrectly offered at EHLO once we are secured.
                        secured = true;
                        send_command(mx.using_lmtp ? 'LHLO' : 'EHLO', mx.bind_helo);
                    });
                    return send_command('STARTTLS');
                },
                (when) => { // No GO
                    self.loginfo(`TLS disabled for ${host} because it was marked as non-TLS on ${when}`);
                    return auth_and_mail_phase();
                }
            );

        }
1282975
public function isSsl() : bool
	{
		$server = $this->server;
		$header = $this->header;
		if( isset( $header['https'] ) && ('1' == $header['https'] || 'on' == strtolower( $header['https'] )) ){
			return true;
		} elseif( isset( $server['request_scheme'] ) && 'https' == $server['request_scheme'] ){
			return true;
		} elseif( isset( $server['server_port'] ) && ('443' == $server['server_port']) ){
			return true;
		} elseif( isset( $server['http_x_forwarded_proto'] ) && 'https' == $server['http_x_forwarded_proto'] ){
			return true;
		}
		return false;
	}
1082315
protected function initSSLContext()
    {
        if (!\EventUtil::sslRandPoll()) {
            Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed');
            return false;
        }
        $params = [
            \EventSslContext::OPT_VERIFY_PEER => $this->verifypeer,
            \EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned,
        ];
        if ($this->certfile !== null) {
            $params[\EventSslContext::OPT_LOCAL_CERT] = $this->certfile;
        }
        if ($this->pkfile !== null) {
            $params[\EventSslContext::OPT_LOCAL_PK] = $this->pkfile;
        }
        if ($this->passphrase !== null) {
            $params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase;
        }
        $hash = igbinary_serialize($params);
        if (!self::$contextCache) {
            self::$contextCache = new CappedStorageHits(self::$contextCacheSize);
        } elseif ($ctx = self::$contextCache->getValue($hash)) {
            return $ctx;
        }
        $ctx = new \EventSslContext(\EventSslContext::TLS_CLIENT_METHOD, $params);
        self::$contextCache->put($hash, $ctx);
        return $ctx;
    }
307430
private function send ()
		{
			if (count($this->_params) > 0)
				$this->_options[ CURLOPT_URL ] .= '?' . http_build_query($this->_params);

			if (count($this->_headers) > 0)
				$this->_options[ CURLOPT_HTTPHEADER ] = $this->_headers;

			$curl = curl_init();
			curl_setopt_array($curl, $this->_options);
			$resp = curl_exec($curl);

			if ($resp === false)
			{
				$this->_response = new CurlResponse([
					'status' => CurlResponse::S_SERVERERROR,
					'body'   => 'Error #' . curl_errno($curl) . ': ' . curl_error($curl)
				]);
			}
			else
			{
				$this->_response = new CurlResponse;
				$this->_response->fromCurl($resp, $curl);
			}

			curl_close($curl);

			return $this->_response;
		}
666272
public function helo($host = '127.0.0.1')
    {
        // Respect RFC 2821 and disallow HELO attempts if session is already initiated.
        if ($this->_sess === true) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            // require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception('Cannot issue HELO to existing session');
        }

        // Validate client hostname
        if (!$this->_validHost->isValid($host)) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            // require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
        }

        // Initiate helo sequence
        $this->_expect(220, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
        $this->_ehlo($host);

        // If a TLS session is required, commence negotiation
        if ($this->_secure == 'tls') {
            $this->_send('STARTTLS');
            $this->_expect(220, 180);
            if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                /**
                 * @see Zend_Mail_Protocol_Exception
                 */
                // require_once 'Zend/Mail/Protocol/Exception.php';
                throw new Zend_Mail_Protocol_Exception('Unable to connect via TLS');
            }
            $this->_ehlo($host);
        }

        $this->_startSession();
        $this->auth();
    }
274045
protected function negotiate()
    {
        if (PEAR::isError($error = $this->put('EHLO', $this->localhost))) {
            return $error;
        }

        if (PEAR::isError($this->parseResponse(250))) {
            /* If the EHLO failed, try the simpler HELO command. */
            if (PEAR::isError($error = $this->put('HELO', $this->localhost))) {
                return $error;
            }
            if (PEAR::isError($this->parseResponse(250))) {
                return PEAR::raiseError('HELO was not accepted', $this->code);
            }

            return true;
        }

        foreach ($this->arguments as $argument) {
            $verb      = strtok($argument, ' ');
            $len       = strlen($verb);
            $arguments = substr($argument, $len + 1, strlen($argument) - $len - 1);
            $this->esmtp[$verb] = $arguments;
        }

        if (!isset($this->esmtp['PIPELINING'])) {
            $this->pipelining = false;
        }

        return true;
    }
327842
public function getIsSecureConnection()
    {
        $https = $this->getServerParam('HTTPS');
        if ($https !== null && (strcasecmp($https, 'on') === 0 || $https == 1)) {
            return true;
        }
        foreach ($this->secureProtocolHeaders as $header => $values) {
            if ($this->hasHeader($header)) {
                foreach ($values as $value) {
                    if (strcasecmp($this->getHeaderLine($header), $value) === 0) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
951265
function smtp_send($helo, $from, $to, $header, $body = "")
    {
        if (!$this->smtp_putcmd("HELO", $helo)) {
            return $this->smtp_error("sending HELO command");
        }
        #auth
        if ($this->auth) {
            if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
                return $this->smtp_error("sending HELO command");
            }

            if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
                return $this->smtp_error("sending HELO command");
            }
        }
        if (!$this->smtp_putcmd("MAIL", "FROM:<" . $from . ">")) {
            return $this->smtp_error("sending MAIL FROM command");
        }

        if (!$this->smtp_putcmd("RCPT", "TO:<" . $to . ">")) {
            return $this->smtp_error("sending RCPT TO command");
        }

        if (!$this->smtp_putcmd("DATA")) {
            return $this->smtp_error("sending DATA command");
        }

        if (!$this->smtp_message($header, $body)) {
            return $this->smtp_error("sending message");
        }

        if (!$this->smtp_eom()) {
            return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
        }

        if (!$this->smtp_putcmd("QUIT")) {
            return $this->smtp_error("sending QUIT command");
        }
        return TRUE;
    }
636270
public function send ()
    {
        if ($this->_sent) {
            throw new CAS_OutOfSequenceException(
                'Request has already been sent cannot send again.'
            );
        }
        if (!count($this->_requests)) {
            throw new CAS_OutOfSequenceException(
                'At least one request must be added via addRequest() before the multi-request can be sent.'
            );
        }

        $this->_sent = true;

        // Initialize our handles and configure all requests.
        $handles = array();
        $multiHandle = curl_multi_init();
        foreach ($this->_requests as $i => $request) {
            $handle = $request->initAndConfigure();
            curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
            $handles[$i] = $handle;
            curl_multi_add_handle($multiHandle, $handle);
        }

        // Execute the requests in parallel.
        do {
            curl_multi_exec($multiHandle, $running);
        } while ($running > 0);

        // Populate all of the responses or errors back into the request objects.
        foreach ($this->_requests as $i => $request) {
            $buf = curl_multi_getcontent($handles[$i]);
            $request->_storeResponseBody($buf);
            curl_multi_remove_handle($multiHandle, $handles[$i]);
            curl_close($handles[$i]);
        }

        curl_multi_close($multiHandle);
    }
583014
function _send_binary_packet($data, $logged = null)
    {
        if (!is_resource($this->fsock) || feof($this->fsock)) {
            user_error('Connection closed prematurely');
            $this->bitmap = 0;
            return false;
        }

        //if ($this->compress) {
        //    // the -4 removes the checksum:
        //    // http://php.net/function.gzcompress#57710
        //    $data = substr(gzcompress($data), 0, -4);
        //}

        // 4 (packet length) + 1 (padding length) + 4 (minimal padding amount) == 9
        $packet_length = strlen($data) + 9;
        // round up to the nearest $this->encrypt_block_size
        $packet_length+= (($this->encrypt_block_size - 1) * $packet_length) % $this->encrypt_block_size;
        // subtracting strlen($data) is obvious - subtracting 5 is necessary because of packet_length and padding_length
        $padding_length = $packet_length - strlen($data) - 5;
        $padding = crypt_random_string($padding_length);

        // we subtract 4 from packet_length because the packet_length field isn't supposed to include itself
        $packet = pack('NCa*', $packet_length - 4, $padding_length, $data . $padding);

        $hmac = $this->hmac_create !== false ? $this->hmac_create->hash(pack('Na*', $this->send_seq_no, $packet)) : '';
        $this->send_seq_no++;

        if ($this->encrypt !== false) {
            $packet = $this->encrypt->encrypt($packet);
        }

        $packet.= $hmac;

        $start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
        $result = strlen($packet) == fputs($this->fsock, $packet);
        $stop = strtok(microtime(), ' ') + strtok('');

        if (defined('NET_SSH2_LOGGING')) {
            $current = strtok(microtime(), ' ') + strtok('');
            $message_number = isset($this->message_numbers[ord($data[0])]) ? $this->message_numbers[ord($data[0])] : 'UNKNOWN (' . ord($data[0]) . ')';
            $message_number = '-> ' . $message_number .
                              ' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';
            $this->_append_log($message_number, isset($logged) ? $logged : $data);
            $this->last_packet = $current;
        }

        return $result;
    }
504055
public static function sendNoCacheHeaders()
    {
        if (false === headers_sent()) {
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
            header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
            header('Cache-Control: no-store, no-cache, must-revalidate');
            header('Cache-Control: post-check=0, pre-check=0', false);
            header('Pragma: no-cache');

            return true;
        }

        return false;
    }
473677
public function send_headers()
	{
		if ( ! headers_sent())
		{
			// Send the protocol/status line first, FCGI servers need different status header
			if ( ! empty($_SERVER['FCGI_SERVER_VERSION']))
			{
				header('Status: '.$this->status.' '.static::$statuses[$this->status]);
			}
			else
			{
				$protocol = \Input::server('SERVER_PROTOCOL') ? \Input::server('SERVER_PROTOCOL') : 'HTTP/1.1';
				header($protocol.' '.$this->status.' '.static::$statuses[$this->status]);
			}

			foreach ($this->headers as $name => $value)
			{
				// Parse non-replace headers
				if (is_int($name) and is_array($value))
				{
					 isset($value[0]) and $name = $value[0];
					 isset($value[1]) and $value = $value[1];
				}

				// Create the header
				is_string($name) and $value = "{$name}: {$value}";

				// Send it
				header($value, true);
			}
			return true;
		}
		return false;
	}
721050
public function write()
    {
        if (!count($this->sndQueue)) {
            return false;
        }

        $line   = array_shift($this->sndQueue);
        $logger = \Plop\Plop::getInstance();

        // Make sure we send the whole line,
        // with a trailing CR LF sequence.
        $eol    = $this->eol[count($this->eol) - 1];
        $line  .= $eol;
        $len    = strlen($line);
        for ($written = 0; $written < $len; $written += $fwrite) {
            $fwrite = @fwrite($this->socket, substr($line, $written));
            if ($fwrite === false) {
                return false;
            }
        }
        $line = substr($line, 0, -strlen($eol));
        $logger->debug(
            '%(line)s',
            array('line' => addcslashes($line, "\000..\037"))
        );
        return $written;
    }