|
|
楼主 |
发表于 2015-6-11 11:58:59
|
显示全部楼层
本帖最后由 demo 于 2015-6-12 04:13 编辑
Continue
- /* RetrieveMessage method - the $message argument indicates the number of
- a message to be listed. Pass a reference variables that will hold the
- arrays of the $header and $body lines. The $lines argument tells how
- many lines of the message are to be retrieved. Pass a negative number
- if you want to retrieve the whole message. */
-
- Function RetrieveMessage($message, $headers, $body, $lines)
- {
- if ($this->state != "TRANSACTION")
- return ("connection is not in TRANSACTION state");
- if ($lines < 0) {
- $command = "RETR";
- $arguments = "$message";
- } else {
- $command = "TOP";
- $arguments = "$message $lines";
- }
- if ($this->PutLine("$command $arguments") == 0)
- return ("Could not send the $command command");
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not get message retrieval command response");
- if (strtok($response, " ") != "+OK")
- return ("Could not retrieve the message: " . strtok("\r\n"));
- for ($headers = $body = array(), $line = 0;; $line++) {
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not retrieve the message");
- switch ($response) {
- case ".":
- return ("");
- case "":
- break 2;
- default:
- if (substr($response, 0, 1) == ".")
- $response = substr($response, 1, strlen($response) - 1);
- break;
- }
- $headers[$line] = $response;
- }
- for ($line = 0;; $line++) {
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not retrieve the message");
- switch ($response) {
- case ".":
- return ("");
- default:
- if (substr($response, 0, 1) == ".")
- $response = substr($response, 1, strlen($response) - 1);
- break;
- }
- $body[$line] = $response;
- }
- return ("");
- }
-
- /* DeleteMessage method - the $message argument indicates the number of
- a message to be marked as deleted. Messages will only be effectively
- deleted upon a successful call to the Close method. */
-
- Function DeleteMessage($message)
- {
- if ($this->state != "TRANSACTION")
- return ("connection is not in TRANSACTION state");
- if ($this->PutLine("DELE $message") == 0)
- return ("Could not send the DELE command");
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not get message delete command response");
- if (strtok($response, " ") != "+OK")
- return ("Could not delete the message: " . strtok("\r\n"));
- $this->must_update = 1;
- return ("");
- }
-
- /* ResetDeletedMessages method - Reset the list of marked to be deleted
- messages. No messages will be marked to be deleted upon a successful
- call to this method. */
-
- Function ResetDeletedMessages()
- {
- if ($this->state != "TRANSACTION")
- return ("connection is not in TRANSACTION state");
- if ($this->PutLine("RSET") == 0)
- return ("Could not send the RSET command");
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not get reset deleted messages command response");
- if (strtok($response, " ") != "+OK")
- return ("Could not reset deleted messages: " . strtok("\r\n"));
- $this->must_update = 0;
- return ("");
- }
-
- /* IssueNOOP method - Just pings the server to prevent it auto-close the
- connection after an idle timeout (tipically 10 minutes). Not very
- useful for most likely uses of this class. It's just here for
- protocol support completeness. */
-
- Function IssueNOOP()
- {
- if ($this->state != "TRANSACTION")
- return ("connection is not in TRANSACTION state");
- if ($this->PutLine("NOOP") == 0)
- return ("Could not send the NOOP command");
- $response = $this->GetLine();
- if (GetType($response) != "string")
- return ("Could not NOOP command response");
- if (strtok($response, " ") != "+OK")
- return ("Could not issue the NOOP command: " . strtok("\r\n"));
- return ("");
- }
- }
- ;
- /* ---- pop3.php3 class file ends here. ---- */
- ?>
复制代码
---- example file ----
- <HTML>
- <HEAD>
- <TITLE>POP3 PHP class test</TITLE>
- </HEAD>
- <BODY>
- <?
- include("pop3.php3");
- $user = "mlemos";
- $password = "password";
- $apop = 0;
- $pop3_connection = new pop3_class;
- $pop3_connection->hostname = "localhost";
- if (($error = $pop3_connection->Open()) == "") {
- echo "<PRE>Connected to the POP3 server $pop3_connection->hostname</PRE>\n";
- if (($error = $pop3_connection->Login($user, $password, $apop)) == "") {
- echo "<PRE>User $user logged in.</PRE>\n";
- if (($error = $pop3_connection->Statistics(&$messages, &$size)) == "") {
- echo "<PRE>There are $messages messages in the mail box with a total of $size bytes.</PRE>\n";
- $result = $pop3_connection->ListMessages("", 0);
- if (GetType($result) == "array") {
- for (Reset($result), $message = 0; $message < count($result); Next($result), $message++)
- echo "<PRE>Message ,Key($result), - , " . $result[Key($result)] . " , bytes.</PRE>\n";
- $result = $pop3_connection->ListMessages("", 1);
- if (GetType($result) == "array") {
- for (Reset($result), $message = 0; $message < count($result); Next($result), $message++)
- echo "<PRE>Message ,Key($result), Unique ID - "" . $result[Key($result)] . ""</PRE>\n";
- if ($messages > 0) {
- if (($error = $pop3_connection->RetrieveMessage(1, &$headers, &$body, 2)) == "") {
- echo "<PRE>Message 1:\n---Message headers starts below---</PRE>\n";
- for ($line = 0; $line < count($headers); $line++)
- echo "<PRE>", HtmlSpecialChars($headers[$line]), "</PRE>\n";
- echo "<PRE>---Message headers ends above---\n---Message body starts below---</PRE>\n";
- for ($line = 0; $line < count($body); $line++)
- echo "<PRE>", HtmlSpecialChars($body[$line]), "</PRE>\n";
- echo "<PRE>---Message body ends above---</PRE>\n";
- if (($error = $pop3_connection->DeleteMessage(1)) == "") {
- echo "<PRE>Marked message 1 for deletion.</PRE>\n";
- if (($error = $pop3_connection->ResetDeletedMessages()) == "") {
- echo "<PRE>Resetted the list of messages to be deleted.</PRE>\n";
- }
- }
- }
- }
- if ($error == "" && ($error = $pop3_connection->Close()) == "")
- echo "<PRE>Disconnected from the POP3 server $pop3_connection->hostname</PRE>\n";
-
- } else
- $error = $result;
- } else
- $error = $result;
- }
- }
- }
- if ($error != "")
- echo "<H2>Error: ", HtmlSpecialChars($error), "</H2>";
- ?>
- </BODY>
- </HTML>
复制代码
reference: http://www.weberdev.com/get_example.php3?ExampleID=461
|
|