23 if (!class_exists(
'FUNC4')) require_once
'FUNC4.php';
36 if (!is_resource(
$conn))
return FUNC4::trace($debug,
'invalid resource connection', 1);
41 if ($result = fgets(
$conn, $_pop3->BLEN)) {
43 if (substr($result, 0, 3) !=
'+OK') {
48 $resp[] =
'can not read';
52 }
while ($result[3] ==
'-');
57 function connect($host = null, $user = null, $pass = null, $port = null, $vssl = null, $tout = null, $context = null, $debug = null) {
62 if ($port == null) $port = $_pop3->PORT;
63 if ($tout == null) $tout = $_pop3->TOUT;
65 if (!is_string($host)) $err[] =
'invalid host type';
69 if (!is_string($user)) $err[] =
'invalid username type';
70 else if (($user =
FUNC4::str_clear($user)) ==
'') $err[] =
'invalid username value';
71 if (!is_string($pass)) $err[] =
'invalid password type';
72 else if (($pass =
FUNC4::str_clear($pass)) ==
'') $err[] =
'invalid password value';
73 if (!(is_int($port) && $port > 0)) $err[] =
'invalid port value';
75 if (!is_string($vssl)) $err[] =
'invalid ssl version type';
77 $vssl = strtolower($vssl);
78 if (!($vssl ==
'tls' || $vssl ==
'ssl' || $vssl ==
'sslv2' || $vssl ==
'sslv3')) $err[] =
'invalid ssl version value';
81 if (!(is_int($tout) && $tout > 0)) $err[] =
'invalid timeout value';
82 if ($context != null && !is_resource($context)) $err[] =
'invalid context type';
83 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
87 $prt = ($vssl == null) ?
'tcp' : $vssl;
88 $conn = ($context == null) ? fsockopen($prt.
'://'.$host, $port, $errno, $errstr, $tout) : fsockopen($prt.
'://'.$host, $port, $errno, $errstr, $tout, $context);
89 if (!
$conn) $_RESULT[401] = $errstr;
90 else if (!socket_set_timeout(
$conn, $_pop3->COUT)) $_RESULT[402] =
'could not set socket timeout';
101 function auth(
$conn = null, $user = null, $pass = null, $debug = null) {
106 if (!is_resource(
$conn)) $err[] =
'invalid resource connection';
107 if (!is_string($user)) $err[] =
'invalid username type';
108 else if (($user =
FUNC4::str_clear($user)) ==
'') $err[] =
'invalid username value';
109 if (!is_string($pass)) $err[] =
'invalid password type';
110 else if (($pass =
FUNC4::str_clear($pass)) ==
'') $err[] =
'invalid password value';
111 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
115 if (!fwrite(
$conn,
'USER '.$user.$_pop3->CRLF)) $_RESULT[404] =
'can not write';
117 else if (!fwrite(
$conn,
'PASS '.$pass.$_pop3->CRLF)) $_RESULT[405] =
'can not write';
120 $_RESULT[407] = $resp;
134 if (!fwrite(
$conn,
'QUIT'.$_pop3->CRLF)) $_RESULT[437] =
'can not write';
136 else $_RESULT[439] = $resp;
137 return @fclose(
$conn);
149 if (!fwrite(
$conn,
'NOOP'.$_pop3->CRLF)) $_RESULT[408] =
'can not write';
152 $_RESULT[410] = $resp;
167 if (!fwrite(
$conn,
'RSET'.$_pop3->CRLF)) $_RESULT[411] =
'can not write';
170 $_RESULT[413] = $resp;
185 if (!fwrite(
$conn,
'QUIT'.$_pop3->CRLF)) $_RESULT[414] =
'can not write';
188 $_RESULT[416] = $resp;
203 if (!fwrite(
$conn,
'STAT'.$_pop3->CRLF)) $_RESULT[417] =
'can not write';
206 if (count($exp = explode(
' ', substr($resp[0], 4, -strlen($_pop3->CRLF)))) == 2) {
207 $val1 = intval($exp[0]);
208 $val2 = intval($exp[1]);
209 if (strval($val1) === $exp[0] && strval($val2) === $exp[1]) {
210 $ret = array($val1 => $val2);
211 $_RESULT[421] = $resp;
212 }
else $_RESULT[420] = $resp;
213 }
else $_RESULT[419] = $resp;
224 if (!is_resource(
$conn)) $err[] =
'invalid resource connection';
225 if (!(is_int($msg) && $msg > 0)) $err[] =
'invalid message number';
226 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
230 if (!fwrite(
$conn,
'DELE '.$msg.$_pop3->CRLF)) $_RESULT[422] =
'can not write';
233 $_RESULT[424] = $resp;
245 if (!is_resource(
$conn)) $err[] =
'invalid resource connection';
246 if (!(is_int($msg) && $msg > 0)) $err[] =
'invalid message number';
247 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
251 if (!fwrite(
$conn,
'RETR '.$msg.$_pop3->CRLF)) $_RESULT[425] =
'can not write';
256 if ($res = fgets(
$conn, $_pop3->BLEN)) $ret .= $res;
258 $_RESULT[427] =
'can not read';
262 }
while ($res !=
'.'.$_pop3->CRLF);
264 $ret = substr($ret, 0, -strlen($_pop3->CRLF.
'.'.$_pop3->CRLF));
265 $_RESULT[428] = $resp;
277 if (!is_resource(
$conn)) $err[] =
'invalid resource connection';
278 if ($msg == null) $msg = 0;
279 if (!(is_int($msg) && $msg >= 0)) $err[] =
'invalid message number';
280 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
284 $num = ($msg > 0) ?
true :
false;
285 if (!fwrite(
$conn,
'LIST'.($num ?
' '.$msg :
'').$_pop3->CRLF)) $_RESULT[429] =
'can not write';
289 if (count($exp = explode(
' ', substr($resp[0], 4, -strlen($_pop3->CRLF)))) == 2) {
290 $val1 = intval($exp[0]);
291 $val2 = intval($exp[1]);
292 if (strval($val1) === $exp[0] && strval($val2) === $exp[1]) {
293 $ret = array($val1 => $val2);
294 $_RESULT[433] = $resp;
295 }
else $_RESULT[432] = $resp;
296 }
else $_RESULT[431] = $resp;
299 if ($res = fgets(
$conn, $_pop3->BLEN)) {
300 if (count($exp = explode(
' ', substr($res, 0, -strlen($_pop3->CRLF)))) == 2) {
301 $val1 = intval($exp[0]);
302 $val2 = intval($exp[1]);
303 if (strval($val1) === $exp[0] && strval($val2) === $exp[1]) {
305 $_RESULT[436] = $resp;
307 }
else if ($res[0] !=
'.') {
308 $_RESULT[435] = $res;
313 $_RESULT[434] =
'can not read';
317 }
while ($res[0] !=
'.');
329 if (!is_resource(
$conn)) $err[] =
'invalid resource connection';
330 if ($msg == null) $msg = 0;
331 if (!(is_int($msg) && $msg >= 0)) $err[] =
'invalid message number';
332 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
336 $num = ($msg > 0) ?
true :
false;
337 if (!fwrite(
$conn,
'UIDL'.($num ?
' '.$msg :
'').$_pop3->CRLF)) $_RESULT[440] =
'can not write';
341 if (count($exp = explode(
' ', substr($resp[0], 4, -strlen($_pop3->CRLF)))) == 2) {
342 $val1 = intval($exp[0]);
343 $val2 = trim($exp[1]);
344 if (strval($val1) === $exp[0] && $val2 !=
'') {
345 $ret = array($val1 => $val2);
346 $_RESULT[444] = $resp;
347 }
else $_RESULT[443] = $resp;
348 }
else $_RESULT[442] = $resp;
351 if ($res = fgets(
$conn, $_pop3->BLEN)) {
352 if (count($exp = explode(
' ', substr($res, 0, -strlen($_pop3->CRLF)))) == 2) {
353 $val1 = intval($exp[0]);
354 $val2 = trim($exp[1]);
355 if (strval($val1) === $exp[0] && $val2 !=
'') {
357 $_RESULT[446] = $resp;
359 }
else if ($res[0] !=
'.') {
360 $_RESULT[445] = $res;
365 $_RESULT[434] =
'can not read';
369 }
while ($res[0] !=
'.');