$host) { $error_number = ""; $error_string = ""; // Connect to IMAP-server $stream = fsockopen( $host, $all_imap_ports[$idx], $error_number, $error_string, 15 ); if ( $stream ) { $response = fgets( $stream, 1024 ); $logon_str = "a001 LOGIN \"" . self::quote_imap( $user ) . "\" \"" . self::quote_imap( $pass ) . "\"\r\n"; fputs( $stream, $logon_str ); $response = fgets( $stream, 1024 ); if ( substr( $response, 5, 2 ) == 'OK' ) { fputs( $stream, "a002 LOGOUT\r\n" ); $response = fgets( $stream, 1024 ); fclose( $stream ); return $user; } fputs( $stream, "a002 LOGOUT\r\n" ); fclose( $stream ); } } // return failure return false; } /** */ public function canValidateByEmail() : bool { return true; } /** */ public function canValidateByUsername() : bool { return false; } /* quote_imap($str) * * quote char's into valid IMAP string * * $str - String to be quoted * * Returns: * quoted string */ private static function quote_imap(string $str) : string { return preg_replace('/(["\\\\])/', '\\$1', $str); } }