3 .---------------------------------------------------------------------------.
\r
4 | Software: PHPMailer - PHP email class |
\r
5 | Version: 2.0.0 rc2 |
\r
6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
\r
7 | Info: http://phpmailer.sourceforge.net |
\r
8 | Support: http://sourceforge.net/projects/phpmailer/ |
\r
9 | ------------------------------------------------------------------------- |
\r
10 | Author: Andy Prevost (project admininistrator) |
\r
11 | Author: Brent R. Matzelle (original founder) |
\r
12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
\r
13 | Copyright (c) 2001-2003, Brent R. Matzelle |
\r
14 | ------------------------------------------------------------------------- |
\r
15 | License: Distributed under the Lesser General Public License (LGPL) |
\r
16 | http://www.gnu.org/copyleft/lesser.html |
\r
17 | This program is distributed in the hope that it will be useful - WITHOUT |
\r
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
\r
19 | FITNESS FOR A PARTICULAR PURPOSE. |
\r
20 | ------------------------------------------------------------------------- |
\r
21 | We offer a number of paid services (www.codeworxtech.com): |
\r
22 | - Web Hosting on highly optimized fast and secure servers |
\r
23 | - Technology Consulting |
\r
24 | - Oursourcing (highly qualified programmers and graphic designers) |
\r
25 '---------------------------------------------------------------------------'
\r
28 * POP Before SMTP Authentication Class
\r
31 * Author: Richard Davey (rich@corephp.co.uk)
\r
32 * License: LGPL, see PHPMailer License
\r
34 * Specifically for PHPMailer to allow POP before SMTP authentication.
\r
35 * Does not yet work with APOP - if you have an APOP account, contact me
\r
36 * and we can test changes to this script.
\r
38 * This class is based on the structure of the SMTP class by Chris Ryan
\r
40 * This class is rfc 1939 compliant and implements all the commands
\r
41 * required for POP3 connection, authentication and disconnection.
\r
43 * @package PHPMailer
\r
44 * @author Richard Davey
\r
53 var $POP3_PORT = 110;
\r
59 var $POP3_TIMEOUT = 30;
\r
62 * POP3 Carriage Return + Line Feed
\r
68 * Displaying Debug warnings? (0 = now, 1+ = yes)
\r
86 * POP3 Timeout Value
\r
108 var $error; // Error log array
\r
112 * Constructor, sets the initial values
\r
118 $this->pop_conn = 0;
\r
119 $this->connected = false;
\r
120 $this->error = null;
\r
124 * Combination of public events - connect, login, disconnect
\r
126 * @param string $host
\r
127 * @param integer $port
\r
128 * @param integer $tval
\r
129 * @param string $username
\r
130 * @param string $password
\r
132 function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0)
\r
134 $this->host = $host;
\r
136 // If no port value is passed, retrieve it
\r
137 if ($port == false)
\r
139 $this->port = $this->POP3_PORT;
\r
143 $this->port = $port;
\r
146 // If no port value is passed, retrieve it
\r
147 if ($tval == false)
\r
149 $this->tval = $this->POP3_TIMEOUT;
\r
153 $this->tval = $tval;
\r
156 $this->do_debug = $debug_level;
\r
157 $this->username = $username;
\r
158 $this->password = $password;
\r
160 // Refresh the error log
\r
161 $this->error = null;
\r
164 $result = $this->Connect($this->host, $this->port, $this->tval);
\r
168 $login_result = $this->Login($this->username, $this->password);
\r
172 $this->Disconnect();
\r
179 // We need to disconnect regardless if the login succeeded
\r
180 $this->Disconnect();
\r
186 * Connect to the POP3 server
\r
188 * @param string $host
\r
189 * @param integer $port
\r
190 * @param integer $tval
\r
193 function Connect ($host, $port = false, $tval = 30)
\r
195 // Are we already connected?
\r
196 if ($this->connected)
\r
202 On Windows this will raise a PHP Warning error if the hostname doesn't exist.
\r
203 Rather than supress it with @fsockopen, let's capture it cleanly instead
\r
206 set_error_handler(array(&$this, 'catchWarning'));
\r
208 // Connect to the POP3 server
\r
209 $this->pop_conn = fsockopen($host, // POP3 Host
\r
211 $errno, // Error Number
\r
212 $errstr, // Error Message
\r
213 $tval); // Timeout (seconds)
\r
215 // Restore the error handler
\r
216 restore_error_handler();
\r
218 // Does the Error Log now contain anything?
\r
219 if ($this->error && $this->do_debug >= 1)
\r
221 $this->displayErrors();
\r
225 if ($this->pop_conn == false)
\r
227 // It would appear not...
\r
228 $this->error = array(
\r
229 'error' => "Failed to connect to server $host on port $port",
\r
231 'errstr' => $errstr
\r
234 if ($this->do_debug >= 1)
\r
236 $this->displayErrors();
\r
242 // Increase the stream time-out
\r
244 // Check for PHP 4.3.0 or later
\r
245 if (version_compare(phpversion(), '4.3.0', 'ge'))
\r
247 stream_set_timeout($this->pop_conn, $tval, 0);
\r
251 // Does not work on Windows
\r
252 if (substr(PHP_OS, 0, 3) !== 'WIN')
\r
254 socket_set_timeout($this->pop_conn, $tval, 0);
\r
258 // Get the POP3 server response
\r
259 $pop3_response = $this->getResponse();
\r
261 // Check for the +OK
\r
262 if ($this->checkResponse($pop3_response))
\r
264 // The connection is established and the POP3 server is talking
\r
265 $this->connected = true;
\r
272 * Login to the POP3 server (does not support APOP yet)
\r
274 * @param string $username
\r
275 * @param string $password
\r
278 function Login ($username = '', $password = '')
\r
280 if ($this->connected == false)
\r
282 $this->error = 'Not connected to POP3 server';
\r
284 if ($this->do_debug >= 1)
\r
286 $this->displayErrors();
\r
290 if (empty($username))
\r
292 $username = $this->username;
\r
295 if (empty($password))
\r
297 $password = $this->password;
\r
300 $pop_username = "USER $username" . $this->CRLF;
\r
301 $pop_password = "PASS $password" . $this->CRLF;
\r
303 // Send the Username
\r
304 $this->sendString($pop_username);
\r
305 $pop3_response = $this->getResponse();
\r
307 if ($this->checkResponse($pop3_response))
\r
309 // Send the Password
\r
310 $this->sendString($pop_password);
\r
311 $pop3_response = $this->getResponse();
\r
313 if ($this->checkResponse($pop3_response))
\r
329 * Disconnect from the POP3 server
\r
331 function Disconnect ()
\r
333 $this->sendString('QUIT');
\r
335 fclose($this->pop_conn);
\r
345 * Get the socket response back.
\r
346 * $size is the maximum number of bytes to retrieve
\r
348 * @param integer $size
\r
351 function getResponse ($size = 128)
\r
353 $pop3_response = fgets($this->pop_conn, $size);
\r
355 return $pop3_response;
\r
359 * Send a string down the open socket connection to the POP3 server
\r
361 * @param string $string
\r
364 function sendString ($string)
\r
366 $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
\r
368 return $bytes_sent;
\r
373 * Checks the POP3 server response for +OK or -ERR
\r
375 * @param string $string
\r
378 function checkResponse ($string)
\r
380 if (substr($string, 0, 3) !== '+OK')
\r
382 $this->error = array(
\r
383 'error' => "Server reported an error: $string",
\r
388 if ($this->do_debug >= 1)
\r
390 $this->displayErrors();
\r
403 * If debug is enabled, display the error message array
\r
406 function displayErrors ()
\r
410 foreach ($this->error as $single_error)
\r
412 print_r($single_error);
\r
419 * Takes over from PHP for the socket warning handler
\r
421 * @param integer $errno
\r
422 * @param string $errstr
\r
423 * @param string $errfile
\r
424 * @param integer $errline
\r
426 function catchWarning ($errno, $errstr, $errfile, $errline)
\r
428 $this->error[] = array(
\r
429 'error' => "Connecting to the POP3 server raised a PHP warning: ",
\r
431 'errstr' => $errstr
\r