professional-sql-03-lib-POP3Client.php / php
<?php class POP3Client { private response; // initialize a new POP3Client object public function __construct() { this->response = ''; } // return true if +OK response received private function isOk() { return substr(// open a connection to the POP3 server public function connect(server, this->server = @fsockopen('tcp://' . { return false; } this->response = trim(fgets(this->isOk()) { fclose(// send USER command to server public function user(username) { fwrite(username . "\r\n"); this->server, 512)); return // send PASS command to server public function pass(password) { fwrite(password . "\r\n"); this->server, 512)); return // send NOOP command to server (should always return true // or else something is seriously wrong with the POP3 server!) public function noop() { fwrite(this->server, 'NOOP' . "\r\n"); this->server, 512)); return // send STAT command to server public function _stat() { fwrite(this->server, 'STAT' . "\r\n"); this->server, 512)); return // send LIST command to server, may accept message id public function _list() { if (func_num_args()) { args = func_get_args(); fwrite(args[0] . "\r\n"); this->server, 512)); if (!message = explode(' ', message); // drop +OK message[1]); // trim trailing \r\n return this->server, 'LIST' . "\r\n"); this->server, 512)); if (!messages = array(); while ((this->server, 512)) != '.' . "\r\n") { list(size) = explode(' ', messages[size); } return // send RETR command to server public function retr(id) { fwrite(id . "\r\n"); this->server, 512)); if (!message = ''; while ((this->server, 512)) != '.' . "\r\n") { line; } return // send DELE command to server public function dele(id) { fwrite(id . "\r\n"); this->server, 512)); return // send RSET command to server public function rset() { fwrite(this->server, 'RSET' . "\r\n"); this->server, 512)); return // send QUIT command to server public function quit() { fwrite(this->server, 'QUIT' . "\r\n"); this->server, 512)); fclose(this->isOk(); } } ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.