PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/_jppf/classes/pop3emailclient/pop3_old.php

https://bitbucket.org/countach/jpphpframework
PHP | 772 lines | 662 code | 59 blank | 51 comment | 149 complexity | c68f0165830e7a3499d07fa5309bb072 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * pop3.php
  4. *
  5. * @(#) $Header: /home/mlemos/cvsroot/pop3/pop3.php,v 1.18 2006/06/12 21:02:39 mlemos Exp $
  6. *
  7. */
  8. class pop3_class
  9. {
  10. var $hostname="";
  11. var $port=110;
  12. var $tls=0;
  13. var $quit_handshake=0;
  14. var $error="";
  15. var $authentication_mechanism="USER";
  16. var $realm="";
  17. var $workstation="";
  18. var $join_continuation_header_lines=1;
  19. var $is_data="";
  20. /* Private variables - DO NOT ACCESS */
  21. var $connection=0;
  22. var $state="DISCONNECTED";
  23. var $greeting="";
  24. var $must_update=0;
  25. var $debug=0;
  26. var $html_debug=0;
  27. var $next_token="";
  28. var $message_buffer="";
  29. /* Private methods - DO NOT CALL */
  30. Function Tokenize($string,$separator="")
  31. {
  32. if(!strcmp($separator,""))
  33. {
  34. $separator=$string;
  35. $string=$this->next_token;
  36. }
  37. for($character=0;$character<strlen($separator);$character++)
  38. {
  39. if(GetType($position=strpos($string,$separator[$character]))=="integer")
  40. $found=(IsSet($found) ? min($found,$position) : $position);
  41. }
  42. if(IsSet($found))
  43. {
  44. $this->next_token=substr($string,$found+1);
  45. return(substr($string,0,$found));
  46. }
  47. else
  48. {
  49. $this->next_token="";
  50. return($string);
  51. }
  52. }
  53. Function SetError($error)
  54. {
  55. return($this->error=$error);
  56. }
  57. Function OutputDebug($message)
  58. {
  59. $message.="\n";
  60. if($this->html_debug)
  61. $message=str_replace("\n","<br />\n",HtmlSpecialChars($message));
  62. echo $message;
  63. flush();
  64. }
  65. Function GetLine()
  66. {
  67. for($line="";;)
  68. {
  69. if(feof($this->connection))
  70. return(0);
  71. $line.=fgets($this->connection,100);
  72. $length=strlen($line);
  73. if($length>=2
  74. && substr($line,$length-2,2)=="\r\n")
  75. {
  76. $line=substr($line,0,$length-2);
  77. if($this->debug)
  78. $this->OutputDebug("S $line");
  79. return($line);
  80. }
  81. }
  82. }
  83. Function PutLine($line)
  84. {
  85. if($this->debug)
  86. $this->OutputDebug("C $line");
  87. return(fputs($this->connection,"$line\r\n"));
  88. }
  89. Function OpenConnection()
  90. {
  91. if($this->tls)
  92. {
  93. $version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
  94. $php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
  95. if($php_version<4003000)
  96. return("establishing TLS connections requires at least PHP version 4.3.0");
  97. if(!function_exists("extension_loaded")
  98. || !extension_loaded("openssl"))
  99. return("establishing TLS connections requires the OpenSSL extension enabled");
  100. }
  101. if($this->hostname=="")
  102. return($this->SetError("2 it was not specified a valid hostname"));
  103. if($this->debug)
  104. $this->OutputDebug("Connecting to ".$this->hostname." ...");
  105. if(($this->connection=@fsockopen(($this->tls ? "tls://" : "").$this->hostname,$this->port,$error))==0)
  106. {
  107. switch($error)
  108. {
  109. case -3:
  110. return($this->SetError("-3 socket could not be created"));
  111. case -4:
  112. return($this->SetError("-4 dns lookup on hostname \"$hostname\" failed"));
  113. case -5:
  114. return($this->SetError("-5 connection refused or timed out"));
  115. case -6:
  116. return($this->SetError("-6 fdopen() call failed"));
  117. case -7:
  118. return($this->SetError("-7 setvbuf() call failed"));
  119. default:
  120. return($this->SetError($error." could not connect to the host \"".$this->hostname."\""));
  121. }
  122. }
  123. return("");
  124. }
  125. Function CloseConnection()
  126. {
  127. if($this->debug)
  128. $this->OutputDebug("Closing connection.");
  129. if($this->connection!=0)
  130. {
  131. fclose($this->connection);
  132. $this->connection=0;
  133. }
  134. }
  135. /* Public methods */
  136. /* Open method - set the object variable $hostname to the POP3 server address. */
  137. Function Open()
  138. {
  139. if($this->state!="DISCONNECTED")
  140. return($this->SetError("1 a connection is already opened"));
  141. if(($error=$this->OpenConnection())!="")
  142. return($error);
  143. $this->greeting=$this->GetLine();
  144. if(GetType($this->greeting)!="string"
  145. || $this->Tokenize($this->greeting," ")!="+OK")
  146. {
  147. $this->CloseConnection();
  148. return($this->SetError("3 POP3 server greeting was not found"));
  149. }
  150. $this->Tokenize("<");
  151. $this->must_update=0;
  152. $this->state="AUTHORIZATION";
  153. return("");
  154. }
  155. /* Close method - this method must be called at least if there are any
  156. messages to be deleted */
  157. Function Close()
  158. {
  159. if($this->state=="DISCONNECTED")
  160. return($this->SetError("no connection was opened"));
  161. if($this->must_update
  162. || $this->quit_handshake)
  163. {
  164. if($this->PutLine("QUIT")==0)
  165. return($this->SetError("Could not send the QUIT command"));
  166. $response=$this->GetLine();
  167. if(GetType($response)!="string")
  168. return($this->SetError("Could not get quit command response"));
  169. if($this->Tokenize($response," ")!="+OK")
  170. return($this->SetError("Could not quit the connection: ".$this->Tokenize("\r\n")));
  171. }
  172. $this->CloseConnection();
  173. $this->state="DISCONNECTED";
  174. return("");
  175. }
  176. /* Login method - pass the user name and password of POP account. Set
  177. $apop to 1 or 0 wether you want to login using APOP method or not. */
  178. Function Login($user,$password,$apop=0)
  179. {
  180. if($this->state!="AUTHORIZATION")
  181. return($this->SetError("connection is not in AUTHORIZATION state"));
  182. if($apop)
  183. {
  184. if(!strcmp($this->greeting,""))
  185. return($this->SetError("Server does not seem to support APOP authentication"));
  186. if($this->PutLine("APOP $user ".md5("<".$this->greeting.">".$password))==0)
  187. return($this->SetError("Could not send the APOP command"));
  188. $response=$this->GetLine();
  189. if(GetType($response)!="string")
  190. return($this->SetError("Could not get APOP login command response"));
  191. if($this->Tokenize($response," ")!="+OK")
  192. return($this->SetError("APOP login failed: ".$this->Tokenize("\r\n")));
  193. }
  194. else
  195. {
  196. $authenticated=0;
  197. if(strcmp($this->authentication_mechanism,"USER")
  198. && function_exists("class_exists")
  199. && class_exists("sasl_client_class"))
  200. {
  201. if(strlen($this->authentication_mechanism))
  202. $mechanisms=array($this->authentication_mechanism);
  203. else
  204. {
  205. $mechanisms=array();
  206. if($this->PutLine("CAPA")==0)
  207. return($this->SetError("Could not send the CAPA command"));
  208. $response=$this->GetLine();
  209. if(GetType($response)!="string")
  210. return($this->SetError("Could not get CAPA command response"));
  211. if(!strcmp($this->Tokenize($response," "),"+OK"))
  212. {
  213. for(;;)
  214. {
  215. $response=$this->GetLine();
  216. if(GetType($response)!="string")
  217. return($this->SetError("Could not retrieve the supported authentication methods"));
  218. switch($this->Tokenize($response," "))
  219. {
  220. case ".":
  221. break 2;
  222. case "SASL":
  223. for($method=1;strlen($mechanism=$this->Tokenize(" "));$method++)
  224. $mechanisms[]=$mechanism;
  225. break;
  226. }
  227. }
  228. }
  229. }
  230. $sasl=new sasl_client_class;
  231. $sasl->SetCredential("user",$user);
  232. $sasl->SetCredential("password",$password);
  233. if(strlen($this->realm))
  234. $sasl->SetCredential("realm",$this->realm);
  235. if(strlen($this->workstation))
  236. $sasl->SetCredential("workstation",$this->workstation);
  237. do
  238. {
  239. $status=$sasl->Start($mechanisms,$message,$interactions);
  240. }
  241. while($status==SASL_INTERACT);
  242. switch($status)
  243. {
  244. case SASL_CONTINUE:
  245. break;
  246. case SASL_NOMECH:
  247. if(strlen($this->authentication_mechanism))
  248. return($this->SetError("authenticated mechanism ".$this->authentication_mechanism." may not be used: ".$sasl->error));
  249. break;
  250. default:
  251. return($this->SetError("Could not start the SASL authentication client: ".$sasl->error));
  252. }
  253. if(strlen($sasl->mechanism))
  254. {
  255. if($this->PutLine("AUTH ".$sasl->mechanism.(IsSet($message) ? " ".base64_encode($message) : ""))==0)
  256. return("Could not send the AUTH command");
  257. $response=$this->GetLine();
  258. if(GetType($response)!="string")
  259. return("Could not get AUTH command response");
  260. switch($this->Tokenize($response," "))
  261. {
  262. case "+OK":
  263. $response="";
  264. break;
  265. case "+":
  266. $response=base64_decode($this->Tokenize("\r\n"));
  267. break;
  268. default:
  269. return($this->SetError("Authentication error: ".$this->Tokenize("\r\n")));
  270. }
  271. for(;!$authenticated;)
  272. {
  273. do
  274. {
  275. $status=$sasl->Step($response,$message,$interactions);
  276. }
  277. while($status==SASL_INTERACT);
  278. switch($status)
  279. {
  280. case SASL_CONTINUE:
  281. if($this->PutLine(base64_encode($message))==0)
  282. return("Could not send message authentication step message");
  283. $response=$this->GetLine();
  284. if(GetType($response)!="string")
  285. return("Could not get authentication step message response");
  286. switch($this->Tokenize($response," "))
  287. {
  288. case "+OK":
  289. $authenticated=1;
  290. break;
  291. case "+":
  292. $response=base64_decode($this->Tokenize("\r\n"));
  293. break;
  294. default:
  295. return($this->SetError("Authentication error: ".$this->Tokenize("\r\n")));
  296. }
  297. break;
  298. default:
  299. return($this->SetError("Could not process the SASL authentication step: ".$sasl->error));
  300. }
  301. }
  302. }
  303. }
  304. if(!$authenticated)
  305. {
  306. if($this->PutLine("USER $user")==0)
  307. return($this->SetError("Could not send the USER command"));
  308. $response=$this->GetLine();
  309. if(GetType($response)!="string")
  310. return($this->SetError("Could not get user login entry response"));
  311. if($this->Tokenize($response," ")!="+OK")
  312. return($this->SetError("User error: ".$this->Tokenize("\r\n")));
  313. if($this->PutLine("PASS $password")==0)
  314. return($this->SetError("Could not send the PASS command"));
  315. $response=$this->GetLine();
  316. if(GetType($response)!="string")
  317. return($this->SetError("Could not get login password entry response"));
  318. if($this->Tokenize($response," ")!="+OK")
  319. return($this->SetError("Password error: ".$this->Tokenize("\r\n")));
  320. }
  321. }
  322. $this->state="TRANSACTION";
  323. return("");
  324. }
  325. /* Statistics method - pass references to variables to hold the number of
  326. messages in the mail box and the size that they take in bytes. */
  327. Function Statistics(&$messages,&$size)
  328. {
  329. if($this->state!="TRANSACTION")
  330. return($this->SetError("connection is not in TRANSACTION state"));
  331. if($this->PutLine("STAT")==0)
  332. return($this->SetError("Could not send the STAT command"));
  333. $response=$this->GetLine();
  334. if(GetType($response)!="string")
  335. return($this->SetError("Could not get the statistics command response"));
  336. if($this->Tokenize($response," ")!="+OK")
  337. return($this->SetError("Could not get the statistics: ".$this->Tokenize("\r\n")));
  338. $messages=$this->Tokenize(" ");
  339. $size=$this->Tokenize(" ");
  340. return("");
  341. }
  342. /* ListMessages method - the $message argument indicates the number of a
  343. message to be listed. If you specify an empty string it will list all
  344. messages in the mail box. The $unique_id flag indicates if you want
  345. to list the each message unique identifier, otherwise it will
  346. return the size of each message listed. If you list all messages the
  347. result will be returned in an array. */
  348. Function ListMessages($message,$unique_id)
  349. {
  350. if($this->state!="TRANSACTION")
  351. return($this->SetError("connection is not in TRANSACTION state"));
  352. if($unique_id)
  353. $list_command="UIDL";
  354. else
  355. $list_command="LIST";
  356. if($this->PutLine("$list_command".($message ? " ".$message : ""))==0)
  357. return($this->SetError("Could not send the $list_command command"));
  358. $response=$this->GetLine();
  359. if(GetType($response)!="string")
  360. return($this->SetError("Could not get message list command response"));
  361. if($this->Tokenize($response," ")!="+OK")
  362. return($this->SetError("Could not get the message listing: ".$this->Tokenize("\r\n")));
  363. if($message=="")
  364. {
  365. for($messages=array();;)
  366. {
  367. $response=$this->GetLine();
  368. if(GetType($response)!="string")
  369. return($this->SetError("Could not get message list response"));
  370. if($response==".")
  371. break;
  372. $message=intval($this->Tokenize($response," "));
  373. if($unique_id)
  374. $messages[$message]=$this->Tokenize(" ");
  375. else
  376. $messages[$message]=intval($this->Tokenize(" "));
  377. }
  378. return($messages);
  379. }
  380. else
  381. {
  382. $message=intval($this->Tokenize(" "));
  383. $value=$this->Tokenize(" ");
  384. return($unique_id ? $value : intval($value));
  385. }
  386. }
  387. /* RetrieveMessage method - the $message argument indicates the number of
  388. a message to be listed. Pass a reference variables that will hold the
  389. arrays of the $header and $body lines. The $lines argument tells how
  390. many lines of the message are to be retrieved. Pass a negative number
  391. if you want to retrieve the whole message. */
  392. Function RetrieveMessage($message,&$headers,&$body,$lines)
  393. {
  394. if($this->state!="TRANSACTION")
  395. return($this->SetError("connection is not in TRANSACTION state"));
  396. if($lines<0)
  397. {
  398. $command="RETR";
  399. $arguments="$message";
  400. }
  401. else
  402. {
  403. $command="TOP";
  404. $arguments="$message $lines";
  405. }
  406. if($this->PutLine("$command $arguments")==0)
  407. return($this->SetError("Could not send the $command command"));
  408. $response=$this->GetLine();
  409. if(GetType($response)!="string")
  410. return($this->SetError("Could not get message retrieval command response"));
  411. if($this->Tokenize($response," ")!="+OK")
  412. return($this->SetError("Could not retrieve the message: ".$this->Tokenize("\r\n")));
  413. for($headers=$body=array(),$line=0;;)
  414. {
  415. $response=$this->GetLine();
  416. if(GetType($response)!="string")
  417. return($this->SetError("Could not retrieve the message"));
  418. switch($response)
  419. {
  420. case ".":
  421. return("");
  422. case "":
  423. break 2;
  424. default:
  425. if(substr($response,0,1)==".")
  426. $response=substr($response,1,strlen($response)-1);
  427. break;
  428. }
  429. if($this->join_continuation_header_lines
  430. && $line>0
  431. && ($response[0]=="\t"
  432. || $response[0]==" "))
  433. $headers[$line-1].=$response;
  434. else
  435. {
  436. $headers[$line]=$response;
  437. $line++;
  438. }
  439. }
  440. for($line=0;;$line++)
  441. {
  442. $response=$this->GetLine();
  443. if(GetType($response)!="string")
  444. return($this->SetError("Could not retrieve the message"));
  445. switch($response)
  446. {
  447. case ".":
  448. return("");
  449. default:
  450. if(substr($response,0,1)==".")
  451. $response=substr($response,1,strlen($response)-1);
  452. break;
  453. }
  454. $body[$line]=$response;
  455. }
  456. return("");
  457. }
  458. /* RetrieveMessageRaw method - the $message argument indicates the number of
  459. a message to be listed. Pass a reference variable that will hold the
  460. raw data of the message The $lines argument tells how
  461. many lines of the message are to be retrieved. Pass a negative number
  462. if you want to retrieve the whole message. */
  463. Function RetrieveMessageRaw($message,&$rawdata,$lines)
  464. {
  465. $rawdata='';
  466. if($this->state!="TRANSACTION")
  467. return($this->SetError("connection is not in TRANSACTION state"));
  468. if($lines<0)
  469. {
  470. $command="RETR";
  471. $arguments="$message";
  472. }
  473. else
  474. {
  475. $command="TOP";
  476. $arguments="$message $lines";
  477. }
  478. if($this->PutLine("$command $arguments")==0)
  479. return($this->SetError("Could not send the $command command"));
  480. $response=$this->GetLine();
  481. if(GetType($response)!="string")
  482. return($this->SetError("Could not get message retrieval command response"));
  483. if($this->Tokenize($response," ")!="+OK")
  484. return($this->SetError("Could not retrieve the message: ".$this->Tokenize("\r\n")));
  485. $rawdata='';
  486. for(;;)
  487. {
  488. $response=$this->GetLine();
  489. if(GetType($response)!="string")
  490. return($this->SetError("Could not retrieve the message"));
  491. switch($response)
  492. {
  493. case ".":
  494. $rawdata.=$response."\r\n";
  495. return("");
  496. default:
  497. $rawdata.=$response."\r\n";
  498. break;
  499. }
  500. }
  501. return("");
  502. }
  503. /* OpenMessage method - the $message argument indicates the number of
  504. a message to be opened. The $lines argument tells how many lines of
  505. the message are to be retrieved. Pass a negative number if you want
  506. to retrieve the whole message. */
  507. Function OpenMessage($message, $lines=-1)
  508. {
  509. if($this->state!="TRANSACTION")
  510. return($this->SetError("connection is not in TRANSACTION state"));
  511. if($lines<0)
  512. {
  513. $command="RETR";
  514. $arguments="$message";
  515. }
  516. else
  517. {
  518. $command="TOP";
  519. $arguments="$message $lines";
  520. }
  521. if($this->PutLine("$command $arguments")==0)
  522. return($this->SetError("Could not send the $command command"));
  523. $response=$this->GetLine();
  524. if(GetType($response)!="string")
  525. return($this->SetError("Could not get message retrieval command response"));
  526. if($this->Tokenize($response," ")!="+OK")
  527. return($this->SetError("Could not retrieve the message: ".$this->Tokenize("\r\n")));
  528. $this->state="GETMESSAGE";
  529. $this->message_buffer="";
  530. return("");
  531. }
  532. /* GetMessage method - the $count argument indicates the number of bytes
  533. to be read from an opened message. The $message returns by reference
  534. the data read from the message. The $end_of_message argument returns
  535. by reference a boolean value indicated whether it was reached the end
  536. of the message. */
  537. Function GetMessage($count, &$message, &$end_of_message)
  538. {
  539. if($this->state!="GETMESSAGE")
  540. return($this->SetError("connection is not in GETMESSAGE state"));
  541. $message="";
  542. $end_of_message=0;
  543. while($count>strlen($this->message_buffer)
  544. && !$end_of_message)
  545. {
  546. $response=$this->GetLine();
  547. if(GetType($response)!="string")
  548. return($this->SetError("Could not retrieve the message headers"));
  549. if(!strcmp($response,"."))
  550. {
  551. $end_of_message=1;
  552. $this->state="TRANSACTION";
  553. break;
  554. }
  555. else
  556. {
  557. if(substr($response,0,1)==".")
  558. $response=substr($response,1,strlen($response)-1);
  559. $this->message_buffer.=$response."\r\n";
  560. }
  561. }
  562. if($end_of_message
  563. || $count>=strlen($this->message_buffer))
  564. {
  565. $message=$this->message_buffer;
  566. $this->message_buffer="";
  567. }
  568. else
  569. {
  570. $message=substr($this->message_buffer, 0, $count);
  571. $this->message_buffer=substr($this->message_buffer, $count);
  572. }
  573. return("");
  574. }
  575. /* DeleteMessage method - the $message argument indicates the number of
  576. a message to be marked as deleted. Messages will only be effectively
  577. deleted upon a successful call to the Close method. */
  578. Function DeleteMessage($message)
  579. {
  580. if($this->state!="TRANSACTION")
  581. return($this->SetError("connection is not in TRANSACTION state"));
  582. if($this->PutLine("DELE $message")==0)
  583. return($this->SetError("Could not send the DELE command"));
  584. $response=$this->GetLine();
  585. if(GetType($response)!="string")
  586. return($this->SetError("Could not get message delete command response"));
  587. if($this->Tokenize($response," ")!="+OK")
  588. return($this->SetError("Could not delete the message: ".$this->Tokenize("\r\n")));
  589. $this->must_update=1;
  590. return("");
  591. }
  592. /* ResetDeletedMessages method - Reset the list of marked to be deleted
  593. messages. No messages will be marked to be deleted upon a successful
  594. call to this method. */
  595. Function ResetDeletedMessages()
  596. {
  597. if($this->state!="TRANSACTION")
  598. return($this->SetError("connection is not in TRANSACTION state"));
  599. if($this->PutLine("RSET")==0)
  600. return($this->SetError("Could not send the RSET command"));
  601. $response=$this->GetLine();
  602. if(GetType($response)!="string")
  603. return($this->SetError("Could not get reset deleted messages command response"));
  604. if($this->Tokenize($response," ")!="+OK")
  605. return($this->SetError("Could not reset deleted messages: ".$this->Tokenize("\r\n")));
  606. $this->must_update=0;
  607. return("");
  608. }
  609. /* IssueNOOP method - Just pings the server to prevent it auto-close the
  610. connection after an idle timeout (tipically 10 minutes). Not very
  611. useful for most likely uses of this class. It's just here for
  612. protocol support completeness. */
  613. Function IssueNOOP()
  614. {
  615. if($this->state!="TRANSACTION")
  616. return($this->SetError("connection is not in TRANSACTION state"));
  617. if($this->PutLine("NOOP")==0)
  618. return($this->SetError("Could not send the NOOP command"));
  619. $response=$this->GetLine();
  620. if(GetType($response)!="string")
  621. return($this->SetError("Could not NOOP command response"));
  622. if($this->Tokenize($response," ")!="+OK")
  623. return($this->SetError("Could not issue the NOOP command: ".$this->Tokenize("\r\n")));
  624. return("");
  625. }
  626. };
  627. class pop3_stream
  628. {
  629. var $report_errors = 1;
  630. var $message = 0;
  631. var $read = 0;
  632. var $buffer = "";
  633. var $end_of_message=0;
  634. Function SetError($error)
  635. {
  636. if($this->report_errors)
  637. trigger_error($error);
  638. return(FALSE);
  639. }
  640. Function stream_open($path, $mode, $options, &$opened_path)
  641. {
  642. $this->report_errors = (($options & STREAM_REPORT_ERRORS) !=0);
  643. if(strcmp($mode, "r"))
  644. return($this->SetError("the message can only be opened for reading"));
  645. $url=parse_url($path);
  646. $this->pop3=new pop3_class;
  647. if(IsSet($url["host"]))
  648. $this->pop3->hostname=$url["host"];
  649. if(IsSet($url["port"]))
  650. $this->pop3->port=intval($url["port"]);
  651. if(IsSet($url["scheme"])
  652. && !strcmp($url["scheme"],"pop3s"))
  653. $this->pop3->tls=1;
  654. if(!IsSet($url["user"]))
  655. return($this->SetError("it was not specified a valid POP3 user"));
  656. if(!IsSet($url["pass"]))
  657. return($this->SetError("it was not specified a valid POP3 password"));
  658. if(!IsSet($url["path"])
  659. || strcmp(intval($path=substr($url["path"],1)),$path))
  660. return($this->SetError("it was not specified a valid message to retrieve"));
  661. $apop=0;
  662. if(IsSet($url["query"]))
  663. {
  664. parse_str($url["query"],$query);
  665. if(IsSet($query["debug"]))
  666. $this->pop3->debug = intval($query["debug"]);
  667. if(IsSet($query["html_debug"]))
  668. $this->pop3->html_debug = intval($query["html_debug"]);
  669. if(IsSet($query["tls"]))
  670. $this->pop3->tls = intval($query["tls"]);
  671. if(IsSet($query["apop"]))
  672. $apop = intval($query["apop"]);
  673. if(IsSet($query["realm"]))
  674. $this->pop3->realm = UrlDecode($query["realm"]);
  675. if(IsSet($query["workstation"]))
  676. $this->pop3->workstation = UrlDecode($query["workstation"]);
  677. if(IsSet($query["authentication_mechanism"]))
  678. $this->pop3->realm = UrlDecode($query["authentication_mechanism"]);
  679. }
  680. if(strlen($error=$this->pop3->Open()))
  681. return($this->SetError($error));
  682. if(strlen($error=$this->pop3->Login(UrlDecode($url["user"]), UrlDecode($url["pass"]),$apop))
  683. || strlen($error=$this->pop3->OpenMessage($this->message = intval($path),-1)))
  684. {
  685. $this->pop3->Close();
  686. return($this->SetError($error));
  687. }
  688. $this->end_of_message=FALSE;
  689. if($options & STREAM_USE_PATH)
  690. $opened_path=$path;
  691. $this->read = 0;
  692. $this->buffer = "";
  693. return(TRUE);
  694. }
  695. Function stream_eof()
  696. {
  697. if($this->read==0)
  698. return(FALSE);
  699. return($this->end_of_message);
  700. }
  701. Function stream_read($count)
  702. {
  703. if($count<=0)
  704. return($this->SetError("it was not specified a valid length of the message to read"));
  705. if($this->end_of_message)
  706. return("");
  707. if(strlen($error=$this->pop3->GetMessage($count, $read, $this->end_of_message)))
  708. return($this->SetError($error));
  709. $this->read += strlen($read);
  710. return($read);
  711. }
  712. };
  713. ?>