| 1 | Index: wp-includes/class-pop3.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/class-pop3.php (revision 8571) |
|---|
| 4 | +++ wp-includes/class-pop3.php (working copy) |
|---|
| 5 | @@ -1,656 +1,436 @@ |
|---|
| 6 | <?php |
|---|
| 7 | +/*~ class.pop3.php |
|---|
| 8 | +.---------------------------------------------------------------------------. |
|---|
| 9 | +| Software: PHPMailer - PHP email class | |
|---|
| 10 | +| Version: 2.0.2 | |
|---|
| 11 | +| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | |
|---|
| 12 | +| Info: http://phpmailer.sourceforge.net | |
|---|
| 13 | +| Support: http://sourceforge.net/projects/phpmailer/ | |
|---|
| 14 | +| ------------------------------------------------------------------------- | |
|---|
| 15 | +| Author: Andy Prevost (project admininistrator) | |
|---|
| 16 | +| Author: Brent R. Matzelle (original founder) | |
|---|
| 17 | +| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | |
|---|
| 18 | +| Copyright (c) 2001-2003, Brent R. Matzelle | |
|---|
| 19 | +| ------------------------------------------------------------------------- | |
|---|
| 20 | +| License: Distributed under the Lesser General Public License (LGPL) | |
|---|
| 21 | +| http://www.gnu.org/copyleft/lesser.html | |
|---|
| 22 | +| This program is distributed in the hope that it will be useful - WITHOUT | |
|---|
| 23 | +| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
|---|
| 24 | +| FITNESS FOR A PARTICULAR PURPOSE. | |
|---|
| 25 | +| ------------------------------------------------------------------------- | |
|---|
| 26 | +| We offer a number of paid services (www.codeworxtech.com): | |
|---|
| 27 | +| - Web Hosting on highly optimized fast and secure servers | |
|---|
| 28 | +| - Technology Consulting | |
|---|
| 29 | +| - Oursourcing (highly qualified programmers and graphic designers) | |
|---|
| 30 | +'---------------------------------------------------------------------------' |
|---|
| 31 | + |
|---|
| 32 | /** |
|---|
| 33 | - * mail_fetch/setup.php |
|---|
| 34 | + * POP Before SMTP Authentication Class |
|---|
| 35 | * |
|---|
| 36 | - * @package SquirrelMail |
|---|
| 37 | + * Author: Richard Davey (rich@corephp.co.uk) |
|---|
| 38 | + * License: LGPL, see PHPMailer License |
|---|
| 39 | * |
|---|
| 40 | - * @copyright (c) 1999-2006 The SquirrelMail Project Team |
|---|
| 41 | + * Specifically for PHPMailer to allow POP before SMTP authentication. |
|---|
| 42 | + * Does not yet work with APOP - if you have an APOP account, contact me |
|---|
| 43 | + * and we can test changes to this script. |
|---|
| 44 | * |
|---|
| 45 | - * @copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved |
|---|
| 46 | - * Modified by Philippe Mingo 2001 mingo@rotedic.com |
|---|
| 47 | - * An RFC 1939 compliant wrapper class for the POP3 protocol. |
|---|
| 48 | + * This class is based on the structure of the SMTP class by Chris Ryan |
|---|
| 49 | * |
|---|
| 50 | - * Licensed under the GNU GPL. For full terms see the file COPYING. |
|---|
| 51 | + * This class is rfc 1939 compliant and implements all the commands |
|---|
| 52 | + * required for POP3 connection, authentication and disconnection. |
|---|
| 53 | * |
|---|
| 54 | - * pop3 class |
|---|
| 55 | - * |
|---|
| 56 | - * $Id$ |
|---|
| 57 | + * @package PHPMailer |
|---|
| 58 | + * @author Richard Davey |
|---|
| 59 | */ |
|---|
| 60 | |
|---|
| 61 | -/** |
|---|
| 62 | - * POP3 |
|---|
| 63 | - * |
|---|
| 64 | - * @package SquirrelMail |
|---|
| 65 | - */ |
|---|
| 66 | -class POP3 { |
|---|
| 67 | - var $ERROR = ''; // Error string. |
|---|
| 68 | +class POP3 |
|---|
| 69 | +{ |
|---|
| 70 | + /** |
|---|
| 71 | + * Default POP3 port |
|---|
| 72 | + * @var int |
|---|
| 73 | + */ |
|---|
| 74 | + var $POP3_PORT = 110; |
|---|
| 75 | |
|---|
| 76 | - var $TIMEOUT = 60; // Default timeout before giving up on a |
|---|
| 77 | - // network operation. |
|---|
| 78 | + /** |
|---|
| 79 | + * Default Timeout |
|---|
| 80 | + * @var int |
|---|
| 81 | + */ |
|---|
| 82 | + var $POP3_TIMEOUT = 30; |
|---|
| 83 | |
|---|
| 84 | - var $COUNT = -1; // Mailbox msg count |
|---|
| 85 | + /** |
|---|
| 86 | + * POP3 Carriage Return + Line Feed |
|---|
| 87 | + * @var string |
|---|
| 88 | + */ |
|---|
| 89 | + var $CRLF = "\r\n"; |
|---|
| 90 | |
|---|
| 91 | - var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|---|
| 92 | - // Per RFC 1939 the returned line a POP3 |
|---|
| 93 | - // server can send is 512 bytes. |
|---|
| 94 | + /** |
|---|
| 95 | + * Displaying Debug warnings? (0 = now, 1+ = yes) |
|---|
| 96 | + * @var int |
|---|
| 97 | + */ |
|---|
| 98 | + var $do_debug = 2; |
|---|
| 99 | |
|---|
| 100 | - var $FP = ''; // The connection to the server's |
|---|
| 101 | - // file descriptor |
|---|
| 102 | + /** |
|---|
| 103 | + * POP3 Mail Server |
|---|
| 104 | + * @var string |
|---|
| 105 | + */ |
|---|
| 106 | + var $host; |
|---|
| 107 | |
|---|
| 108 | - var $MAILSERVER = ''; // Set this to hard code the server name |
|---|
| 109 | + /** |
|---|
| 110 | + * POP3 Port |
|---|
| 111 | + * @var int |
|---|
| 112 | + */ |
|---|
| 113 | + var $port; |
|---|
| 114 | |
|---|
| 115 | - var $DEBUG = FALSE; // set to true to echo pop3 |
|---|
| 116 | - // commands and responses to error_log |
|---|
| 117 | - // this WILL log passwords! |
|---|
| 118 | + /** |
|---|
| 119 | + * POP3 Timeout Value |
|---|
| 120 | + * @var int |
|---|
| 121 | + */ |
|---|
| 122 | + var $tval; |
|---|
| 123 | |
|---|
| 124 | - var $BANNER = ''; // Holds the banner returned by the |
|---|
| 125 | - // pop server - used for apop() |
|---|
| 126 | + /** |
|---|
| 127 | + * POP3 Username |
|---|
| 128 | + * @var string |
|---|
| 129 | + */ |
|---|
| 130 | + var $username; |
|---|
| 131 | |
|---|
| 132 | - var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|---|
| 133 | - // This must be set to true |
|---|
| 134 | - // manually |
|---|
| 135 | + /** |
|---|
| 136 | + * POP3 Password |
|---|
| 137 | + * @var string |
|---|
| 138 | + */ |
|---|
| 139 | + var $password; |
|---|
| 140 | |
|---|
| 141 | - function POP3 ( $server = '', $timeout = '' ) { |
|---|
| 142 | - settype($this->BUFFER,"integer"); |
|---|
| 143 | - if( !empty($server) ) { |
|---|
| 144 | - // Do not allow programs to alter MAILSERVER |
|---|
| 145 | - // if it is already specified. They can get around |
|---|
| 146 | - // this if they -really- want to, so don't count on it. |
|---|
| 147 | - if(empty($this->MAILSERVER)) |
|---|
| 148 | - $this->MAILSERVER = $server; |
|---|
| 149 | - } |
|---|
| 150 | - if(!empty($timeout)) { |
|---|
| 151 | - settype($timeout,"integer"); |
|---|
| 152 | - $this->TIMEOUT = $timeout; |
|---|
| 153 | - if (!ini_get('safe_mode')) |
|---|
| 154 | - set_time_limit($timeout); |
|---|
| 155 | - } |
|---|
| 156 | - return true; |
|---|
| 157 | + /**#@+ |
|---|
| 158 | + * @access private |
|---|
| 159 | + */ |
|---|
| 160 | + var $pop_conn; |
|---|
| 161 | + var $connected; |
|---|
| 162 | + var $error; // Error log array |
|---|
| 163 | + /**#@-*/ |
|---|
| 164 | + |
|---|
| 165 | + /** |
|---|
| 166 | + * Constructor, sets the initial values |
|---|
| 167 | + * |
|---|
| 168 | + * @return POP3 |
|---|
| 169 | + */ |
|---|
| 170 | + function POP3 () |
|---|
| 171 | + { |
|---|
| 172 | + $this->pop_conn = 0; |
|---|
| 173 | + $this->connected = false; |
|---|
| 174 | + $this->error = null; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | - function update_timer () { |
|---|
| 178 | - if (!ini_get('safe_mode')) |
|---|
| 179 | - set_time_limit($this->TIMEOUT); |
|---|
| 180 | - return true; |
|---|
| 181 | + /** |
|---|
| 182 | + * Combination of public events - connect, login, disconnect |
|---|
| 183 | + * |
|---|
| 184 | + * @param string $host |
|---|
| 185 | + * @param integer $port |
|---|
| 186 | + * @param integer $tval |
|---|
| 187 | + * @param string $username |
|---|
| 188 | + * @param string $password |
|---|
| 189 | + */ |
|---|
| 190 | + function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) |
|---|
| 191 | + { |
|---|
| 192 | + $this->host = $host; |
|---|
| 193 | + |
|---|
| 194 | + // If no port value is passed, retrieve it |
|---|
| 195 | + if ($port == false) |
|---|
| 196 | + { |
|---|
| 197 | + $this->port = $this->POP3_PORT; |
|---|
| 198 | } |
|---|
| 199 | + else |
|---|
| 200 | + { |
|---|
| 201 | + $this->port = $port; |
|---|
| 202 | + } |
|---|
| 203 | |
|---|
| 204 | - function connect ($server, $port = 110) { |
|---|
| 205 | - // Opens a socket to the specified server. Unless overridden, |
|---|
| 206 | - // port defaults to 110. Returns true on success, false on fail |
|---|
| 207 | + // If no port value is passed, retrieve it |
|---|
| 208 | + if ($tval == false) |
|---|
| 209 | + { |
|---|
| 210 | + $this->tval = $this->POP3_TIMEOUT; |
|---|
| 211 | + } |
|---|
| 212 | + else |
|---|
| 213 | + { |
|---|
| 214 | + $this->tval = $tval; |
|---|
| 215 | + } |
|---|
| 216 | |
|---|
| 217 | - // If MAILSERVER is set, override $server with it's value |
|---|
| 218 | + $this->do_debug = $debug_level; |
|---|
| 219 | + $this->username = $username; |
|---|
| 220 | + $this->password = $password; |
|---|
| 221 | |
|---|
| 222 | - if (!isset($port) || !$port) {$port = 110;} |
|---|
| 223 | - if(!empty($this->MAILSERVER)) |
|---|
| 224 | - $server = $this->MAILSERVER; |
|---|
| 225 | + // Refresh the error log |
|---|
| 226 | + $this->error = null; |
|---|
| 227 | |
|---|
| 228 | - if(empty($server)){ |
|---|
| 229 | - $this->ERROR = "POP3 connect: " . _("No server specified"); |
|---|
| 230 | - unset($this->FP); |
|---|
| 231 | - return false; |
|---|
| 232 | - } |
|---|
| 233 | + // Connect |
|---|
| 234 | + $result = $this->Connect($this->host, $this->port, $this->tval); |
|---|
| 235 | |
|---|
| 236 | - $fp = @fsockopen("$server", $port, $errno, $errstr); |
|---|
| 237 | + if ($result) |
|---|
| 238 | + { |
|---|
| 239 | + $login_result = $this->Login($this->username, $this->password); |
|---|
| 240 | |
|---|
| 241 | - if(!$fp) { |
|---|
| 242 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|---|
| 243 | - unset($this->FP); |
|---|
| 244 | - return false; |
|---|
| 245 | - } |
|---|
| 246 | + if ($login_result) |
|---|
| 247 | + { |
|---|
| 248 | + $this->Disconnect(); |
|---|
| 249 | |
|---|
| 250 | - socket_set_blocking($fp,-1); |
|---|
| 251 | - $this->update_timer(); |
|---|
| 252 | - $reply = fgets($fp,$this->BUFFER); |
|---|
| 253 | - $reply = $this->strip_clf($reply); |
|---|
| 254 | - if($this->DEBUG) |
|---|
| 255 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|---|
| 256 | - if(!$this->is_ok($reply)) { |
|---|
| 257 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|---|
| 258 | - unset($this->FP); |
|---|
| 259 | - return false; |
|---|
| 260 | - } |
|---|
| 261 | - $this->FP = $fp; |
|---|
| 262 | - $this->BANNER = $this->parse_banner($reply); |
|---|
| 263 | return true; |
|---|
| 264 | - } |
|---|
| 265 | + } |
|---|
| 266 | |
|---|
| 267 | - function user ($user = "") { |
|---|
| 268 | - // Sends the USER command, returns true or false |
|---|
| 269 | - |
|---|
| 270 | - if( empty($user) ) { |
|---|
| 271 | - $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|---|
| 272 | - return false; |
|---|
| 273 | - } elseif(!isset($this->FP)) { |
|---|
| 274 | - $this->ERROR = "POP3 user: " . _("connection not established"); |
|---|
| 275 | - return false; |
|---|
| 276 | - } else { |
|---|
| 277 | - $reply = $this->send_cmd("USER $user"); |
|---|
| 278 | - if(!$this->is_ok($reply)) { |
|---|
| 279 | - $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|---|
| 280 | - return false; |
|---|
| 281 | - } else |
|---|
| 282 | - return true; |
|---|
| 283 | - } |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | - function pass ($pass = "") { |
|---|
| 287 | - // Sends the PASS command, returns # of msgs in mailbox, |
|---|
| 288 | - // returns false (undef) on Auth failure |
|---|
| 289 | + // We need to disconnect regardless if the login succeeded |
|---|
| 290 | + $this->Disconnect(); |
|---|
| 291 | |
|---|
| 292 | - if(empty($pass)) { |
|---|
| 293 | - $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|---|
| 294 | - return false; |
|---|
| 295 | - } elseif(!isset($this->FP)) { |
|---|
| 296 | - $this->ERROR = "POP3 pass: " . _("connection not established"); |
|---|
| 297 | - return false; |
|---|
| 298 | - } else { |
|---|
| 299 | - $reply = $this->send_cmd("PASS $pass"); |
|---|
| 300 | - if(!$this->is_ok($reply)) { |
|---|
| 301 | - $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|---|
| 302 | - $this->quit(); |
|---|
| 303 | - return false; |
|---|
| 304 | - } else { |
|---|
| 305 | - // Auth successful. |
|---|
| 306 | - $count = $this->last("count"); |
|---|
| 307 | - $this->COUNT = $count; |
|---|
| 308 | - return $count; |
|---|
| 309 | - } |
|---|
| 310 | - } |
|---|
| 311 | - } |
|---|
| 312 | + return false; |
|---|
| 313 | + } |
|---|
| 314 | |
|---|
| 315 | - function apop ($login,$pass) { |
|---|
| 316 | - // Attempts an APOP login. If this fails, it'll |
|---|
| 317 | - // try a standard login. YOUR SERVER MUST SUPPORT |
|---|
| 318 | - // THE USE OF THE APOP COMMAND! |
|---|
| 319 | - // (apop is optional per rfc1939) |
|---|
| 320 | - |
|---|
| 321 | - if(!isset($this->FP)) { |
|---|
| 322 | - $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|---|
| 323 | - return false; |
|---|
| 324 | - } elseif(!$this->ALLOWAPOP) { |
|---|
| 325 | - $retVal = $this->login($login,$pass); |
|---|
| 326 | - return $retVal; |
|---|
| 327 | - } elseif(empty($login)) { |
|---|
| 328 | - $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|---|
| 329 | - return false; |
|---|
| 330 | - } elseif(empty($pass)) { |
|---|
| 331 | - $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|---|
| 332 | - return false; |
|---|
| 333 | - } else { |
|---|
| 334 | - $banner = $this->BANNER; |
|---|
| 335 | - if( (!$banner) or (empty($banner)) ) { |
|---|
| 336 | - $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|---|
| 337 | - $retVal = $this->login($login,$pass); |
|---|
| 338 | - return $retVal; |
|---|
| 339 | - } else { |
|---|
| 340 | - $AuthString = $banner; |
|---|
| 341 | - $AuthString .= $pass; |
|---|
| 342 | - $APOPString = md5($AuthString); |
|---|
| 343 | - $cmd = "APOP $login $APOPString"; |
|---|
| 344 | - $reply = $this->send_cmd($cmd); |
|---|
| 345 | - if(!$this->is_ok($reply)) { |
|---|
| 346 | - $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|---|
| 347 | - $retVal = $this->login($login,$pass); |
|---|
| 348 | - return $retVal; |
|---|
| 349 | - } else { |
|---|
| 350 | - // Auth successful. |
|---|
| 351 | - $count = $this->last("count"); |
|---|
| 352 | - $this->COUNT = $count; |
|---|
| 353 | - return $count; |
|---|
| 354 | - } |
|---|
| 355 | - } |
|---|
| 356 | - } |
|---|
| 357 | + /** |
|---|
| 358 | + * Connect to the POP3 server |
|---|
| 359 | + * |
|---|
| 360 | + * @param string $host |
|---|
| 361 | + * @param integer $port |
|---|
| 362 | + * @param integer $tval |
|---|
| 363 | + * @return boolean |
|---|
| 364 | + */ |
|---|
| 365 | + function Connect ($host, $port = false, $tval = 30) |
|---|
| 366 | + { |
|---|
| 367 | + // Are we already connected? |
|---|
| 368 | + if ($this->connected) |
|---|
| 369 | + { |
|---|
| 370 | + return true; |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | - function login ($login = "", $pass = "") { |
|---|
| 374 | - // Sends both user and pass. Returns # of msgs in mailbox or |
|---|
| 375 | - // false on failure (or -1, if the error occurs while getting |
|---|
| 376 | - // the number of messages.) |
|---|
| 377 | + /* |
|---|
| 378 | + On Windows this will raise a PHP Warning error if the hostname doesn't exist. |
|---|
| 379 | + Rather than supress it with @fsockopen, let's capture it cleanly instead |
|---|
| 380 | + */ |
|---|
| 381 | |
|---|
| 382 | - if( !isset($this->FP) ) { |
|---|
| 383 | - $this->ERROR = "POP3 login: " . _("No connection to server"); |
|---|
| 384 | - return false; |
|---|
| 385 | - } else { |
|---|
| 386 | - $fp = $this->FP; |
|---|
| 387 | - if( !$this->user( $login ) ) { |
|---|
| 388 | - // Preserve the error generated by user() |
|---|
| 389 | - return false; |
|---|
| 390 | - } else { |
|---|
| 391 | - $count = $this->pass($pass); |
|---|
| 392 | - if( (!$count) || ($count == -1) ) { |
|---|
| 393 | - // Preserve the error generated by last() and pass() |
|---|
| 394 | - return false; |
|---|
| 395 | - } else |
|---|
| 396 | - return $count; |
|---|
| 397 | - } |
|---|
| 398 | - } |
|---|
| 399 | - } |
|---|
| 400 | + set_error_handler(array(&$this, 'catchWarning')); |
|---|
| 401 | |
|---|
| 402 | - function top ($msgNum, $numLines = "0") { |
|---|
| 403 | - // Gets the header and first $numLines of the msg body |
|---|
| 404 | - // returns data in an array with each returned line being |
|---|
| 405 | - // an array element. If $numLines is empty, returns |
|---|
| 406 | - // only the header information, and none of the body. |
|---|
| 407 | + // Connect to the POP3 server |
|---|
| 408 | + $this->pop_conn = fsockopen($host, // POP3 Host |
|---|
| 409 | + $port, // Port # |
|---|
| 410 | + $errno, // Error Number |
|---|
| 411 | + $errstr, // Error Message |
|---|
| 412 | + $tval); // Timeout (seconds) |
|---|
| 413 | |
|---|
| 414 | - if(!isset($this->FP)) { |
|---|
| 415 | - $this->ERROR = "POP3 top: " . _("No connection to server"); |
|---|
| 416 | - return false; |
|---|
| 417 | - } |
|---|
| 418 | - $this->update_timer(); |
|---|
| 419 | + // Restore the error handler |
|---|
| 420 | + restore_error_handler(); |
|---|
| 421 | |
|---|
| 422 | - $fp = $this->FP; |
|---|
| 423 | - $buffer = $this->BUFFER; |
|---|
| 424 | - $cmd = "TOP $msgNum $numLines"; |
|---|
| 425 | - fwrite($fp, "TOP $msgNum $numLines\r\n"); |
|---|
| 426 | - $reply = fgets($fp, $buffer); |
|---|
| 427 | - $reply = $this->strip_clf($reply); |
|---|
| 428 | - if($this->DEBUG) { |
|---|
| 429 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|---|
| 430 | - } |
|---|
| 431 | - if(!$this->is_ok($reply)) |
|---|
| 432 | - { |
|---|
| 433 | - $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|---|
| 434 | - return false; |
|---|
| 435 | - } |
|---|
| 436 | - |
|---|
| 437 | - $count = 0; |
|---|
| 438 | - $MsgArray = array(); |
|---|
| 439 | - |
|---|
| 440 | - $line = fgets($fp,$buffer); |
|---|
| 441 | - while ( !ereg("^\.\r\n",$line)) |
|---|
| 442 | - { |
|---|
| 443 | - $MsgArray[$count] = $line; |
|---|
| 444 | - $count++; |
|---|
| 445 | - $line = fgets($fp,$buffer); |
|---|
| 446 | - if(empty($line)) { break; } |
|---|
| 447 | - } |
|---|
| 448 | - |
|---|
| 449 | - return $MsgArray; |
|---|
| 450 | + // Does the Error Log now contain anything? |
|---|
| 451 | + if ($this->error && $this->do_debug >= 1) |
|---|
| 452 | + { |
|---|
| 453 | + $this->displayErrors(); |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | - function pop_list ($msgNum = "") { |
|---|
| 457 | - // If called with an argument, returns that msgs' size in octets |
|---|
| 458 | - // No argument returns an associative array of undeleted |
|---|
| 459 | - // msg numbers and their sizes in octets |
|---|
| 460 | + // Did we connect? |
|---|
| 461 | + if ($this->pop_conn == false) |
|---|
| 462 | + { |
|---|
| 463 | + // It would appear not... |
|---|
| 464 | + $this->error = array( |
|---|
| 465 | + 'error' => "Failed to connect to server $host on port $port", |
|---|
| 466 | + 'errno' => $errno, |
|---|
| 467 | + 'errstr' => $errstr |
|---|
| 468 | + ); |
|---|
| 469 | |
|---|
| 470 | - if(!isset($this->FP)) |
|---|
| 471 | + if ($this->do_debug >= 1) |
|---|
| 472 | { |
|---|
| 473 | - $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|---|
| 474 | - return false; |
|---|
| 475 | + $this->displayErrors(); |
|---|
| 476 | } |
|---|
| 477 | - $fp = $this->FP; |
|---|
| 478 | - $Total = $this->COUNT; |
|---|
| 479 | - if( (!$Total) or ($Total == -1) ) |
|---|
| 480 | - { |
|---|
| 481 | - return false; |
|---|
| 482 | - } |
|---|
| 483 | - if($Total == 0) |
|---|
| 484 | - { |
|---|
| 485 | - return array("0","0"); |
|---|
| 486 | - // return -1; // mailbox empty |
|---|
| 487 | - } |
|---|
| 488 | |
|---|
| 489 | - $this->update_timer(); |
|---|
| 490 | + return false; |
|---|
| 491 | + } |
|---|
| 492 | |
|---|
| 493 | - if(!empty($msgNum)) |
|---|
| 494 | - { |
|---|
| 495 | - $cmd = "LIST $msgNum"; |
|---|
| 496 | - fwrite($fp,"$cmd\r\n"); |
|---|
| 497 | - $reply = fgets($fp,$this->BUFFER); |
|---|
| 498 | - $reply = $this->strip_clf($reply); |
|---|
| 499 | - if($this->DEBUG) { |
|---|
| 500 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|---|
| 501 | - } |
|---|
| 502 | - if(!$this->is_ok($reply)) |
|---|
| 503 | - { |
|---|
| 504 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|---|
| 505 | - return false; |
|---|
| 506 | - } |
|---|
| 507 | - list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|---|
| 508 | - return $size; |
|---|
| 509 | - } |
|---|
| 510 | - $cmd = "LIST"; |
|---|
| 511 | - $reply = $this->send_cmd($cmd); |
|---|
| 512 | - if(!$this->is_ok($reply)) |
|---|
| 513 | - { |
|---|
| 514 | - $reply = $this->strip_clf($reply); |
|---|
| 515 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|---|
| 516 | - return false; |
|---|
| 517 | - } |
|---|
| 518 | - $MsgArray = array(); |
|---|
| 519 | - $MsgArray[0] = $Total; |
|---|
| 520 | - for($msgC=1;$msgC <= $Total; $msgC++) |
|---|
| 521 | - { |
|---|
| 522 | - if($msgC > $Total) { break; } |
|---|
| 523 | - $line = fgets($fp,$this->BUFFER); |
|---|
| 524 | - $line = $this->strip_clf($line); |
|---|
| 525 | - if(ereg("^\.",$line)) |
|---|
| 526 | - { |
|---|
| 527 | - $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|---|
| 528 | - return false; |
|---|
| 529 | - } |
|---|
| 530 | - list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|---|
| 531 | - settype($thisMsg,"integer"); |
|---|
| 532 | - if($thisMsg != $msgC) |
|---|
| 533 | - { |
|---|
| 534 | - $MsgArray[$msgC] = "deleted"; |
|---|
| 535 | - } |
|---|
| 536 | - else |
|---|
| 537 | - { |
|---|
| 538 | - $MsgArray[$msgC] = $msgSize; |
|---|
| 539 | - } |
|---|
| 540 | - } |
|---|
| 541 | - return $MsgArray; |
|---|
| 542 | - } |
|---|
| 543 | + // Increase the stream time-out |
|---|
| 544 | |
|---|
| 545 | - function get ($msgNum) { |
|---|
| 546 | - // Retrieve the specified msg number. Returns an array |
|---|
| 547 | - // where each line of the msg is an array element. |
|---|
| 548 | - |
|---|
| 549 | - if(!isset($this->FP)) |
|---|
| 550 | + // Check for PHP 4.3.0 or later |
|---|
| 551 | + if (version_compare(phpversion(), '4.3.0', 'ge')) |
|---|
| 552 | + { |
|---|
| 553 | + stream_set_timeout($this->pop_conn, $tval, 0); |
|---|
| 554 | + } |
|---|
| 555 | + else |
|---|
| 556 | + { |
|---|
| 557 | + // Does not work on Windows |
|---|
| 558 | + if (substr(PHP_OS, 0, 3) !== 'WIN') |
|---|
| 559 | { |
|---|
| 560 | - $this->ERROR = "POP3 get: " . _("No connection to server"); |
|---|
| 561 | - return false; |
|---|
| 562 | + socket_set_timeout($this->pop_conn, $tval, 0); |
|---|
| 563 | } |
|---|
| 564 | + } |
|---|
| 565 | |
|---|
| 566 | - $this->update_timer(); |
|---|
| 567 | + // Get the POP3 server response |
|---|
| 568 | + $pop3_response = $this->getResponse(); |
|---|
| 569 | |
|---|
| 570 | - $fp = $this->FP; |
|---|
| 571 | - $buffer = $this->BUFFER; |
|---|
| 572 | - $cmd = "RETR $msgNum"; |
|---|
| 573 | - $reply = $this->send_cmd($cmd); |
|---|
| 574 | + // Check for the +OK |
|---|
| 575 | + if ($this->checkResponse($pop3_response)) |
|---|
| 576 | + { |
|---|
| 577 | + // The connection is established and the POP3 server is talking |
|---|
| 578 | + $this->connected = true; |
|---|
| 579 | + return true; |
|---|
| 580 | + } |
|---|
| 581 | |
|---|
| 582 | - if(!$this->is_ok($reply)) |
|---|
| 583 | - { |
|---|
| 584 | - $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|---|
| 585 | - return false; |
|---|
| 586 | - } |
|---|
| 587 | + } |
|---|
| 588 | |
|---|
| 589 | - $count = 0; |
|---|
| 590 | - $MsgArray = array(); |
|---|
| 591 | + /** |
|---|
| 592 | + * Login to the POP3 server (does not support APOP yet) |
|---|
| 593 | + * |
|---|
| 594 | + * @param string $username |
|---|
| 595 | + * @param string $password |
|---|
| 596 | + * @return boolean |
|---|
| 597 | + */ |
|---|
| 598 | + function Login ($username = '', $password = '') |
|---|
| 599 | + { |
|---|
| 600 | + if ($this->connected == false) |
|---|
| 601 | + { |
|---|
| 602 | + $this->error = 'Not connected to POP3 server'; |
|---|
| 603 | |
|---|
| 604 | - $line = fgets($fp,$buffer); |
|---|
| 605 | - while ( !ereg("^\.\r\n",$line)) |
|---|
| 606 | + if ($this->do_debug >= 1) |
|---|
| 607 | { |
|---|
| 608 | - if ( $line{0} == '.' ) { $line = substr($line,1); } |
|---|
| 609 | - $MsgArray[$count] = $line; |
|---|
| 610 | - $count++; |
|---|
| 611 | - $line = fgets($fp,$buffer); |
|---|
| 612 | - if(empty($line)) { break; } |
|---|
| 613 | + $this->displayErrors(); |
|---|
| 614 | } |
|---|
| 615 | - return $MsgArray; |
|---|
| 616 | - } |
|---|
| 617 | + } |
|---|
| 618 | |
|---|
| 619 | - function last ( $type = "count" ) { |
|---|
| 620 | - // Returns the highest msg number in the mailbox. |
|---|
| 621 | - // returns -1 on error, 0+ on success, if type != count |
|---|
| 622 | - // results in a popstat() call (2 element array returned) |
|---|
| 623 | + if (empty($username)) |
|---|
| 624 | + { |
|---|
| 625 | + $username = $this->username; |
|---|
| 626 | + } |
|---|
| 627 | |
|---|
| 628 | - $last = -1; |
|---|
| 629 | - if(!isset($this->FP)) |
|---|
| 630 | - { |
|---|
| 631 | - $this->ERROR = "POP3 last: " . _("No connection to server"); |
|---|
| 632 | - return $last; |
|---|
| 633 | - } |
|---|
| 634 | + if (empty($password)) |
|---|
| 635 | + { |
|---|
| 636 | + $password = $this->password; |
|---|
| 637 | + } |
|---|
| 638 | |
|---|
| 639 | - $reply = $this->send_cmd("STAT"); |
|---|
| 640 | - if(!$this->is_ok($reply)) |
|---|
| 641 | - { |
|---|
| 642 | - $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|---|
| 643 | - return $last; |
|---|
| 644 | - } |
|---|
| 645 | + $pop_username = "USER $username" . $this->CRLF; |
|---|
| 646 | + $pop_password = "PASS $password" . $this->CRLF; |
|---|
| 647 | |
|---|
| 648 | - $Vars = preg_split('/\s+/',$reply); |
|---|
| 649 | - $count = $Vars[1]; |
|---|
| 650 | - $size = $Vars[2]; |
|---|
| 651 | - settype($count,"integer"); |
|---|
| 652 | - settype($size,"integer"); |
|---|
| 653 | - if($type != "count") |
|---|
| 654 | - { |
|---|
| 655 | - return array($count,$size); |
|---|
| 656 | - } |
|---|
| 657 | - return $count; |
|---|
| 658 | - } |
|---|
| 659 | + // Send the Username |
|---|
| 660 | + $this->sendString($pop_username); |
|---|
| 661 | + $pop3_response = $this->getResponse(); |
|---|
| 662 | |
|---|
| 663 | - function reset () { |
|---|
| 664 | - // Resets the status of the remote server. This includes |
|---|
| 665 | - // resetting the status of ALL msgs to not be deleted. |
|---|
| 666 | - // This method automatically closes the connection to the server. |
|---|
| 667 | + if ($this->checkResponse($pop3_response)) |
|---|
| 668 | + { |
|---|
| 669 | + // Send the Password |
|---|
| 670 | + $this->sendString($pop_password); |
|---|
| 671 | + $pop3_response = $this->getResponse(); |
|---|
| 672 | |
|---|
| 673 | - if(!isset($this->FP)) |
|---|
| 674 | + if ($this->checkResponse($pop3_response)) |
|---|
| 675 | { |
|---|
| 676 | - $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|---|
| 677 | - return false; |
|---|
| 678 | + return true; |
|---|
| 679 | } |
|---|
| 680 | - $reply = $this->send_cmd("RSET"); |
|---|
| 681 | - if(!$this->is_ok($reply)) |
|---|
| 682 | + else |
|---|
| 683 | { |
|---|
| 684 | - // The POP3 RSET command -never- gives a -ERR |
|---|
| 685 | - // response - if it ever does, something truely |
|---|
| 686 | - // wild is going on. |
|---|
| 687 | - |
|---|
| 688 | - $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|---|
| 689 | - @error_log("POP3 reset: ERROR [$reply]",0); |
|---|
| 690 | + return false; |
|---|
| 691 | } |
|---|
| 692 | - $this->quit(); |
|---|
| 693 | - return true; |
|---|
| 694 | + } |
|---|
| 695 | + else |
|---|
| 696 | + { |
|---|
| 697 | + return false; |
|---|
| 698 | + } |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | - function send_cmd ( $cmd = "" ) |
|---|
| 702 | + /** |
|---|
| 703 | + * Disconnect from the POP3 server |
|---|
| 704 | + */ |
|---|
| 705 | + function Disconnect () |
|---|
| 706 | { |
|---|
| 707 | - // Sends a user defined command string to the |
|---|
| 708 | - // POP server and returns the results. Useful for |
|---|
| 709 | - // non-compliant or custom POP servers. |
|---|
| 710 | - // Do NOT includ the \r\n as part of your command |
|---|
| 711 | - // string - it will be appended automatically. |
|---|
| 712 | + $this->sendString('QUIT'); |
|---|
| 713 | |
|---|
| 714 | - // The return value is a standard fgets() call, which |
|---|
| 715 | - // will read up to $this->BUFFER bytes of data, until it |
|---|
| 716 | - // encounters a new line, or EOF, whichever happens first. |
|---|
| 717 | - |
|---|
| 718 | - // This method works best if $cmd responds with only |
|---|
| 719 | - // one line of data. |
|---|
| 720 | - |
|---|
| 721 | - if(!isset($this->FP)) |
|---|
| 722 | - { |
|---|
| 723 | - $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|---|
| 724 | - return false; |
|---|
| 725 | - } |
|---|
| 726 | - |
|---|
| 727 | - if(empty($cmd)) |
|---|
| 728 | - { |
|---|
| 729 | - $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|---|
| 730 | - return ""; |
|---|
| 731 | - } |
|---|
| 732 | - |
|---|
| 733 | - $fp = $this->FP; |
|---|
| 734 | - $buffer = $this->BUFFER; |
|---|
| 735 | - $this->update_timer(); |
|---|
| 736 | - fwrite($fp,"$cmd\r\n"); |
|---|
| 737 | - $reply = fgets($fp,$buffer); |
|---|
| 738 | - $reply = $this->strip_clf($reply); |
|---|
| 739 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|---|
| 740 | - return $reply; |
|---|
| 741 | + fclose($this->pop_conn); |
|---|
| 742 | } |
|---|
| 743 | |
|---|
| 744 | - function quit() { |
|---|
| 745 | - // Closes the connection to the POP3 server, deleting |
|---|
| 746 | - // any msgs marked as deleted. |
|---|
| 747 | + /* |
|---|
| 748 | + --------------- |
|---|
| 749 | + Private Methods |
|---|
| 750 | + --------------- |
|---|
| 751 | + */ |
|---|
| 752 | |
|---|
| 753 | - if(!isset($this->FP)) |
|---|
| 754 | - { |
|---|
| 755 | - $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|---|
| 756 | - return false; |
|---|
| 757 | - } |
|---|
| 758 | - $fp = $this->FP; |
|---|
| 759 | - $cmd = "QUIT"; |
|---|
| 760 | - fwrite($fp,"$cmd\r\n"); |
|---|
| 761 | - $reply = fgets($fp,$this->BUFFER); |
|---|
| 762 | - $reply = $this->strip_clf($reply); |
|---|
| 763 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|---|
| 764 | - fclose($fp); |
|---|
| 765 | - unset($this->FP); |
|---|
| 766 | - return true; |
|---|
| 767 | - } |
|---|
| 768 | + /** |
|---|
| 769 | + * Get the socket response back. |
|---|
| 770 | + * $size is the maximum number of bytes to retrieve |
|---|
| 771 | + * |
|---|
| 772 | + * @param integer $size |
|---|
| 773 | + * @return string |
|---|
| 774 | + */ |
|---|
| 775 | + function getResponse ($size = 128) |
|---|
| 776 | + { |
|---|
| 777 | + $pop3_response = fgets($this->pop_conn, $size); |
|---|
| 778 | |
|---|
| 779 | - function popstat () { |
|---|
| 780 | - // Returns an array of 2 elements. The number of undeleted |
|---|
| 781 | - // msgs in the mailbox, and the size of the mbox in octets. |
|---|
| 782 | - |
|---|
| 783 | - $PopArray = $this->last("array"); |
|---|
| 784 | - |
|---|
| 785 | - if($PopArray == -1) { return false; } |
|---|
| 786 | - |
|---|
| 787 | - if( (!$PopArray) or (empty($PopArray)) ) |
|---|
| 788 | - { |
|---|
| 789 | - return false; |
|---|
| 790 | - } |
|---|
| 791 | - return $PopArray; |
|---|
| 792 | + return $pop3_response; |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | - function uidl ($msgNum = "") |
|---|
| 796 | + /** |
|---|
| 797 | + * Send a string down the open socket connection to the POP3 server |
|---|
| 798 | + * |
|---|
| 799 | + * @param string $string |
|---|
| 800 | + * @return integer |
|---|
| 801 | + */ |
|---|
| 802 | + function sendString ($string) |
|---|
| 803 | { |
|---|
| 804 | - // Returns the UIDL of the msg specified. If called with |
|---|
| 805 | - // no arguments, returns an associative array where each |
|---|
| 806 | - // undeleted msg num is a key, and the msg's uidl is the element |
|---|
| 807 | - // Array element 0 will contain the total number of msgs |
|---|
| 808 | + $bytes_sent = fwrite($this->pop_conn, $string, strlen($string)); |
|---|
| 809 | |
|---|
| 810 | - if(!isset($this->FP)) { |
|---|
| 811 | - $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|---|
| 812 | - return false; |
|---|
| 813 | - } |
|---|
| 814 | + return $bytes_sent; |
|---|
| 815 | |
|---|
| 816 | - $fp = $this->FP; |
|---|
| 817 | - $buffer = $this->BUFFER; |
|---|
| 818 | - |
|---|
| 819 | - if(!empty($msgNum)) { |
|---|
| 820 | - $cmd = "UIDL $msgNum"; |
|---|
| 821 | - $reply = $this->send_cmd($cmd); |
|---|
| 822 | - if(!$this->is_ok($reply)) |
|---|
| 823 | - { |
|---|
| 824 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|---|
| 825 | - return false; |
|---|
| 826 | - } |
|---|
| 827 | - list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|---|
| 828 | - return $myUidl; |
|---|
| 829 | - } else { |
|---|
| 830 | - $this->update_timer(); |
|---|
| 831 | - |
|---|
| 832 | - $UIDLArray = array(); |
|---|
| 833 | - $Total = $this->COUNT; |
|---|
| 834 | - $UIDLArray[0] = $Total; |
|---|
| 835 | - |
|---|
| 836 | - if ($Total < 1) |
|---|
| 837 | - { |
|---|
| 838 | - return $UIDLArray; |
|---|
| 839 | - } |
|---|
| 840 | - $cmd = "UIDL"; |
|---|
| 841 | - fwrite($fp, "UIDL\r\n"); |
|---|
| 842 | - $reply = fgets($fp, $buffer); |
|---|
| 843 | - $reply = $this->strip_clf($reply); |
|---|
| 844 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|---|
| 845 | - if(!$this->is_ok($reply)) |
|---|
| 846 | - { |
|---|
| 847 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|---|
| 848 | - return false; |
|---|
| 849 | - } |
|---|
| 850 | - |
|---|
| 851 | - $line = ""; |
|---|
| 852 | - $count = 1; |
|---|
| 853 | - $line = fgets($fp,$buffer); |
|---|
| 854 | - while ( !ereg("^\.\r\n",$line)) { |
|---|
| 855 | - if(ereg("^\.\r\n",$line)) { |
|---|
| 856 | - break; |
|---|
| 857 | - } |
|---|
| 858 | - list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|---|
| 859 | - $msgUidl = $this->strip_clf($msgUidl); |
|---|
| 860 | - if($count == $msg) { |
|---|
| 861 | - $UIDLArray[$msg] = $msgUidl; |
|---|
| 862 | - } |
|---|
| 863 | - else |
|---|
| 864 | - { |
|---|
| 865 | - $UIDLArray[$count] = 'deleted'; |
|---|
| 866 | - } |
|---|
| 867 | - $count++; |
|---|
| 868 | - $line = fgets($fp,$buffer); |
|---|
| 869 | - } |
|---|
| 870 | - } |
|---|
| 871 | - return $UIDLArray; |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | - function delete ($msgNum = "") { |
|---|
| 875 | - // Flags a specified msg as deleted. The msg will not |
|---|
| 876 | - // be deleted until a quit() method is called. |
|---|
| 877 | + /** |
|---|
| 878 | + * Checks the POP3 server response for +OK or -ERR |
|---|
| 879 | + * |
|---|
| 880 | + * @param string $string |
|---|
| 881 | + * @return boolean |
|---|
| 882 | + */ |
|---|
| 883 | + function checkResponse ($string) |
|---|
| 884 | + { |
|---|
| 885 | + if (substr($string, 0, 3) !== '+OK') |
|---|
| 886 | + { |
|---|
| 887 | + $this->error = array( |
|---|
| 888 | + 'error' => "Server reported an error: $string", |
|---|
| 889 | + 'errno' => 0, |
|---|
| 890 | + 'errstr' => '' |
|---|
| 891 | + ); |
|---|
| 892 | |
|---|
| 893 | - if(!isset($this->FP)) |
|---|
| 894 | + if ($this->do_debug >= 1) |
|---|
| 895 | { |
|---|
| 896 | - $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|---|
| 897 | - return false; |
|---|
| 898 | + $this->displayErrors(); |
|---|
| 899 | } |
|---|
| 900 | - if(empty($msgNum)) |
|---|
| 901 | - { |
|---|
| 902 | - $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|---|
| 903 | - return false; |
|---|
| 904 | - } |
|---|
| 905 | - $reply = $this->send_cmd("DELE $msgNum"); |
|---|
| 906 | - if(!$this->is_ok($reply)) |
|---|
| 907 | - { |
|---|
| 908 | - $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|---|
| 909 | - return false; |
|---|
| 910 | - } |
|---|
| 911 | + |
|---|
| 912 | + return false; |
|---|
| 913 | + } |
|---|
| 914 | + else |
|---|
| 915 | + { |
|---|
| 916 | return true; |
|---|
| 917 | - } |
|---|
| 918 | + } |
|---|
| 919 | |
|---|
| 920 | - // ********************************************************* |
|---|
| 921 | - |
|---|
| 922 | - // The following methods are internal to the class. |
|---|
| 923 | - |
|---|
| 924 | - function is_ok ($cmd = "") { |
|---|
| 925 | - // Return true or false on +OK or -ERR |
|---|
| 926 | - |
|---|
| 927 | - if( empty($cmd) ) |
|---|
| 928 | - return false; |
|---|
| 929 | - else |
|---|
| 930 | - return( ereg ("^\+OK", $cmd ) ); |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | - function strip_clf ($text = "") { |
|---|
| 934 | - // Strips \r\n from server responses |
|---|
| 935 | + /** |
|---|
| 936 | + * If debug is enabled, display the error message array |
|---|
| 937 | + * |
|---|
| 938 | + */ |
|---|
| 939 | + function displayErrors () |
|---|
| 940 | + { |
|---|
| 941 | + echo '<pre>'; |
|---|
| 942 | |
|---|
| 943 | - if(empty($text)) |
|---|
| 944 | - return $text; |
|---|
| 945 | - else { |
|---|
| 946 | - $stripped = str_replace("\r",'',$text); |
|---|
| 947 | - $stripped = str_replace("\n",'',$stripped); |
|---|
| 948 | - return $stripped; |
|---|
| 949 | - } |
|---|
| 950 | + foreach ($this->error as $single_error) |
|---|
| 951 | + { |
|---|
| 952 | + print_r($single_error); |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | - function parse_banner ( $server_text ) { |
|---|
| 956 | - $outside = true; |
|---|
| 957 | - $banner = ""; |
|---|
| 958 | - $length = strlen($server_text); |
|---|
| 959 | - for($count =0; $count < $length; $count++) |
|---|
| 960 | - { |
|---|
| 961 | - $digit = substr($server_text,$count,1); |
|---|
| 962 | - if(!empty($digit)) { |
|---|
| 963 | - if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|---|
| 964 | - { |
|---|
| 965 | - $banner .= $digit; |
|---|
| 966 | - } |
|---|
| 967 | - if ($digit == '<') |
|---|
| 968 | - { |
|---|
| 969 | - $outside = false; |
|---|
| 970 | - } |
|---|
| 971 | - if($digit == '>') |
|---|
| 972 | - { |
|---|
| 973 | - $outside = true; |
|---|
| 974 | - } |
|---|
| 975 | - } |
|---|
| 976 | - } |
|---|
| 977 | - $banner = $this->strip_clf($banner); // Just in case |
|---|
| 978 | - return "<$banner>"; |
|---|
| 979 | + echo '</pre>'; |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | -} // End class |
|---|
| 983 | + /** |
|---|
| 984 | + * Takes over from PHP for the socket warning handler |
|---|
| 985 | + * |
|---|
| 986 | + * @param integer $errno |
|---|
| 987 | + * @param string $errstr |
|---|
| 988 | + * @param string $errfile |
|---|
| 989 | + * @param integer $errline |
|---|
| 990 | + */ |
|---|
| 991 | + function catchWarning ($errno, $errstr, $errfile, $errline) |
|---|
| 992 | + { |
|---|
| 993 | + $this->error[] = array( |
|---|
| 994 | + 'error' => "Connecting to the POP3 server raised a PHP warning: ", |
|---|
| 995 | + 'errno' => $errno, |
|---|
| 996 | + 'errstr' => $errstr |
|---|
| 997 | + ); |
|---|
| 998 | + } |
|---|
| 999 | + |
|---|
| 1000 | + // End of class |
|---|
| 1001 | +} |
|---|
| 1002 | ?> |
|---|
| 1003 | Index: wp-includes/class-phpmailer.php |
|---|
| 1004 | =================================================================== |
|---|
| 1005 | --- wp-includes/class-phpmailer.php (revision 8571) |
|---|
| 1006 | +++ wp-includes/class-phpmailer.php (working copy) |
|---|
| 1007 | @@ -1,1497 +1,1896 @@ |
|---|
| 1008 | <?php |
|---|
| 1009 | -/** |
|---|
| 1010 | - * PHPMailer - PHP email class |
|---|
| 1011 | - * |
|---|
| 1012 | - * Class for sending email using either sendmail, PHP mail(), or SMTP. Methods |
|---|
| 1013 | - * are based upon the standard AspEmail(tm) classes. |
|---|
| 1014 | - * |
|---|
| 1015 | - * @copyright 2001 - 2003 Brent R. Matzelle |
|---|
| 1016 | - * @license LGPL |
|---|
| 1017 | - * @package PHPMailer |
|---|
| 1018 | - */ |
|---|
| 1019 | +/*~ class.phpmailer.php |
|---|
| 1020 | +.---------------------------------------------------------------------------. |
|---|
| 1021 | +| Software: PHPMailer - PHP email class | |
|---|
| 1022 | +| Version: 2.0.2 | |
|---|
| 1023 | +| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | |
|---|
| 1024 | +| Info: http://phpmailer.sourceforge.net | |
|---|
| 1025 | +| Support: http://sourceforge.net/projects/phpmailer/ | |
|---|
| 1026 | +| ------------------------------------------------------------------------- | |
|---|
| 1027 | +| Author: Andy Prevost (project admininistrator) | |
|---|
| 1028 | +| Author: Brent R. Matzelle (original founder) | |
|---|
| 1029 | +| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | |
|---|
| 1030 | +| Copyright (c) 2001-2003, Brent R. Matzelle | |
|---|
| 1031 | +| ------------------------------------------------------------------------- | |
|---|
| 1032 | +| License: Distributed under the Lesser General Public License (LGPL) | |
|---|
| 1033 | +| http://www.gnu.org/copyleft/lesser.html | |
|---|
| 1034 | +| This program is distributed in the hope that it will be useful - WITHOUT | |
|---|
| 1035 | +| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
|---|
| 1036 | +| FITNESS FOR A PARTICULAR PURPOSE. | |
|---|
| 1037 | +| ------------------------------------------------------------------------- | |
|---|
| 1038 | +| We offer a number of paid services (www.codeworxtech.com): | |
|---|
| 1039 | +| - Web Hosting on highly optimized fast and secure servers | |
|---|
| 1040 | +| - Technology Consulting | |
|---|
| 1041 | +| - Oursourcing (highly qualified programmers and graphic designers) | |
|---|
| 1042 | +'---------------------------------------------------------------------------' |
|---|
| 1043 | |
|---|
| 1044 | /** |
|---|
| 1045 | * PHPMailer - PHP email transport class |
|---|
| 1046 | * @package PHPMailer |
|---|
| 1047 | - * @author Brent R. Matzelle |
|---|
| 1048 | - * @copyright 2001 - 2003 Brent R. Matzelle |
|---|
| 1049 | + * @author Andy Prevost |
|---|
| 1050 | + * @copyright 2004 - 2008 Andy Prevost |
|---|
| 1051 | */ |
|---|
| 1052 | -class PHPMailer |
|---|
| 1053 | -{ |
|---|
| 1054 | - ///////////////////////////////////////////////// |
|---|
| 1055 | - // PUBLIC VARIABLES |
|---|
| 1056 | - ///////////////////////////////////////////////// |
|---|
| 1057 | |
|---|
| 1058 | - /** |
|---|
| 1059 | - * Email priority (1 = High, 3 = Normal, 5 = low). |
|---|
| 1060 | - * @var int |
|---|
| 1061 | - */ |
|---|
| 1062 | - var $Priority = 3; |
|---|
| 1063 | +class PHPMailer { |
|---|
| 1064 | |
|---|
| 1065 | - /** |
|---|
| 1066 | - * Sets the CharSet of the message. |
|---|
| 1067 | - * @var string |
|---|
| 1068 | - */ |
|---|
| 1069 | - var $CharSet = "UTF-8"; |
|---|
| 1070 | + ///////////////////////////////////////////////// |
|---|
| 1071 | + // PROPERTIES, PUBLIC |
|---|
| 1072 | + ///////////////////////////////////////////////// |
|---|
| 1073 | |
|---|
| 1074 | - /** |
|---|
| 1075 | - * Sets the Content-type of the message. |
|---|
| 1076 | - * @var string |
|---|
| 1077 | - */ |
|---|
| 1078 | - var $ContentType = "text/plain"; |
|---|
| 1079 | + /** |
|---|
| 1080 | + * Email priority (1 = High, 3 = Normal, 5 = low). |
|---|
| 1081 | + * @var int |
|---|
| 1082 | + */ |
|---|
| 1083 | + var $Priority = 3; |
|---|
| 1084 | |
|---|
| 1085 | - /** |
|---|
| 1086 | - * Sets the Encoding of the message. Options for this are "8bit", |
|---|
| 1087 | - * "7bit", "binary", "base64", and "quoted-printable". |
|---|
| 1088 | - * @var string |
|---|
| 1089 | - */ |
|---|
| 1090 | - var $Encoding = "8bit"; |
|---|
| 1091 | + /** |
|---|
| 1092 | + * Sets the CharSet of the message. |
|---|
| 1093 | + * @var string |
|---|
| 1094 | + */ |
|---|
| 1095 | + var $CharSet = 'iso-8859-1'; |
|---|
| 1096 | |
|---|
| 1097 | - /** |
|---|
| 1098 | - * Holds the most recent mailer error message. |
|---|
| 1099 | - * @var string |
|---|
| 1100 | - */ |
|---|
| 1101 | - var $ErrorInfo = ""; |
|---|
| 1102 | + /** |
|---|
| 1103 | + * Sets the Content-type of the message. |
|---|
| 1104 | + * @var string |
|---|
| 1105 | + */ |
|---|
| 1106 | + var $ContentType = 'text/plain'; |
|---|
| 1107 | |
|---|
| 1108 | - /** |
|---|
| 1109 | - * Sets the From email address for the message. |
|---|
| 1110 | - * @var string |
|---|
| 1111 | - */ |
|---|
| 1112 | - var $From = "localhost.localdomain"; |
|---|
| 1113 | + /** |
|---|
| 1114 | + * Sets the Encoding of the message. Options for this are "8bit", |
|---|
| 1115 | + * "7bit", "binary", "base64", and "quoted-printable". |
|---|
| 1116 | + * @var string |
|---|
| 1117 | + */ |
|---|
| 1118 | + var $Encoding = '8bit'; |
|---|
| 1119 | |
|---|
| 1120 | - /** |
|---|
| 1121 | - * Sets the From name of the message. |
|---|
| 1122 | - * @var string |
|---|
| 1123 | - */ |
|---|
| 1124 | - var $FromName = "Support"; |
|---|
| 1125 | + /** |
|---|
| 1126 | + * Holds the most recent mailer error message. |
|---|
| 1127 | + * @var string |
|---|
| 1128 | + */ |
|---|
| 1129 | + var $ErrorInfo = ''; |
|---|
| 1130 | |
|---|
| 1131 | - /** |
|---|
| 1132 | - * Sets the Sender email (Return-Path) of the message. If not empty, |
|---|
| 1133 | - * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
|---|
| 1134 | - * @var string |
|---|
| 1135 | - */ |
|---|
| 1136 | - var $Sender = ""; |
|---|
| 1137 | + /** |
|---|
| 1138 | + * Sets the From email address for the message. |
|---|
| 1139 | + * @var string |
|---|
| 1140 | + */ |
|---|
| 1141 | + var $From = 'root@localhost'; |
|---|
| 1142 | |
|---|
| 1143 | - /** |
|---|
| 1144 | - * Sets the Subject of the message. |
|---|
| 1145 | - * @var string |
|---|
| 1146 | - */ |
|---|
| 1147 | - var $Subject = ""; |
|---|
| 1148 | + /** |
|---|
| 1149 | + * Sets the From name of the message. |
|---|
| 1150 | + * @var string |
|---|
| 1151 | + */ |
|---|
| 1152 | + var $FromName = 'Root User'; |
|---|
| 1153 | |
|---|
| 1154 | - /** |
|---|
| 1155 | - * Sets the Body of the message. This can be either an HTML or text body. |
|---|
| 1156 | - * If HTML then run IsHTML(true). |
|---|
| 1157 | - * @var string |
|---|
| 1158 | - */ |
|---|
| 1159 | - var $Body = ""; |
|---|
| 1160 | + /** |
|---|
| 1161 | + * Sets the Sender email (Return-Path) of the message. If not empty, |
|---|
| 1162 | + * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
|---|
| 1163 | + * @var string |
|---|
| 1164 | + */ |
|---|
| 1165 | + var $Sender = ''; |
|---|
| 1166 | |
|---|
| 1167 | - /** |
|---|
| 1168 | - * Sets the text-only body of the message. This automatically sets the |
|---|
| 1169 | - * email to multipart/alternative. This body can be read by mail |
|---|
| 1170 | - * clients that do not have HTML email capability such as mutt. Clients |
|---|
| 1171 | - * that can read HTML will view the normal Body. |
|---|
| 1172 | - * @var string |
|---|
| 1173 | - */ |
|---|
| 1174 | - var $AltBody = ""; |
|---|
| 1175 | + /** |
|---|
| 1176 | + * Sets the Subject of the message. |
|---|
| 1177 | + * @var string |
|---|
| 1178 | + */ |
|---|
| 1179 | + var $Subject = ''; |
|---|
| 1180 | |
|---|
| 1181 | - /** |
|---|
| 1182 | - * Sets word wrapping on the body of the message to a given number of |
|---|
| 1183 | - * characters. |
|---|
| 1184 | - * @var int |
|---|
| 1185 | - */ |
|---|
| 1186 | - var $WordWrap = 0; |
|---|
| 1187 | + /** |
|---|
| 1188 | + * Sets the Body of the message. This can be either an HTML or text body. |
|---|
| 1189 | + * If HTML then run IsHTML(true). |
|---|
| 1190 | + * @var string |
|---|
| 1191 | + */ |
|---|
| 1192 | + var $Body = ''; |
|---|
| 1193 | |
|---|
| 1194 | - /** |
|---|
| 1195 | - * Method to send mail: ("mail", "sendmail", or "smtp"). |
|---|
| 1196 | - * @var string |
|---|
| 1197 | - */ |
|---|
| 1198 | - var $Mailer = "mail"; |
|---|
| 1199 | + /** |
|---|
| 1200 | + * Sets the text-only body of the message. This automatically sets the |
|---|
| 1201 | + * email to multipart/alternative. This body can be read by mail |
|---|
| 1202 | + * clients that do not have HTML email capability such as mutt. Clients |
|---|
| 1203 | + * that can read HTML will view the normal Body. |
|---|
| 1204 | + * @var string |
|---|
| 1205 | + */ |
|---|
| 1206 | + var $AltBody = ''; |
|---|
| 1207 | |
|---|
| 1208 | - /** |
|---|
| 1209 | - * Sets the path of the sendmail program. |
|---|
| 1210 | - * @var string |
|---|
| 1211 | - */ |
|---|
| 1212 | - var $Sendmail = "/usr/sbin/sendmail"; |
|---|
| 1213 | + /** |
|---|
| 1214 | + * Sets word wrapping on the body of the message to a given number of |
|---|
| 1215 | + * characters. |
|---|
| 1216 | + * @var int |
|---|
| 1217 | + */ |
|---|
| 1218 | + var $WordWrap = 0; |
|---|
| 1219 | |
|---|
| 1220 | - /** |
|---|
| 1221 | - * Path to PHPMailer plugins. This is now only useful if the SMTP class |
|---|
| 1222 | - * is in a different directory than the PHP include path. |
|---|
| 1223 | - * @var string |
|---|
| 1224 | - */ |
|---|
| 1225 | - var $PluginDir = ""; |
|---|
| 1226 | + /** |
|---|
| 1227 | + * Method to send mail: ("mail", "sendmail", or "smtp"). |
|---|
| 1228 | + * @var string |
|---|
| 1229 | + */ |
|---|
| 1230 | + var $Mailer = 'mail'; |
|---|
| 1231 | |
|---|
| 1232 | - /** |
|---|
| 1233 | - * Holds PHPMailer version. |
|---|
| 1234 | - * @var string |
|---|
| 1235 | - */ |
|---|
| 1236 | - var $Version = "1.73"; |
|---|
| 1237 | + /** |
|---|
| 1238 | + * Sets the path of the sendmail program. |
|---|
| 1239 | + * @var string |
|---|
| 1240 | + */ |
|---|
| 1241 | + var $Sendmail = '/usr/sbin/sendmail'; |
|---|
| 1242 | |
|---|
| 1243 | - /** |
|---|
| 1244 | - * Sets the email address that a reading confirmation will be sent. |
|---|
| 1245 | - * @var string |
|---|
| 1246 | - */ |
|---|
| 1247 | - var $ConfirmReadingTo = ""; |
|---|
| 1248 | + /** |
|---|
| 1249 | + * Path to PHPMailer plugins. This is now only useful if the SMTP class |
|---|
| 1250 | + * is in a different directory than the PHP include path. |
|---|
| 1251 | + * @var string |
|---|
| 1252 | + */ |
|---|
| 1253 | + var $PluginDir = ''; |
|---|
| 1254 | |
|---|
| 1255 | - /** |
|---|
| 1256 | - * Sets the hostname to use in Message-Id and Received headers |
|---|
| 1257 | - * and as default HELO string. If empty, the value returned |
|---|
| 1258 | - * by SERVER_NAME is used or 'localhost.localdomain'. |
|---|
| 1259 | - * @var string |
|---|
| 1260 | - */ |
|---|
| 1261 | - var $Hostname = ""; |
|---|
| 1262 | + /** |
|---|
| 1263 | + * Holds PHPMailer version. |
|---|
| 1264 | + * @var string |
|---|
| 1265 | + */ |
|---|
| 1266 | + var $Version = "2.0.2"; |
|---|
| 1267 | |
|---|
| 1268 | - ///////////////////////////////////////////////// |
|---|
| 1269 | - // SMTP VARIABLES |
|---|
| 1270 | - ///////////////////////////////////////////////// |
|---|
| 1271 | + /** |
|---|
| 1272 | + * Sets the email address that a reading confirmation will be sent. |
|---|
| 1273 | + * @var string |
|---|
| 1274 | + */ |
|---|
| 1275 | + var $ConfirmReadingTo = ''; |
|---|
| 1276 | |
|---|
| 1277 | - /** |
|---|
| 1278 | - * Sets the SMTP hosts. All hosts must be separated by a |
|---|
| 1279 | - * semicolon. You can also specify a different port |
|---|
| 1280 | - * for each host by using this format: [hostname:port] |
|---|
| 1281 | - * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|---|
| 1282 | - * Hosts will be tried in order. |
|---|
| 1283 | - * @var string |
|---|
| 1284 | - */ |
|---|
| 1285 | - var $Host = "localhost"; |
|---|
| 1286 | + /** |
|---|
| 1287 | + * Sets the hostname to use in Message-Id and Received headers |
|---|
| 1288 | + * and as default HELO string. If empty, the value returned |
|---|
| 1289 | + * by SERVER_NAME is used or 'localhost.localdomain'. |
|---|
| 1290 | + * @var string |
|---|
| 1291 | + */ |
|---|
| 1292 | + var $Hostname = ''; |
|---|
| 1293 | |
|---|
| 1294 | - /** |
|---|
| 1295 | - * Sets the default SMTP server port. |
|---|
| 1296 | - * @var int |
|---|
| 1297 | - */ |
|---|
| 1298 | - var $Port = 25; |
|---|
| 1299 | + /** |
|---|
| 1300 | + * Sets the message ID to be used in the Message-Id header. |
|---|
| 1301 | + * If empty, a unique id will be generated. |
|---|
| 1302 | + * @var string |
|---|
| 1303 | + */ |
|---|
| 1304 | + var $MessageID = ''; |
|---|
| 1305 | |
|---|
| 1306 | - /** |
|---|
| 1307 | - * Sets the SMTP HELO of the message (Default is $Hostname). |
|---|
| 1308 | - * @var string |
|---|
| 1309 | - */ |
|---|
| 1310 | - var $Helo = ""; |
|---|
| 1311 | + ///////////////////////////////////////////////// |
|---|
| 1312 | + // PROPERTIES FOR SMTP |
|---|
| 1313 | + ///////////////////////////////////////////////// |
|---|
| 1314 | |
|---|
| 1315 | - /** |
|---|
| 1316 | - * Sets SMTP authentication. Utilizes the Username and Password variables. |
|---|
| 1317 | - * @var bool |
|---|
| 1318 | - */ |
|---|
| 1319 | - var $SMTPAuth = false; |
|---|
| 1320 | + /** |
|---|
| 1321 | + * Sets the SMTP hosts. All hosts must be separated by a |
|---|
| 1322 | + * semicolon. You can also specify a different port |
|---|
| 1323 | + * for each host by using this format: [hostname:port] |
|---|
| 1324 | + * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|---|
| 1325 | + * Hosts will be tried in order. |
|---|
| 1326 | + * @var string |
|---|
| 1327 | + */ |
|---|
| 1328 | + var $Host = 'localhost'; |
|---|
| 1329 | |
|---|
| 1330 | - /** |
|---|
| 1331 | - * Sets SMTP username. |
|---|
| 1332 | - * @var string |
|---|
| 1333 | - */ |
|---|
| 1334 | - var $Username = ""; |
|---|
| 1335 | + /** |
|---|
| 1336 | + * Sets the default SMTP server port. |
|---|
| 1337 | + * @var int |
|---|
| 1338 | + */ |
|---|
| 1339 | + var $Port = 25; |
|---|
| 1340 | |
|---|
| 1341 | - /** |
|---|
| 1342 | - * Sets SMTP password. |
|---|
| 1343 | - * @var string |
|---|
| 1344 | - */ |
|---|
| 1345 | - var $Password = ""; |
|---|
| 1346 | + /** |
|---|
| 1347 | + * Sets the SMTP HELO of the message (Default is $Hostname). |
|---|
| 1348 | + * @var string |
|---|
| 1349 | + */ |
|---|
| 1350 | + var $Helo = ''; |
|---|
| 1351 | |
|---|
| 1352 | - /** |
|---|
| 1353 | - * Sets the SMTP server timeout in seconds. This function will not |
|---|
| 1354 | - * work with the win32 version. |
|---|
| 1355 | - * @var int |
|---|
| 1356 | - */ |
|---|
| 1357 | - var $Timeout = 10; |
|---|
| 1358 | + /** |
|---|
| 1359 | + * Sets connection prefix. |
|---|
| 1360 | + * Options are "", "ssl" or "tls" |
|---|
| 1361 | + * @var string |
|---|
| 1362 | + */ |
|---|
| 1363 | + var $SMTPSecure = ""; |
|---|
| 1364 | |
|---|
| 1365 | - /** |
|---|
| 1366 | - * Sets SMTP class debugging on or off. |
|---|
| 1367 | - * @var bool |
|---|
| 1368 | - */ |
|---|
| 1369 | - var $SMTPDebug = false; |
|---|
| 1370 | + /** |
|---|
| 1371 | + * Sets SMTP authentication. Utilizes the Username and Password variables. |
|---|
| 1372 | + * @var bool |
|---|
| 1373 | + */ |
|---|
| 1374 | + var $SMTPAuth = false; |
|---|
| 1375 | |
|---|
| 1376 | - /** |
|---|
| 1377 | - * Prevents the SMTP connection from being closed after each mail |
|---|
| 1378 | - * sending. If this is set to true then to close the connection |
|---|
| 1379 | - * requires an explicit call to SmtpClose(). |
|---|
| 1380 | - * @var bool |
|---|
| 1381 | - */ |
|---|
| 1382 | - var $SMTPKeepAlive = false; |
|---|
| 1383 | + /** |
|---|
| 1384 | + * Sets SMTP username. |
|---|
| 1385 | + * @var string |
|---|
| 1386 | + */ |
|---|
| 1387 | + var $Username = ''; |
|---|
| 1388 | |
|---|
| 1389 | - /**#@+ |
|---|
| 1390 | - * @access private |
|---|
| 1391 | - */ |
|---|
| 1392 | - var $smtp = NULL; |
|---|
| 1393 | - var $to = array(); |
|---|
| 1394 | - var $cc = array(); |
|---|
| 1395 | - var $bcc = array(); |
|---|
| 1396 | - var $ReplyTo = array(); |
|---|
| 1397 | - var $attachment = array(); |
|---|
| 1398 | - var $CustomHeader = array(); |
|---|
| 1399 | - var $message_type = ""; |
|---|
| 1400 | - var $boundary = array(); |
|---|
| 1401 | - var $language = array(); |
|---|
| 1402 | - var $error_count = 0; |
|---|
| 1403 | - var $LE = "\n"; |
|---|
| 1404 | - /**#@-*/ |
|---|
| 1405 | + /** |
|---|
| 1406 | + * Sets SMTP password. |
|---|
| 1407 | + * @var string |
|---|
| 1408 | + */ |
|---|
| 1409 | + var $Password = ''; |
|---|
| 1410 | |
|---|
| 1411 | - ///////////////////////////////////////////////// |
|---|
| 1412 | - // VARIABLE METHODS |
|---|
| 1413 | - ///////////////////////////////////////////////// |
|---|
| 1414 | + /** |
|---|
| 1415 | + * Sets the SMTP server timeout in seconds. This function will not |
|---|
| 1416 | + * work with the win32 version. |
|---|
| 1417 | + * @var int |
|---|
| 1418 | + */ |
|---|
| 1419 | + var $Timeout = 10; |
|---|
| 1420 | |
|---|
| 1421 | - /** |
|---|
| 1422 | - * Sets message type to HTML. |
|---|
| 1423 | - * @param bool $bool |
|---|
| 1424 | - * @return void |
|---|
| 1425 | - */ |
|---|
| 1426 | - function IsHTML($bool) { |
|---|
| 1427 | - if($bool == true) |
|---|
| 1428 | - $this->ContentType = "text/html"; |
|---|
| 1429 | - else |
|---|
| 1430 | - $this->ContentType = "text/plain"; |
|---|
| 1431 | - } |
|---|
| 1432 | + /** |
|---|
| 1433 | + * Sets SMTP class debugging on or off. |
|---|
| 1434 | + * @var bool |
|---|
| 1435 | + */ |
|---|
| 1436 | + var $SMTPDebug = false; |
|---|
| 1437 | |
|---|
| 1438 | - /** |
|---|
| 1439 | - * Sets Mailer to send message using SMTP. |
|---|
| 1440 | - * @return void |
|---|
| 1441 | - */ |
|---|
| 1442 | - function IsSMTP() { |
|---|
| 1443 | - $this->Mailer = "smtp"; |
|---|
| 1444 | - } |
|---|
| 1445 | + /** |
|---|
| 1446 | + * Prevents the SMTP connection from being closed after each mail |
|---|
| 1447 | + * sending. If this is set to true then to close the connection |
|---|
| 1448 | + * requires an explicit call to SmtpClose(). |
|---|
| 1449 | + * @var bool |
|---|
| 1450 | + */ |
|---|
| 1451 | + var $SMTPKeepAlive = false; |
|---|
| 1452 | |
|---|
| 1453 | - /** |
|---|
| 1454 | - * Sets Mailer to send message using PHP mail() function. |
|---|
| 1455 | - * @return void |
|---|
| 1456 | - */ |
|---|
| 1457 | - function IsMail() { |
|---|
| 1458 | - $this->Mailer = "mail"; |
|---|
| 1459 | - } |
|---|
| 1460 | + /** |
|---|
| 1461 | + * Provides the ability to have the TO field process individual |
|---|
| 1462 | + * emails, instead of sending to entire TO addresses |
|---|
| 1463 | + * @var bool |
|---|
| 1464 | + */ |
|---|
| 1465 | + var $SingleTo = false; |
|---|
| 1466 | |
|---|
| 1467 | - /** |
|---|
| 1468 | - * Sets Mailer to send message using the $Sendmail program. |
|---|
| 1469 | - * @return void |
|---|
| 1470 | - */ |
|---|
| 1471 | - function IsSendmail() { |
|---|
| 1472 | - $this->Mailer = "sendmail"; |
|---|
| 1473 | - } |
|---|
| 1474 | + ///////////////////////////////////////////////// |
|---|
| 1475 | + // PROPERTIES, PRIVATE |
|---|
| 1476 | + ///////////////////////////////////////////////// |
|---|
| 1477 | |
|---|
| 1478 | - /** |
|---|
| 1479 | - * Sets Mailer to send message using the qmail MTA. |
|---|
| 1480 | - * @return void |
|---|
| 1481 | - */ |
|---|
| 1482 | - function IsQmail() { |
|---|
| 1483 | - $this->Sendmail = "/var/qmail/bin/sendmail"; |
|---|
| 1484 | - $this->Mailer = "sendmail"; |
|---|
| 1485 | - } |
|---|
| 1486 | + var $smtp = NULL; |
|---|
| 1487 | + var $to = array(); |
|---|
| 1488 | + var $cc = array(); |
|---|
| 1489 | + var $bcc = array(); |
|---|
| 1490 | + var $ReplyTo = array(); |
|---|
| 1491 | + var $attachment = array(); |
|---|
| 1492 | + var $CustomHeader = array(); |
|---|
| 1493 | + var $message_type = ''; |
|---|
| 1494 | + var $boundary = array(); |
|---|
| 1495 | + var $language = array(); |
|---|
| 1496 | + var $error_count = 0; |
|---|
| 1497 | + var $LE = "\n"; |
|---|
| 1498 | + var $sign_key_file = ""; |
|---|
| 1499 | + var $sign_key_pass = ""; |
|---|
| 1500 | |
|---|
| 1501 | + ///////////////////////////////////////////////// |
|---|
| 1502 | + // METHODS, VARIABLES |
|---|
| 1503 | + ///////////////////////////////////////////////// |
|---|
| 1504 | |
|---|
| 1505 | - ///////////////////////////////////////////////// |
|---|
| 1506 | - // RECIPIENT METHODS |
|---|
| 1507 | - ///////////////////////////////////////////////// |
|---|
| 1508 | - |
|---|
| 1509 | - /** |
|---|
| 1510 | - * Adds a "To" address. |
|---|
| 1511 | - * @param string $address |
|---|
| 1512 | - * @param string $name |
|---|
| 1513 | - * @return void |
|---|
| 1514 | - */ |
|---|
| 1515 | - function AddAddress($address, $name = "") { |
|---|
| 1516 | - $cur = count($this->to); |
|---|
| 1517 | - $this->to[$cur][0] = trim($address); |
|---|
| 1518 | - $this->to[$cur][1] = $name; |
|---|
| 1519 | + /** |
|---|
| 1520 | + * Sets message type to HTML. |
|---|
| 1521 | + * @param bool $bool |
|---|
| 1522 | + * @return void |
|---|
| 1523 | + */ |
|---|
| 1524 | + function IsHTML($bool) { |
|---|
| 1525 | + if($bool == true) { |
|---|
| 1526 | + $this->ContentType = 'text/html'; |
|---|
| 1527 | + } else { |
|---|
| 1528 | + $this->ContentType = 'text/plain'; |
|---|
| 1529 | } |
|---|
| 1530 | + } |
|---|
| 1531 | |
|---|
| 1532 | - /** |
|---|
| 1533 | - * Adds a "Cc" address. Note: this function works |
|---|
| 1534 | - * with the SMTP mailer on win32, not with the "mail" |
|---|
| 1535 | - * mailer. |
|---|
| 1536 | - * @param string $address |
|---|
| 1537 | - * @param string $name |
|---|
| 1538 | - * @return void |
|---|
| 1539 | - */ |
|---|
| 1540 | - function AddCC($address, $name = "") { |
|---|
| 1541 | - $cur = count($this->cc); |
|---|
| 1542 | - $this->cc[$cur][0] = trim($address); |
|---|
| 1543 | - $this->cc[$cur][1] = $name; |
|---|
| 1544 | - } |
|---|
| 1545 | + /** |
|---|
| 1546 | + * Sets Mailer to send message using SMTP. |
|---|
| 1547 | + * @return void |
|---|
| 1548 | + */ |
|---|
| 1549 | + function IsSMTP() { |
|---|
| 1550 | + $this->Mailer = 'smtp'; |
|---|
| 1551 | + } |
|---|
| 1552 | |
|---|
| 1553 | - /** |
|---|
| 1554 | - * Adds a "Bcc" address. Note: this function works |
|---|
| 1555 | - * with the SMTP mailer on win32, not with the "mail" |
|---|
| 1556 | - * mailer. |
|---|
| 1557 | - * @param string $address |
|---|
| 1558 | - * @param string $name |
|---|
| 1559 | - * @return void |
|---|
| 1560 | - */ |
|---|
| 1561 | - function AddBCC($address, $name = "") { |
|---|
| 1562 | - $cur = count($this->bcc); |
|---|
| 1563 | - $this->bcc[$cur][0] = trim($address); |
|---|
| 1564 | - $this->bcc[$cur][1] = $name; |
|---|
| 1565 | - } |
|---|
| 1566 | + /** |
|---|
| 1567 | + * Sets Mailer to send message using PHP mail() function. |
|---|
| 1568 | + * @return void |
|---|
| 1569 | + */ |
|---|
| 1570 | + function IsMail() { |
|---|
| 1571 | + $this->Mailer = 'mail'; |
|---|
| 1572 | + } |
|---|
| 1573 | |
|---|
| 1574 | - /** |
|---|
| 1575 | - * Adds a "Reply-to" address. |
|---|
| 1576 | - * @param string $address |
|---|
| 1577 | - * @param string $name |
|---|
| 1578 | - * @return void |
|---|
| 1579 | - */ |
|---|
| 1580 | - function AddReplyTo($address, $name = "") { |
|---|
| 1581 | - $cur = count($this->ReplyTo); |
|---|
| 1582 | - $this->ReplyTo[$cur][0] = trim($address); |
|---|
| 1583 | - $this->ReplyTo[$cur][1] = $name; |
|---|
| 1584 | - } |
|---|
| 1585 | + /** |
|---|
| 1586 | + * Sets Mailer to send message using the $Sendmail program. |
|---|
| 1587 | + * @return void |
|---|
| 1588 | + */ |
|---|
| 1589 | + function IsSendmail() { |
|---|
| 1590 | + $this->Mailer = 'sendmail'; |
|---|
| 1591 | + } |
|---|
| 1592 | |
|---|
| 1593 | + /** |
|---|
| 1594 | + * Sets Mailer to send message using the qmail MTA. |
|---|
| 1595 | + * @return void |
|---|
| 1596 | + */ |
|---|
| 1597 | + function IsQmail() { |
|---|
| 1598 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|---|
| 1599 | + $this->Mailer = 'sendmail'; |
|---|
| 1600 | + } |
|---|
| 1601 | |
|---|
| 1602 | - ///////////////////////////////////////////////// |
|---|
| 1603 | - // MAIL SENDING METHODS |
|---|
| 1604 | - ///////////////////////////////////////////////// |
|---|
| 1605 | + ///////////////////////////////////////////////// |
|---|
| 1606 | + // METHODS, RECIPIENTS |
|---|
| 1607 | + ///////////////////////////////////////////////// |
|---|
| 1608 | |
|---|
| 1609 | - /** |
|---|
| 1610 | - * Creates message and assigns Mailer. If the message is |
|---|
| 1611 | - * not sent successfully then it returns false. Use the ErrorInfo |
|---|
| 1612 | - * variable to view description of the error. |
|---|
| 1613 | - * @return bool |
|---|
| 1614 | - */ |
|---|
| 1615 | - function Send() { |
|---|
| 1616 | - $header = ""; |
|---|
| 1617 | - $body = ""; |
|---|
| 1618 | - $result = true; |
|---|
| 1619 | + /** |
|---|
| 1620 | + * Adds a "To" address. |
|---|
| 1621 | + * @param string $address |
|---|
| 1622 | + * @param string $name |
|---|
| 1623 | + * @return void |
|---|
| 1624 | + */ |
|---|
| 1625 | + function AddAddress($address, $name = '') { |
|---|
| 1626 | + $cur = count($this->to); |
|---|
| 1627 | + $this->to[$cur][0] = trim($address); |
|---|
| 1628 | + $this->to[$cur][1] = $name; |
|---|
| 1629 | + } |
|---|
| 1630 | |
|---|
| 1631 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) |
|---|
| 1632 | - { |
|---|
| 1633 | - $this->SetError($this->Lang("provide_address")); |
|---|
| 1634 | - return false; |
|---|
| 1635 | - } |
|---|
| 1636 | + /** |
|---|
| 1637 | + * Adds a "Cc" address. Note: this function works |
|---|
| 1638 | + * with the SMTP mailer on win32, not with the "mail" |
|---|
| 1639 | + * mailer. |
|---|
| 1640 | + * @param string $address |
|---|
| 1641 | + * @param string $name |
|---|
| 1642 | + * @return void |
|---|
| 1643 | + */ |
|---|
| 1644 | + function AddCC($address, $name = '') { |
|---|
| 1645 | + $cur = count($this->cc); |
|---|
| 1646 | + $this->cc[$cur][0] = trim($address); |
|---|
| 1647 | + $this->cc[$cur][1] = $name; |
|---|
| 1648 | + } |
|---|
| 1649 | |
|---|
| 1650 | - // Set whether the message is multipart/alternative |
|---|
| 1651 | - if(!empty($this->AltBody)) |
|---|
| 1652 | - $this->ContentType = "multipart/alternative"; |
|---|
| 1653 | + /** |
|---|
| 1654 | + * Adds a "Bcc" address. Note: this function works |
|---|
| 1655 | + * with the SMTP mailer on win32, not with the "mail" |
|---|
| 1656 | + * mailer. |
|---|
| 1657 | + * @param string $address |
|---|
| 1658 | + * @param string $name |
|---|
| 1659 | + * @return void |
|---|
| 1660 | + */ |
|---|
| 1661 | + function AddBCC($address, $name = '') { |
|---|
| 1662 | + $cur = count($this->bcc); |
|---|
| 1663 | + $this->bcc[$cur][0] = trim($address); |
|---|
| 1664 | + $this->bcc[$cur][1] = $name; |
|---|
| 1665 | + } |
|---|
| 1666 | |
|---|
| 1667 | - $this->error_count = 0; // reset errors |
|---|
| 1668 | - $this->SetMessageType(); |
|---|
| 1669 | - $header .= $this->CreateHeader(); |
|---|
| 1670 | - $body = $this->CreateBody(); |
|---|
| 1671 | + /** |
|---|
| 1672 | + * Adds a "Reply-To" address. |
|---|
| 1673 | + * @param string $address |
|---|
| 1674 | + * @param string $name |
|---|
| 1675 | + * @return void |
|---|
| 1676 | + */ |
|---|
| 1677 | + function AddReplyTo($address, $name = '') { |
|---|
| 1678 | + $cur = count($this->ReplyTo); |
|---|
| 1679 | + $this->ReplyTo[$cur][0] = trim($address); |
|---|
| 1680 | + $this->ReplyTo[$cur][1] = $name; |
|---|
| 1681 | + } |
|---|
| 1682 | |
|---|
| 1683 | - if($body == "") { return false; } |
|---|
| 1684 | + ///////////////////////////////////////////////// |
|---|
| 1685 | + // METHODS, MAIL SENDING |
|---|
| 1686 | + ///////////////////////////////////////////////// |
|---|
| 1687 | |
|---|
| 1688 | - // Choose the mailer |
|---|
| 1689 | - switch($this->Mailer) |
|---|
| 1690 | - { |
|---|
| 1691 | - case "sendmail": |
|---|
| 1692 | - $result = $this->SendmailSend($header, $body); |
|---|
| 1693 | - break; |
|---|
| 1694 | - case "mail": |
|---|
| 1695 | - $result = $this->MailSend($header, $body); |
|---|
| 1696 | - break; |
|---|
| 1697 | - case "smtp": |
|---|
| 1698 | - $result = $this->SmtpSend($header, $body); |
|---|
| 1699 | - break; |
|---|
| 1700 | - default: |
|---|
| 1701 | - $this->SetError($this->Mailer . $this->Lang("mailer_not_supported")); |
|---|
| 1702 | - $result = false; |
|---|
| 1703 | - break; |
|---|
| 1704 | - } |
|---|
| 1705 | + /** |
|---|
| 1706 | + * Creates message and assigns Mailer. If the message is |
|---|
| 1707 | + * not sent successfully then it returns false. Use the ErrorInfo |
|---|
| 1708 | + * variable to view description of the error. |
|---|
| 1709 | + * @return bool |
|---|
| 1710 | + */ |
|---|
| 1711 | + function Send() { |
|---|
| 1712 | + $header = ''; |
|---|
| 1713 | + $body = ''; |
|---|
| 1714 | + $result = true; |
|---|
| 1715 | |
|---|
| 1716 | - return $result; |
|---|
| 1717 | + if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|---|
| 1718 | + $this->SetError($this->Lang('provide_address')); |
|---|
| 1719 | + return false; |
|---|
| 1720 | } |
|---|
| 1721 | |
|---|
| 1722 | - /** |
|---|
| 1723 | - * Sends mail using the $Sendmail program. |
|---|
| 1724 | - * @access private |
|---|
| 1725 | - * @return bool |
|---|
| 1726 | - */ |
|---|
| 1727 | - function SendmailSend($header, $body) { |
|---|
| 1728 | - if ($this->Sender != "") |
|---|
| 1729 | - $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, escapeshellarg($this->Sender)); |
|---|
| 1730 | - else |
|---|
| 1731 | - $sendmail = sprintf("%s -oi -t", $this->Sendmail); |
|---|
| 1732 | + /* Set whether the message is multipart/alternative */ |
|---|
| 1733 | + if(!empty($this->AltBody)) { |
|---|
| 1734 | + $this->ContentType = 'multipart/alternative'; |
|---|
| 1735 | + } |
|---|
| 1736 | |
|---|
| 1737 | - if(!@$mail = popen($sendmail, "w")) |
|---|
| 1738 | - { |
|---|
| 1739 | - $this->SetError($this->Lang("execute") . $this->Sendmail); |
|---|
| 1740 | - return false; |
|---|
| 1741 | - } |
|---|
| 1742 | + $this->error_count = 0; // reset errors |
|---|
| 1743 | + $this->SetMessageType(); |
|---|
| 1744 | + $header .= $this->CreateHeader(); |
|---|
| 1745 | + $body = $this->CreateBody(); |
|---|
| 1746 | |
|---|
| 1747 | - fputs($mail, $header); |
|---|
| 1748 | - fputs($mail, $body); |
|---|
| 1749 | + if($body == '') { |
|---|
| 1750 | + return false; |
|---|
| 1751 | + } |
|---|
| 1752 | |
|---|
| 1753 | - $result = pclose($mail) >> 8 & 0xFF; |
|---|
| 1754 | - if($result != 0) |
|---|
| 1755 | - { |
|---|
| 1756 | - $this->SetError($this->Lang("execute") . $this->Sendmail); |
|---|
| 1757 | - return false; |
|---|
| 1758 | - } |
|---|
| 1759 | - |
|---|
| 1760 | - return true; |
|---|
| 1761 | + /* Choose the mailer */ |
|---|
| 1762 | + switch($this->Mailer) { |
|---|
| 1763 | + case 'sendmail': |
|---|
| 1764 | + $result = $this->SendmailSend($header, $body); |
|---|
| 1765 | + break; |
|---|
| 1766 | + case 'smtp': |
|---|
| 1767 | + $result = $this->SmtpSend($header, $body); |
|---|
| 1768 | + break; |
|---|
| 1769 | + case 'mail': |
|---|
| 1770 | + $result = $this->MailSend($header, $body); |
|---|
| 1771 | + break; |
|---|
| 1772 | + default: |
|---|
| 1773 | + $result = $this->MailSend($header, $body); |
|---|
| 1774 | + break; |
|---|
| 1775 | + //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported')); |
|---|
| 1776 | + //$result = false; |
|---|
| 1777 | + //break; |
|---|
| 1778 | } |
|---|
| 1779 | |
|---|
| 1780 | - /** |
|---|
| 1781 | - * Sends mail using the PHP mail() function. |
|---|
| 1782 | - * @access private |
|---|
| 1783 | - * @return bool |
|---|
| 1784 | - */ |
|---|
| 1785 | - function MailSend($header, $body) { |
|---|
| 1786 | - $to = ""; |
|---|
| 1787 | - for($i = 0; $i < count($this->to); $i++) |
|---|
| 1788 | - { |
|---|
| 1789 | - if($i != 0) { $to .= ", "; } |
|---|
| 1790 | - $to .= $this->to[$i][0]; |
|---|
| 1791 | - } |
|---|
| 1792 | + return $result; |
|---|
| 1793 | + } |
|---|
| 1794 | |
|---|
| 1795 | - if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) |
|---|
| 1796 | - { |
|---|
| 1797 | - $old_from = ini_get("sendmail_from"); |
|---|
| 1798 | - ini_set("sendmail_from", $this->Sender); |
|---|
| 1799 | - $params = sprintf("-oi -f %s", $this->Sender); |
|---|
| 1800 | - $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
|---|
| 1801 | - $header, $params); |
|---|
| 1802 | - } |
|---|
| 1803 | - else |
|---|
| 1804 | - $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); |
|---|
| 1805 | + /** |
|---|
| 1806 | + * Sends mail using the $Sendmail program. |
|---|
| 1807 | + * @access private |
|---|
| 1808 | + * @return bool |
|---|
| 1809 | + */ |
|---|
| 1810 | + function SendmailSend($header, $body) { |
|---|
| 1811 | + if ($this->Sender != '') { |
|---|
| 1812 | + $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|---|
| 1813 | + } else { |
|---|
| 1814 | + $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|---|
| 1815 | + } |
|---|
| 1816 | |
|---|
| 1817 | - if (isset($old_from)) |
|---|
| 1818 | - ini_set("sendmail_from", $old_from); |
|---|
| 1819 | + if(!@$mail = popen($sendmail, 'w')) { |
|---|
| 1820 | + $this->SetError($this->Lang('execute') . $this->Sendmail); |
|---|
| 1821 | + return false; |
|---|
| 1822 | + } |
|---|
| 1823 | |
|---|
| 1824 | - if(!$rt) |
|---|
| 1825 | - { |
|---|
| 1826 | - $this->SetError($this->Lang("instantiate")); |
|---|
| 1827 | - return false; |
|---|
| 1828 | - } |
|---|
| 1829 | + fputs($mail, $header); |
|---|
| 1830 | + fputs($mail, $body); |
|---|
| 1831 | |
|---|
| 1832 | - return true; |
|---|
| 1833 | + $result = pclose($mail); |
|---|
| 1834 | + if (version_compare(phpversion(), '4.2.3') == -1) { |
|---|
| 1835 | + $result = $result >> 8 & 0xFF; |
|---|
| 1836 | } |
|---|
| 1837 | + if($result != 0) { |
|---|
| 1838 | + $this->SetError($this->Lang('execute') . $this->Sendmail); |
|---|
| 1839 | + return false; |
|---|
| 1840 | + } |
|---|
| 1841 | + return true; |
|---|
| 1842 | + } |
|---|
| 1843 | |
|---|
| 1844 | - /** |
|---|
| 1845 | - * Sends mail via SMTP using PhpSMTP (Author: |
|---|
| 1846 | - * Chris Ryan). Returns bool. Returns false if there is a |
|---|
| 1847 | - * bad MAIL FROM, RCPT, or DATA input. |
|---|
| 1848 | - * @access private |
|---|
| 1849 | - * @return bool |
|---|
| 1850 | - */ |
|---|
| 1851 | - function SmtpSend($header, $body) { |
|---|
| 1852 | - include_once($this->PluginDir . "class-smtp.php"); |
|---|
| 1853 | - $error = ""; |
|---|
| 1854 | - $bad_rcpt = array(); |
|---|
| 1855 | + /** |
|---|
| 1856 | + * Sends mail using the PHP mail() function. |
|---|
| 1857 | + * @access private |
|---|
| 1858 | + * @return bool |
|---|
| 1859 | + */ |
|---|
| 1860 | + function MailSend($header, $body) { |
|---|
| 1861 | |
|---|
| 1862 | - if(!$this->SmtpConnect()) |
|---|
| 1863 | - return false; |
|---|
| 1864 | + $to = ''; |
|---|
| 1865 | + for($i = 0; $i < count($this->to); $i++) { |
|---|
| 1866 | + if($i != 0) { $to .= ', '; } |
|---|
| 1867 | + $to .= $this->AddrFormat($this->to[$i]); |
|---|
| 1868 | + } |
|---|
| 1869 | |
|---|
| 1870 | - $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; |
|---|
| 1871 | - if(!$this->smtp->Mail($smtp_from)) |
|---|
| 1872 | - { |
|---|
| 1873 | - $error = $this->Lang("from_failed") . $smtp_from; |
|---|
| 1874 | - $this->SetError($error); |
|---|
| 1875 | - $this->smtp->Reset(); |
|---|
| 1876 | - return false; |
|---|
| 1877 | - } |
|---|
| 1878 | + $toArr = split(',', $to); |
|---|
| 1879 | |
|---|
| 1880 | - // Attempt to send attach all recipients |
|---|
| 1881 | - for($i = 0; $i < count($this->to); $i++) |
|---|
| 1882 | - { |
|---|
| 1883 | - if(!$this->smtp->Recipient($this->to[$i][0])) |
|---|
| 1884 | - $bad_rcpt[] = $this->to[$i][0]; |
|---|
| 1885 | + $params = sprintf("-oi -f %s", $this->Sender); |
|---|
| 1886 | + if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|---|
| 1887 | + $old_from = ini_get('sendmail_from'); |
|---|
| 1888 | + ini_set('sendmail_from', $this->Sender); |
|---|
| 1889 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|---|
| 1890 | + foreach ($toArr as $key => $val) { |
|---|
| 1891 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|---|
| 1892 | } |
|---|
| 1893 | - for($i = 0; $i < count($this->cc); $i++) |
|---|
| 1894 | - { |
|---|
| 1895 | - if(!$this->smtp->Recipient($this->cc[$i][0])) |
|---|
| 1896 | - $bad_rcpt[] = $this->cc[$i][0]; |
|---|
| 1897 | + } else { |
|---|
| 1898 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|---|
| 1899 | + } |
|---|
| 1900 | + } else { |
|---|
| 1901 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|---|
| 1902 | + foreach ($toArr as $key => $val) { |
|---|
| 1903 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|---|
| 1904 | } |
|---|
| 1905 | - for($i = 0; $i < count($this->bcc); $i++) |
|---|
| 1906 | - { |
|---|
| 1907 | - if(!$this->smtp->Recipient($this->bcc[$i][0])) |
|---|
| 1908 | - $bad_rcpt[] = $this->bcc[$i][0]; |
|---|
| 1909 | - } |
|---|
| 1910 | + } else { |
|---|
| 1911 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|---|
| 1912 | + } |
|---|
| 1913 | + } |
|---|
| 1914 | |
|---|
| 1915 | - if(count($bad_rcpt) > 0) // Create error message |
|---|
| 1916 | - { |
|---|
| 1917 | - for($i = 0; $i < count($bad_rcpt); $i++) |
|---|
| 1918 | - { |
|---|
| 1919 | - if($i != 0) { $error .= ", "; } |
|---|
| 1920 | - $error .= $bad_rcpt[$i]; |
|---|
| 1921 | - } |
|---|
| 1922 | - $error = $this->Lang("recipients_failed") . $error; |
|---|
| 1923 | - $this->SetError($error); |
|---|
| 1924 | - $this->smtp->Reset(); |
|---|
| 1925 | - return false; |
|---|
| 1926 | - } |
|---|
| 1927 | + if (isset($old_from)) { |
|---|
| 1928 | + ini_set('sendmail_from', $old_from); |
|---|
| 1929 | + } |
|---|
| 1930 | |
|---|
| 1931 | - if(!$this->smtp->Data($header . $body)) |
|---|
| 1932 | - { |
|---|
| 1933 | - $this->SetError($this->Lang("data_not_accepted")); |
|---|
| 1934 | - $this->smtp->Reset(); |
|---|
| 1935 | - return false; |
|---|
| 1936 | - } |
|---|
| 1937 | - if($this->SMTPKeepAlive == true) |
|---|
| 1938 | - $this->smtp->Reset(); |
|---|
| 1939 | - else |
|---|
| 1940 | - $this->SmtpClose(); |
|---|
| 1941 | - |
|---|
| 1942 | - return true; |
|---|
| 1943 | + if(!$rt) { |
|---|
| 1944 | + $this->SetError($this->Lang('instantiate')); |
|---|
| 1945 | + return false; |
|---|
| 1946 | } |
|---|
| 1947 | |
|---|
| 1948 | - /** |
|---|
| 1949 | - * Initiates a connection to an SMTP server. Returns false if the |
|---|
| 1950 | - * operation failed. |
|---|
| 1951 | - * @access private |
|---|
| 1952 | - * @return bool |
|---|
| 1953 | - */ |
|---|
| 1954 | - function SmtpConnect() { |
|---|
| 1955 | - if($this->smtp == NULL) { $this->smtp = new SMTP(); } |
|---|
| 1956 | + return true; |
|---|
| 1957 | + } |
|---|
| 1958 | |
|---|
| 1959 | - $this->smtp->do_debug = $this->SMTPDebug; |
|---|
| 1960 | - $hosts = explode(";", $this->Host); |
|---|
| 1961 | - $index = 0; |
|---|
| 1962 | - $connection = ($this->smtp->Connected()); |
|---|
| 1963 | + /** |
|---|
| 1964 | + * Sends mail via SMTP using PhpSMTP (Author: |
|---|
| 1965 | + * Chris Ryan). Returns bool. Returns false if there is a |
|---|
| 1966 | + * bad MAIL FROM, RCPT, or DATA input. |
|---|
| 1967 | + * @access private |
|---|
| 1968 | + * @return bool |
|---|
| 1969 | + */ |
|---|
| 1970 | + function SmtpSend($header, $body) { |
|---|
| 1971 | + include_once($this->PluginDir . 'class.smtp.php'); |
|---|
| 1972 | + $error = ''; |
|---|
| 1973 | + $bad_rcpt = array(); |
|---|
| 1974 | |
|---|
| 1975 | - // Retry while there is no connection |
|---|
| 1976 | - while($index < count($hosts) && $connection == false) |
|---|
| 1977 | - { |
|---|
| 1978 | - if(strstr($hosts[$index], ":")) |
|---|
| 1979 | - list($host, $port) = explode(":", $hosts[$index]); |
|---|
| 1980 | - else |
|---|
| 1981 | - { |
|---|
| 1982 | - $host = $hosts[$index]; |
|---|
| 1983 | - $port = $this->Port; |
|---|
| 1984 | - } |
|---|
| 1985 | + if(!$this->SmtpConnect()) { |
|---|
| 1986 | + return false; |
|---|
| 1987 | + } |
|---|
| 1988 | |
|---|
| 1989 | - if($this->smtp->Connect($host, $port, $this->Timeout)) |
|---|
| 1990 | - { |
|---|
| 1991 | - if ($this->Helo != '') |
|---|
| 1992 | - $this->smtp->Hello($this->Helo); |
|---|
| 1993 | - else |
|---|
| 1994 | - $this->smtp->Hello($this->ServerHostname()); |
|---|
| 1995 | + $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|---|
| 1996 | + if(!$this->smtp->Mail($smtp_from)) { |
|---|
| 1997 | + $error = $this->Lang('from_failed') . $smtp_from; |
|---|
| 1998 | + $this->SetError($error); |
|---|
| 1999 | + $this->smtp->Reset(); |
|---|
| 2000 | + return false; |
|---|
| 2001 | + } |
|---|
| 2002 | |
|---|
| 2003 | - if($this->SMTPAuth) |
|---|
| 2004 | - { |
|---|
| 2005 | - if(!$this->smtp->Authenticate($this->Username, |
|---|
| 2006 | - $this->Password)) |
|---|
| 2007 | - { |
|---|
| 2008 | - $this->SetError($this->Lang("authenticate")); |
|---|
| 2009 | - $this->smtp->Reset(); |
|---|
| 2010 | - $connection = false; |
|---|
| 2011 | - } |
|---|
| 2012 | - } |
|---|
| 2013 | - $connection = true; |
|---|
| 2014 | - } |
|---|
| 2015 | - $index++; |
|---|
| 2016 | - } |
|---|
| 2017 | - if(!$connection) |
|---|
| 2018 | - $this->SetError($this->Lang("connect_host")); |
|---|
| 2019 | - |
|---|
| 2020 | - return $connection; |
|---|
| 2021 | + /* Attempt to send attach all recipients */ |
|---|
| 2022 | + for($i = 0; $i < count($this->to); $i++) { |
|---|
| 2023 | + if(!$this->smtp->Recipient($this->to[$i][0])) { |
|---|
| 2024 | + $bad_rcpt[] = $this->to[$i][0]; |
|---|
| 2025 | + } |
|---|
| 2026 | } |
|---|
| 2027 | + for($i = 0; $i < count($this->cc); $i++) { |
|---|
| 2028 | + if(!$this->smtp->Recipient($this->cc[$i][0])) { |
|---|
| 2029 | + $bad_rcpt[] = $this->cc[$i][0]; |
|---|
| 2030 | + } |
|---|
| 2031 | + } |
|---|
| 2032 | + for($i = 0; $i < count($this->bcc); $i++) { |
|---|
| 2033 | + if(!$this->smtp->Recipient($this->bcc[$i][0])) { |
|---|
| 2034 | + $bad_rcpt[] = $this->bcc[$i][0]; |
|---|
| 2035 | + } |
|---|
| 2036 | + } |
|---|
| 2037 | |
|---|
| 2038 | - /** |
|---|
| 2039 | - * Closes the active SMTP session if one exists. |
|---|
| 2040 | - * @return void |
|---|
| 2041 | - */ |
|---|
| 2042 | - function SmtpClose() { |
|---|
| 2043 | - if($this->smtp != NULL) |
|---|
| 2044 | - { |
|---|
| 2045 | - if($this->smtp->Connected()) |
|---|
| 2046 | - { |
|---|
| 2047 | - $this->smtp->Quit(); |
|---|
| 2048 | - $this->smtp->Close(); |
|---|
| 2049 | - } |
|---|
| 2050 | + if(count($bad_rcpt) > 0) { // Create error message |
|---|
| 2051 | + for($i = 0; $i < count($bad_rcpt); $i++) { |
|---|
| 2052 | + if($i != 0) { |
|---|
| 2053 | + $error .= ', '; |
|---|
| 2054 | } |
|---|
| 2055 | + $error .= $bad_rcpt[$i]; |
|---|
| 2056 | + } |
|---|
| 2057 | + $error = $this->Lang('recipients_failed') . $error; |
|---|
| 2058 | + $this->SetError($error); |
|---|
| 2059 | + $this->smtp->Reset(); |
|---|
| 2060 | + return false; |
|---|
| 2061 | } |
|---|
| 2062 | |
|---|
| 2063 | - /** |
|---|
| 2064 | - * Sets the language for all class error messages. Returns false |
|---|
| 2065 | - * if it cannot load the language file. The default language type |
|---|
| 2066 | - * is English. |
|---|
| 2067 | - * @param string $lang_type Type of language (e.g. Portuguese: "br") |
|---|
| 2068 | - * @param string $lang_path Path to the language file directory |
|---|
| 2069 | - * @access public |
|---|
| 2070 | - * @return bool |
|---|
| 2071 | - */ |
|---|
| 2072 | - function SetLanguage($lang_type, $lang_path = "language/") { |
|---|
| 2073 | - if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) |
|---|
| 2074 | - include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|---|
| 2075 | - else if(file_exists($lang_path.'phpmailer.lang-en.php')) |
|---|
| 2076 | - include($lang_path.'phpmailer.lang-en.php'); |
|---|
| 2077 | - else |
|---|
| 2078 | - { |
|---|
| 2079 | - $this->SetError("Could not load language file"); |
|---|
| 2080 | - return false; |
|---|
| 2081 | - } |
|---|
| 2082 | - $this->language = $PHPMAILER_LANG; |
|---|
| 2083 | + if(!$this->smtp->Data($header . $body)) { |
|---|
| 2084 | + $this->SetError($this->Lang('data_not_accepted')); |
|---|
| 2085 | + $this->smtp->Reset(); |
|---|
| 2086 | + return false; |
|---|
| 2087 | + } |
|---|
| 2088 | + if($this->SMTPKeepAlive == true) { |
|---|
| 2089 | + $this->smtp->Reset(); |
|---|
| 2090 | + } else { |
|---|
| 2091 | + $this->SmtpClose(); |
|---|
| 2092 | + } |
|---|
| 2093 | |
|---|
| 2094 | - return true; |
|---|
| 2095 | + return true; |
|---|
| 2096 | + } |
|---|
| 2097 | + |
|---|
| 2098 | + /** |
|---|
| 2099 | + * Initiates a connection to an SMTP server. Returns false if the |
|---|
| 2100 | + * operation failed. |
|---|
| 2101 | + * @access private |
|---|
| 2102 | + * @return bool |
|---|
| 2103 | + */ |
|---|
| 2104 | + function SmtpConnect() { |
|---|
| 2105 | + if($this->smtp == NULL) { |
|---|
| 2106 | + $this->smtp = new SMTP(); |
|---|
| 2107 | } |
|---|
| 2108 | |
|---|
| 2109 | - ///////////////////////////////////////////////// |
|---|
| 2110 | - // MESSAGE CREATION METHODS |
|---|
| 2111 | - ///////////////////////////////////////////////// |
|---|
| 2112 | + $this->smtp->do_debug = $this->SMTPDebug; |
|---|
| 2113 | + $hosts = explode(';', $this->Host); |
|---|
| 2114 | + $index = 0; |
|---|
| 2115 | + $connection = ($this->smtp->Connected()); |
|---|
| 2116 | |
|---|
| 2117 | - /** |
|---|
| 2118 | - * Creates recipient headers. |
|---|
| 2119 | - * @access private |
|---|
| 2120 | - * @return string |
|---|
| 2121 | - */ |
|---|
| 2122 | - function AddrAppend($type, $addr) { |
|---|
| 2123 | - $addr_str = $type . ": "; |
|---|
| 2124 | - $addr_str .= $this->AddrFormat($addr[0]); |
|---|
| 2125 | - if(count($addr) > 1) |
|---|
| 2126 | - { |
|---|
| 2127 | - for($i = 1; $i < count($addr); $i++) |
|---|
| 2128 | - $addr_str .= ", " . $this->AddrFormat($addr[$i]); |
|---|
| 2129 | + /* Retry while there is no connection */ |
|---|
| 2130 | + while($index < count($hosts) && $connection == false) { |
|---|
| 2131 | + $hostinfo = array(); |
|---|
| 2132 | + if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) { |
|---|
| 2133 | + $host = $hostinfo[1]; |
|---|
| 2134 | + $port = $hostinfo[2]; |
|---|
| 2135 | + } else { |
|---|
| 2136 | + $host = $hosts[$index]; |
|---|
| 2137 | + $port = $this->Port; |
|---|
| 2138 | + } |
|---|
| 2139 | + |
|---|
| 2140 | + if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) { |
|---|
| 2141 | + if ($this->Helo != '') { |
|---|
| 2142 | + $this->smtp->Hello($this->Helo); |
|---|
| 2143 | + } else { |
|---|
| 2144 | + $this->smtp->Hello($this->ServerHostname()); |
|---|
| 2145 | } |
|---|
| 2146 | - $addr_str .= $this->LE; |
|---|
| 2147 | |
|---|
| 2148 | - return $addr_str; |
|---|
| 2149 | + $connection = true; |
|---|
| 2150 | + if($this->SMTPAuth) { |
|---|
| 2151 | + if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|---|
| 2152 | + $this->SetError($this->Lang('authenticate')); |
|---|
| 2153 | + $this->smtp->Reset(); |
|---|
| 2154 | + $connection = false; |
|---|
| 2155 | + } |
|---|
| 2156 | + } |
|---|
| 2157 | + } |
|---|
| 2158 | + $index++; |
|---|
| 2159 | } |
|---|
| 2160 | + if(!$connection) { |
|---|
| 2161 | + $this->SetError($this->Lang('connect_host')); |
|---|
| 2162 | + } |
|---|
| 2163 | |
|---|
| 2164 | - /** |
|---|
| 2165 | - * Formats an address correctly. |
|---|
| 2166 | - * @access private |
|---|
| 2167 | - * @return string |
|---|
| 2168 | - */ |
|---|
| 2169 | - function AddrFormat($addr) { |
|---|
| 2170 | - if(empty($addr[1])) |
|---|
| 2171 | - $formatted = $addr[0]; |
|---|
| 2172 | - else |
|---|
| 2173 | - { |
|---|
| 2174 | - $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . |
|---|
| 2175 | - $addr[0] . ">"; |
|---|
| 2176 | - } |
|---|
| 2177 | + return $connection; |
|---|
| 2178 | + } |
|---|
| 2179 | |
|---|
| 2180 | - return $formatted; |
|---|
| 2181 | + /** |
|---|
| 2182 | + * Closes the active SMTP session if one exists. |
|---|
| 2183 | + * @return void |
|---|
| 2184 | + */ |
|---|
| 2185 | + function SmtpClose() { |
|---|
| 2186 | + if($this->smtp != NULL) { |
|---|
| 2187 | + if($this->smtp->Connected()) { |
|---|
| 2188 | + $this->smtp->Quit(); |
|---|
| 2189 | + $this->smtp->Close(); |
|---|
| 2190 | + } |
|---|
| 2191 | } |
|---|
| 2192 | + } |
|---|
| 2193 | |
|---|
| 2194 | - /** |
|---|
| 2195 | - * Wraps message for use with mailers that do not |
|---|
| 2196 | - * automatically perform wrapping and for quoted-printable. |
|---|
| 2197 | - * Original written by philippe. |
|---|
| 2198 | - * @access private |
|---|
| 2199 | - * @return string |
|---|
| 2200 | - */ |
|---|
| 2201 | - function WrapText($message, $length, $qp_mode = false) { |
|---|
| 2202 | - $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|---|
| 2203 | + /** |
|---|
| 2204 | + * Sets the language for all class error messages. Returns false |
|---|
| 2205 | + * if it cannot load the language file. The default language type |
|---|
| 2206 | + * is English. |
|---|
| 2207 | + * @param string $lang_type Type of language (e.g. Portuguese: "br") |
|---|
| 2208 | + * @param string $lang_path Path to the language file directory |
|---|
| 2209 | + * @access public |
|---|
| 2210 | + * @return bool |
|---|
| 2211 | + */ |
|---|
| 2212 | + function SetLanguage($lang_type, $lang_path = 'language/') { |
|---|
| 2213 | + if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) { |
|---|
| 2214 | + include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); |
|---|
| 2215 | + } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) { |
|---|
| 2216 | + include($lang_path.'phpmailer.lang-en.php'); |
|---|
| 2217 | + } else { |
|---|
| 2218 | + $this->SetError('Could not load language file'); |
|---|
| 2219 | + return false; |
|---|
| 2220 | + } |
|---|
| 2221 | + $this->language = $PHPMAILER_LANG; |
|---|
| 2222 | |
|---|
| 2223 | - $message = $this->FixEOL($message); |
|---|
| 2224 | - if (substr($message, -1) == $this->LE) |
|---|
| 2225 | - $message = substr($message, 0, -1); |
|---|
| 2226 | + return true; |
|---|
| 2227 | + } |
|---|
| 2228 | |
|---|
| 2229 | - $line = explode($this->LE, $message); |
|---|
| 2230 | - $message = ""; |
|---|
| 2231 | - for ($i=0 ;$i < count($line); $i++) |
|---|
| 2232 | - { |
|---|
| 2233 | - $line_part = explode(" ", $line[$i]); |
|---|
| 2234 | - $buf = ""; |
|---|
| 2235 | - for ($e = 0; $e<count($line_part); $e++) |
|---|
| 2236 | - { |
|---|
| 2237 | - $word = $line_part[$e]; |
|---|
| 2238 | - if ($qp_mode and (strlen($word) > $length)) |
|---|
| 2239 | - { |
|---|
| 2240 | - $space_left = $length - strlen($buf) - 1; |
|---|
| 2241 | - if ($e != 0) |
|---|
| 2242 | - { |
|---|
| 2243 | - if ($space_left > 20) |
|---|
| 2244 | - { |
|---|
| 2245 | - $len = $space_left; |
|---|
| 2246 | - if (substr($word, $len - 1, 1) == "=") |
|---|
| 2247 | - $len--; |
|---|
| 2248 | - elseif (substr($word, $len - 2, 1) == "=") |
|---|
| 2249 | - $len -= 2; |
|---|
| 2250 | - $part = substr($word, 0, $len); |
|---|
| 2251 | - $word = substr($word, $len); |
|---|
| 2252 | - $buf .= " " . $part; |
|---|
| 2253 | - $message .= $buf . sprintf("=%s", $this->LE); |
|---|
| 2254 | - } |
|---|
| 2255 | - else |
|---|
| 2256 | - { |
|---|
| 2257 | - $message .= $buf . $soft_break; |
|---|
| 2258 | - } |
|---|
| 2259 | - $buf = ""; |
|---|
| 2260 | - } |
|---|
| 2261 | - while (strlen($word) > 0) |
|---|
| 2262 | - { |
|---|
| 2263 | - $len = $length; |
|---|
| 2264 | - if (substr($word, $len - 1, 1) == "=") |
|---|
| 2265 | - $len--; |
|---|
| 2266 | - elseif (substr($word, $len - 2, 1) == "=") |
|---|
| 2267 | - $len -= 2; |
|---|
| 2268 | - $part = substr($word, 0, $len); |
|---|
| 2269 | - $word = substr($word, $len); |
|---|
| 2270 | + ///////////////////////////////////////////////// |
|---|
| 2271 | + // METHODS, MESSAGE CREATION |
|---|
| 2272 | + ///////////////////////////////////////////////// |
|---|
| 2273 | |
|---|
| 2274 | - if (strlen($word) > 0) |
|---|
| 2275 | - $message .= $part . sprintf("=%s", $this->LE); |
|---|
| 2276 | - else |
|---|
| 2277 | - $buf = $part; |
|---|
| 2278 | - } |
|---|
| 2279 | - } |
|---|
| 2280 | - else |
|---|
| 2281 | - { |
|---|
| 2282 | - $buf_o = $buf; |
|---|
| 2283 | - $buf .= ($e == 0) ? $word : (" " . $word); |
|---|
| 2284 | + /** |
|---|
| 2285 | + * Creates recipient headers. |
|---|
| 2286 | + * @access private |
|---|
| 2287 | + * @return string |
|---|
| 2288 | + */ |
|---|
| 2289 | + function AddrAppend($type, $addr) { |
|---|
| 2290 | + $addr_str = $type . ': '; |
|---|
| 2291 | + $addr_str .= $this->AddrFormat($addr[0]); |
|---|
| 2292 | + if(count($addr) > 1) { |
|---|
| 2293 | + for($i = 1; $i < count($addr); $i++) { |
|---|
| 2294 | + $addr_str .= ', ' . $this->AddrFormat($addr[$i]); |
|---|
| 2295 | + } |
|---|
| 2296 | + } |
|---|
| 2297 | + $addr_str .= $this->LE; |
|---|
| 2298 | |
|---|
| 2299 | - if (strlen($buf) > $length and $buf_o != "") |
|---|
| 2300 | - { |
|---|
| 2301 | - $message .= $buf_o . $soft_break; |
|---|
| 2302 | - $buf = $word; |
|---|
| 2303 | - } |
|---|
| 2304 | - } |
|---|
| 2305 | - } |
|---|
| 2306 | - $message .= $buf . $this->LE; |
|---|
| 2307 | - } |
|---|
| 2308 | + return $addr_str; |
|---|
| 2309 | + } |
|---|
| 2310 | |
|---|
| 2311 | - return $message; |
|---|
| 2312 | + /** |
|---|
| 2313 | + * Formats an address correctly. |
|---|
| 2314 | + * @access private |
|---|
| 2315 | + * @return string |
|---|
| 2316 | + */ |
|---|
| 2317 | + function AddrFormat($addr) { |
|---|
| 2318 | + if(empty($addr[1])) { |
|---|
| 2319 | + $formatted = $this->SecureHeader($addr[0]); |
|---|
| 2320 | + } else { |
|---|
| 2321 | + $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|---|
| 2322 | } |
|---|
| 2323 | |
|---|
| 2324 | - /** |
|---|
| 2325 | - * Set the body wrapping. |
|---|
| 2326 | - * @access private |
|---|
| 2327 | - * @return void |
|---|
| 2328 | - */ |
|---|
| 2329 | - function SetWordWrap() { |
|---|
| 2330 | - if($this->WordWrap < 1) |
|---|
| 2331 | - return; |
|---|
| 2332 | + return $formatted; |
|---|
| 2333 | + } |
|---|
| 2334 | |
|---|
| 2335 | - switch($this->message_type) |
|---|
| 2336 | - { |
|---|
| 2337 | - case "alt": |
|---|
| 2338 | - // fall through |
|---|
| 2339 | - case "alt_attachments": |
|---|
| 2340 | - $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|---|
| 2341 | - break; |
|---|
| 2342 | - default: |
|---|
| 2343 | - $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|---|
| 2344 | - break; |
|---|
| 2345 | - } |
|---|
| 2346 | + /** |
|---|
| 2347 | + * Wraps message for use with mailers that do not |
|---|
| 2348 | + * automatically perform wrapping and for quoted-printable. |
|---|
| 2349 | + * Original written by philippe. |
|---|
| 2350 | + * @access private |
|---|
| 2351 | + * @return string |
|---|
| 2352 | + */ |
|---|
| 2353 | + function WrapText($message, $length, $qp_mode = false) { |
|---|
| 2354 | + $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|---|
| 2355 | + // If utf-8 encoding is used, we will need to make sure we don't |
|---|
| 2356 | + // split multibyte characters when we wrap |
|---|
| 2357 | + $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|---|
| 2358 | + |
|---|
| 2359 | + $message = $this->FixEOL($message); |
|---|
| 2360 | + if (substr($message, -1) == $this->LE) { |
|---|
| 2361 | + $message = substr($message, 0, -1); |
|---|
| 2362 | } |
|---|
| 2363 | |
|---|
| 2364 | - /** |
|---|
| 2365 | - * Assembles message header. |
|---|
| 2366 | - * @access private |
|---|
| 2367 | - * @return string |
|---|
| 2368 | - */ |
|---|
| 2369 | - function CreateHeader() { |
|---|
| 2370 | - $result = ""; |
|---|
| 2371 | + $line = explode($this->LE, $message); |
|---|
| 2372 | + $message = ''; |
|---|
| 2373 | + for ($i=0 ;$i < count($line); $i++) { |
|---|
| 2374 | + $line_part = explode(' ', $line[$i]); |
|---|
| 2375 | + $buf = ''; |
|---|
| 2376 | + for ($e = 0; $e<count($line_part); $e++) { |
|---|
| 2377 | + $word = $line_part[$e]; |
|---|
| 2378 | + if ($qp_mode and (strlen($word) > $length)) { |
|---|
| 2379 | + $space_left = $length - strlen($buf) - 1; |
|---|
| 2380 | + if ($e != 0) { |
|---|
| 2381 | + if ($space_left > 20) { |
|---|
| 2382 | + $len = $space_left; |
|---|
| 2383 | + if ($is_utf8) { |
|---|
| 2384 | + $len = $this->UTF8CharBoundary($word, $len); |
|---|
| 2385 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|---|
| 2386 | + $len--; |
|---|
| 2387 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|---|
| 2388 | + $len -= 2; |
|---|
| 2389 | + } |
|---|
| 2390 | + $part = substr($word, 0, $len); |
|---|
| 2391 | + $word = substr($word, $len); |
|---|
| 2392 | + $buf .= ' ' . $part; |
|---|
| 2393 | + $message .= $buf . sprintf("=%s", $this->LE); |
|---|
| 2394 | + } else { |
|---|
| 2395 | + $message .= $buf . $soft_break; |
|---|
| 2396 | + } |
|---|
| 2397 | + $buf = ''; |
|---|
| 2398 | + } |
|---|
| 2399 | + while (strlen($word) > 0) { |
|---|
| 2400 | + $len = $length; |
|---|
| 2401 | + if ($is_utf8) { |
|---|
| 2402 | + $len = $this->UTF8CharBoundary($word, $len); |
|---|
| 2403 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|---|
| 2404 | + $len--; |
|---|
| 2405 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|---|
| 2406 | + $len -= 2; |
|---|
| 2407 | + } |
|---|
| 2408 | + $part = substr($word, 0, $len); |
|---|
| 2409 | + $word = substr($word, $len); |
|---|
| 2410 | |
|---|
| 2411 | - // Set the boundaries |
|---|
| 2412 | - $uniq_id = md5(uniqid(time())); |
|---|
| 2413 | - $this->boundary[1] = "b1_" . $uniq_id; |
|---|
| 2414 | - $this->boundary[2] = "b2_" . $uniq_id; |
|---|
| 2415 | + if (strlen($word) > 0) { |
|---|
| 2416 | + $message .= $part . sprintf("=%s", $this->LE); |
|---|
| 2417 | + } else { |
|---|
| 2418 | + $buf = $part; |
|---|
| 2419 | + } |
|---|
| 2420 | + } |
|---|
| 2421 | + } else { |
|---|
| 2422 | + $buf_o = $buf; |
|---|
| 2423 | + $buf .= ($e == 0) ? $word : (' ' . $word); |
|---|
| 2424 | |
|---|
| 2425 | - $result .= $this->HeaderLine("Date", $this->RFCDate()); |
|---|
| 2426 | - if($this->Sender == "") |
|---|
| 2427 | - $result .= $this->HeaderLine("Return-Path", trim($this->From)); |
|---|
| 2428 | - else |
|---|
| 2429 | - $result .= $this->HeaderLine("Return-Path", trim($this->Sender)); |
|---|
| 2430 | - |
|---|
| 2431 | - // To be created automatically by mail() |
|---|
| 2432 | - if($this->Mailer != "mail") |
|---|
| 2433 | - { |
|---|
| 2434 | - if(count($this->to) > 0) |
|---|
| 2435 | - $result .= $this->AddrAppend("To", $this->to); |
|---|
| 2436 | - else if (count($this->cc) == 0) |
|---|
| 2437 | - $result .= $this->HeaderLine("To", "undisclosed-recipients:;"); |
|---|
| 2438 | - if(count($this->cc) > 0) |
|---|
| 2439 | - $result .= $this->AddrAppend("Cc", $this->cc); |
|---|
| 2440 | + if (strlen($buf) > $length and $buf_o != '') { |
|---|
| 2441 | + $message .= $buf_o . $soft_break; |
|---|
| 2442 | + $buf = $word; |
|---|
| 2443 | + } |
|---|
| 2444 | } |
|---|
| 2445 | + } |
|---|
| 2446 | + $message .= $buf . $this->LE; |
|---|
| 2447 | + } |
|---|
| 2448 | |
|---|
| 2449 | - $from = array(); |
|---|
| 2450 | - $from[0][0] = trim($this->From); |
|---|
| 2451 | - $from[0][1] = $this->FromName; |
|---|
| 2452 | - $result .= $this->AddrAppend("From", $from); |
|---|
| 2453 | + return $message; |
|---|
| 2454 | + } |
|---|
| 2455 | |
|---|
| 2456 | - // sendmail and mail() extract Bcc from the header before sending |
|---|
| 2457 | - if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) |
|---|
| 2458 | - $result .= $this->AddrAppend("Bcc", $this->bcc); |
|---|
| 2459 | + /** |
|---|
| 2460 | + * Finds last character boundary prior to maxLength in a utf-8 |
|---|
| 2461 | + * quoted (printable) encoded string. |
|---|
| 2462 | + * Original written by Colin Brown. |
|---|
| 2463 | + * @access private |
|---|
| 2464 | + * @param string $encodedText utf-8 QP text |
|---|
| 2465 | + * @param int $maxLength find last character boundary prior to this length |
|---|
| 2466 | + * @return int |
|---|
| 2467 | + */ |
|---|
| 2468 | + function UTF8CharBoundary($encodedText, $maxLength) { |
|---|
| 2469 | + $foundSplitPos = false; |
|---|
| 2470 | + $lookBack = 3; |
|---|
| 2471 | + while (!$foundSplitPos) { |
|---|
| 2472 | + $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|---|
| 2473 | + $encodedCharPos = strpos($lastChunk, "="); |
|---|
| 2474 | + if ($encodedCharPos !== false) { |
|---|
| 2475 | + // Found start of encoded character byte within $lookBack block. |
|---|
| 2476 | + // Check the encoded byte value (the 2 chars after the '=') |
|---|
| 2477 | + $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|---|
| 2478 | + $dec = hexdec($hex); |
|---|
| 2479 | + if ($dec < 128) { // Single byte character. |
|---|
| 2480 | + // If the encoded char was found at pos 0, it will fit |
|---|
| 2481 | + // otherwise reduce maxLength to start of the encoded char |
|---|
| 2482 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|---|
| 2483 | + $maxLength - ($lookBack - $encodedCharPos); |
|---|
| 2484 | + $foundSplitPos = true; |
|---|
| 2485 | + } elseif ($dec >= 192) { // First byte of a multi byte character |
|---|
| 2486 | + // Reduce maxLength to split at start of character |
|---|
| 2487 | + $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|---|
| 2488 | + $foundSplitPos = true; |
|---|
| 2489 | + } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|---|
| 2490 | + $lookBack += 3; |
|---|
| 2491 | + } |
|---|
| 2492 | + } else { |
|---|
| 2493 | + // No encoded character found |
|---|
| 2494 | + $foundSplitPos = true; |
|---|
| 2495 | + } |
|---|
| 2496 | + } |
|---|
| 2497 | + return $maxLength; |
|---|
| 2498 | + } |
|---|
| 2499 | |
|---|
| 2500 | - if(count($this->ReplyTo) > 0) |
|---|
| 2501 | - $result .= $this->AddrAppend("Reply-to", $this->ReplyTo); |
|---|
| 2502 | + /** |
|---|
| 2503 | + * Set the body wrapping. |
|---|
| 2504 | + * @access private |
|---|
| 2505 | + * @return void |
|---|
| 2506 | + */ |
|---|
| 2507 | + function SetWordWrap() { |
|---|
| 2508 | + if($this->WordWrap < 1) { |
|---|
| 2509 | + return; |
|---|
| 2510 | + } |
|---|
| 2511 | |
|---|
| 2512 | - // mail() sets the subject itself |
|---|
| 2513 | - if($this->Mailer != "mail") |
|---|
| 2514 | - $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject))); |
|---|
| 2515 | + switch($this->message_type) { |
|---|
| 2516 | + case 'alt': |
|---|
| 2517 | + /* fall through */ |
|---|
| 2518 | + case 'alt_attachments': |
|---|
| 2519 | + $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|---|
| 2520 | + break; |
|---|
| 2521 | + default: |
|---|
| 2522 | + $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|---|
| 2523 | + break; |
|---|
| 2524 | + } |
|---|
| 2525 | + } |
|---|
| 2526 | |
|---|
| 2527 | - $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|---|
| 2528 | - $result .= $this->HeaderLine("X-Priority", $this->Priority); |
|---|
| 2529 | + /** |
|---|
| 2530 | + * Assembles message header. |
|---|
| 2531 | + * @access private |
|---|
| 2532 | + * @return string |
|---|
| 2533 | + */ |
|---|
| 2534 | + function CreateHeader() { |
|---|
| 2535 | + $result = ''; |
|---|
| 2536 | |
|---|
| 2537 | - if($this->ConfirmReadingTo != "") |
|---|
| 2538 | - { |
|---|
| 2539 | - $result .= $this->HeaderLine("Disposition-Notification-To", |
|---|
| 2540 | - "<" . trim($this->ConfirmReadingTo) . ">"); |
|---|
| 2541 | - } |
|---|
| 2542 | + /* Set the boundaries */ |
|---|
| 2543 | + $uniq_id = md5(uniqid(time())); |
|---|
| 2544 | + $this->boundary[1] = 'b1_' . $uniq_id; |
|---|
| 2545 | + $this->boundary[2] = 'b2_' . $uniq_id; |
|---|
| 2546 | |
|---|
| 2547 | - // Add custom headers |
|---|
| 2548 | - for($index = 0; $index < count($this->CustomHeader); $index++) |
|---|
| 2549 | - { |
|---|
| 2550 | - $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), |
|---|
| 2551 | - $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|---|
| 2552 | - } |
|---|
| 2553 | - $result .= $this->HeaderLine("MIME-Version", "1.0"); |
|---|
| 2554 | + $result .= $this->HeaderLine('Date', $this->RFCDate()); |
|---|
| 2555 | + if($this->Sender == '') { |
|---|
| 2556 | + $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|---|
| 2557 | + } else { |
|---|
| 2558 | + $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|---|
| 2559 | + } |
|---|
| 2560 | |
|---|
| 2561 | - switch($this->message_type) |
|---|
| 2562 | - { |
|---|
| 2563 | - case "plain": |
|---|
| 2564 | - $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding); |
|---|
| 2565 | - $result .= sprintf("Content-Type: %s; charset=\"%s\"", |
|---|
| 2566 | - $this->ContentType, $this->CharSet); |
|---|
| 2567 | - break; |
|---|
| 2568 | - case "attachments": |
|---|
| 2569 | - // fall through |
|---|
| 2570 | - case "alt_attachments": |
|---|
| 2571 | - if($this->InlineImageExists()) |
|---|
| 2572 | - { |
|---|
| 2573 | - $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", |
|---|
| 2574 | - "multipart/related", $this->LE, $this->LE, |
|---|
| 2575 | - $this->boundary[1], $this->LE); |
|---|
| 2576 | - } |
|---|
| 2577 | - else |
|---|
| 2578 | - { |
|---|
| 2579 | - $result .= $this->HeaderLine("Content-Type", "multipart/mixed;"); |
|---|
| 2580 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|---|
| 2581 | - } |
|---|
| 2582 | - break; |
|---|
| 2583 | - case "alt": |
|---|
| 2584 | - $result .= $this->HeaderLine("Content-Type", "multipart/alternative;"); |
|---|
| 2585 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|---|
| 2586 | - break; |
|---|
| 2587 | - } |
|---|
| 2588 | + /* To be created automatically by mail() */ |
|---|
| 2589 | + if($this->Mailer != 'mail') { |
|---|
| 2590 | + if(count($this->to) > 0) { |
|---|
| 2591 | + $result .= $this->AddrAppend('To', $this->to); |
|---|
| 2592 | + } elseif (count($this->cc) == 0) { |
|---|
| 2593 | + $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|---|
| 2594 | + } |
|---|
| 2595 | + if(count($this->cc) > 0) { |
|---|
| 2596 | + $result .= $this->AddrAppend('Cc', $this->cc); |
|---|
| 2597 | + } |
|---|
| 2598 | + } |
|---|
| 2599 | |
|---|
| 2600 | - if($this->Mailer != "mail") |
|---|
| 2601 | - $result .= $this->LE.$this->LE; |
|---|
| 2602 | + $from = array(); |
|---|
| 2603 | + $from[0][0] = trim($this->From); |
|---|
| 2604 | + $from[0][1] = $this->FromName; |
|---|
| 2605 | + $result .= $this->AddrAppend('From', $from); |
|---|
| 2606 | |
|---|
| 2607 | - return $result; |
|---|
| 2608 | + /* sendmail and mail() extract Cc from the header before sending */ |
|---|
| 2609 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) { |
|---|
| 2610 | + $result .= $this->AddrAppend('Cc', $this->cc); |
|---|
| 2611 | } |
|---|
| 2612 | |
|---|
| 2613 | - /** |
|---|
| 2614 | - * Assembles the message body. Returns an empty string on failure. |
|---|
| 2615 | - * @access private |
|---|
| 2616 | - * @return string |
|---|
| 2617 | - */ |
|---|
| 2618 | - function CreateBody() { |
|---|
| 2619 | - $result = ""; |
|---|
| 2620 | + /* sendmail and mail() extract Bcc from the header before sending */ |
|---|
| 2621 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|---|
| 2622 | + $result .= $this->AddrAppend('Bcc', $this->bcc); |
|---|
| 2623 | + } |
|---|
| 2624 | |
|---|
| 2625 | - $this->SetWordWrap(); |
|---|
| 2626 | + if(count($this->ReplyTo) > 0) { |
|---|
| 2627 | + $result .= $this->AddrAppend('Reply-To', $this->ReplyTo); |
|---|
| 2628 | + } |
|---|
| 2629 | |
|---|
| 2630 | - switch($this->message_type) |
|---|
| 2631 | - { |
|---|
| 2632 | - case "alt": |
|---|
| 2633 | - $result .= $this->GetBoundary($this->boundary[1], "", |
|---|
| 2634 | - "text/plain", ""); |
|---|
| 2635 | - $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|---|
| 2636 | - $result .= $this->LE.$this->LE; |
|---|
| 2637 | - $result .= $this->GetBoundary($this->boundary[1], "", |
|---|
| 2638 | - "text/html", ""); |
|---|
| 2639 | + /* mail() sets the subject itself */ |
|---|
| 2640 | + if($this->Mailer != 'mail') { |
|---|
| 2641 | + $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|---|
| 2642 | + } |
|---|
| 2643 | |
|---|
| 2644 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2645 | - $result .= $this->LE.$this->LE; |
|---|
| 2646 | + if($this->MessageID != '') { |
|---|
| 2647 | + $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|---|
| 2648 | + } else { |
|---|
| 2649 | + $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|---|
| 2650 | + } |
|---|
| 2651 | + $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|---|
| 2652 | + $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']'); |
|---|
| 2653 | |
|---|
| 2654 | - $result .= $this->EndBoundary($this->boundary[1]); |
|---|
| 2655 | - break; |
|---|
| 2656 | - case "plain": |
|---|
| 2657 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2658 | - break; |
|---|
| 2659 | - case "attachments": |
|---|
| 2660 | - $result .= $this->GetBoundary($this->boundary[1], "", "", ""); |
|---|
| 2661 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2662 | - $result .= $this->LE; |
|---|
| 2663 | + if($this->ConfirmReadingTo != '') { |
|---|
| 2664 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|---|
| 2665 | + } |
|---|
| 2666 | |
|---|
| 2667 | - $result .= $this->AttachAll(); |
|---|
| 2668 | - break; |
|---|
| 2669 | - case "alt_attachments": |
|---|
| 2670 | - $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|---|
| 2671 | - $result .= sprintf("Content-Type: %s;%s" . |
|---|
| 2672 | - "\tboundary=\"%s\"%s", |
|---|
| 2673 | - "multipart/alternative", $this->LE, |
|---|
| 2674 | - $this->boundary[2], $this->LE.$this->LE); |
|---|
| 2675 | + // Add custom headers |
|---|
| 2676 | + for($index = 0; $index < count($this->CustomHeader); $index++) { |
|---|
| 2677 | + $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|---|
| 2678 | + } |
|---|
| 2679 | + if (!$this->sign_key_file) { |
|---|
| 2680 | + $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|---|
| 2681 | + $result .= $this->GetMailMIME(); |
|---|
| 2682 | + } |
|---|
| 2683 | |
|---|
| 2684 | - // Create text body |
|---|
| 2685 | - $result .= $this->GetBoundary($this->boundary[2], "", |
|---|
| 2686 | - "text/plain", "") . $this->LE; |
|---|
| 2687 | + return $result; |
|---|
| 2688 | + } |
|---|
| 2689 | |
|---|
| 2690 | - $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|---|
| 2691 | - $result .= $this->LE.$this->LE; |
|---|
| 2692 | + /** |
|---|
| 2693 | + * Returns the message MIME. |
|---|
| 2694 | + * @access private |
|---|
| 2695 | + * @return string |
|---|
| 2696 | + */ |
|---|
| 2697 | + function GetMailMIME() { |
|---|
| 2698 | + $result = ''; |
|---|
| 2699 | + switch($this->message_type) { |
|---|
| 2700 | + case 'plain': |
|---|
| 2701 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|---|
| 2702 | + $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|---|
| 2703 | + break; |
|---|
| 2704 | + case 'attachments': |
|---|
| 2705 | + /* fall through */ |
|---|
| 2706 | + case 'alt_attachments': |
|---|
| 2707 | + if($this->InlineImageExists()){ |
|---|
| 2708 | + $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|---|
| 2709 | + } else { |
|---|
| 2710 | + $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|---|
| 2711 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|---|
| 2712 | + } |
|---|
| 2713 | + break; |
|---|
| 2714 | + case 'alt': |
|---|
| 2715 | + $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|---|
| 2716 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|---|
| 2717 | + break; |
|---|
| 2718 | + } |
|---|
| 2719 | |
|---|
| 2720 | - // Create the HTML body |
|---|
| 2721 | - $result .= $this->GetBoundary($this->boundary[2], "", |
|---|
| 2722 | - "text/html", "") . $this->LE; |
|---|
| 2723 | + if($this->Mailer != 'mail') { |
|---|
| 2724 | + $result .= $this->LE.$this->LE; |
|---|
| 2725 | + } |
|---|
| 2726 | |
|---|
| 2727 | - $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2728 | - $result .= $this->LE.$this->LE; |
|---|
| 2729 | + return $result; |
|---|
| 2730 | + } |
|---|
| 2731 | |
|---|
| 2732 | - $result .= $this->EndBoundary($this->boundary[2]); |
|---|
| 2733 | + /** |
|---|
| 2734 | + * Assembles the message body. Returns an empty string on failure. |
|---|
| 2735 | + * @access private |
|---|
| 2736 | + * @return string |
|---|
| 2737 | + */ |
|---|
| 2738 | + function CreateBody() { |
|---|
| 2739 | + $result = ''; |
|---|
| 2740 | + if ($this->sign_key_file) { |
|---|
| 2741 | + $result .= $this->GetMailMIME(); |
|---|
| 2742 | + } |
|---|
| 2743 | |
|---|
| 2744 | - $result .= $this->AttachAll(); |
|---|
| 2745 | - break; |
|---|
| 2746 | - } |
|---|
| 2747 | - if($this->IsError()) |
|---|
| 2748 | - $result = ""; |
|---|
| 2749 | + $this->SetWordWrap(); |
|---|
| 2750 | |
|---|
| 2751 | - return $result; |
|---|
| 2752 | + switch($this->message_type) { |
|---|
| 2753 | + case 'alt': |
|---|
| 2754 | + $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|---|
| 2755 | + $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|---|
| 2756 | + $result .= $this->LE.$this->LE; |
|---|
| 2757 | + $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|---|
| 2758 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2759 | + $result .= $this->LE.$this->LE; |
|---|
| 2760 | + $result .= $this->EndBoundary($this->boundary[1]); |
|---|
| 2761 | + break; |
|---|
| 2762 | + case 'plain': |
|---|
| 2763 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2764 | + break; |
|---|
| 2765 | + case 'attachments': |
|---|
| 2766 | + $result .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|---|
| 2767 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2768 | + $result .= $this->LE; |
|---|
| 2769 | + $result .= $this->AttachAll(); |
|---|
| 2770 | + break; |
|---|
| 2771 | + case 'alt_attachments': |
|---|
| 2772 | + $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|---|
| 2773 | + $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|---|
| 2774 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|---|
| 2775 | + $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
|---|
| 2776 | + $result .= $this->LE.$this->LE; |
|---|
| 2777 | + $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|---|
| 2778 | + $result .= $this->EncodeString($this->Body, $this->Encoding); |
|---|
| 2779 | + $result .= $this->LE.$this->LE; |
|---|
| 2780 | + $result .= $this->EndBoundary($this->boundary[2]); |
|---|
| 2781 | + $result .= $this->AttachAll(); |
|---|
| 2782 | + break; |
|---|
| 2783 | } |
|---|
| 2784 | |
|---|
| 2785 | - /** |
|---|
| 2786 | - * Returns the start of a message boundary. |
|---|
| 2787 | - * @access private |
|---|
| 2788 | - */ |
|---|
| 2789 | - function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
|---|
| 2790 | - $result = ""; |
|---|
| 2791 | - if($charSet == "") { $charSet = $this->CharSet; } |
|---|
| 2792 | - if($contentType == "") { $contentType = $this->ContentType; } |
|---|
| 2793 | - if($encoding == "") { $encoding = $this->Encoding; } |
|---|
| 2794 | + if($this->IsError()) { |
|---|
| 2795 | + $result = ''; |
|---|
| 2796 | + } else if ($this->sign_key_file) { |
|---|
| 2797 | + $file = tempnam("", "mail"); |
|---|
| 2798 | + $fp = fopen($file, "w"); |
|---|
| 2799 | + fwrite($fp, $result); |
|---|
| 2800 | + fclose($fp); |
|---|
| 2801 | + $signed = tempnam("", "signed"); |
|---|
| 2802 | |
|---|
| 2803 | - $result .= $this->TextLine("--" . $boundary); |
|---|
| 2804 | - $result .= sprintf("Content-Type: %s; charset = \"%s\"", |
|---|
| 2805 | - $contentType, $charSet); |
|---|
| 2806 | - $result .= $this->LE; |
|---|
| 2807 | - $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding); |
|---|
| 2808 | - $result .= $this->LE; |
|---|
| 2809 | + if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) { |
|---|
| 2810 | + $fp = fopen($signed, "r"); |
|---|
| 2811 | + $result = fread($fp, filesize($this->sign_key_file)); |
|---|
| 2812 | + fclose($fp); |
|---|
| 2813 | + } else { |
|---|
| 2814 | + $this->SetError($this->Lang("signing").openssl_error_string()); |
|---|
| 2815 | + $result = ''; |
|---|
| 2816 | + } |
|---|
| 2817 | |
|---|
| 2818 | - return $result; |
|---|
| 2819 | + unlink($file); |
|---|
| 2820 | + unlink($signed); |
|---|
| 2821 | } |
|---|
| 2822 | |
|---|
| 2823 | - /** |
|---|
| 2824 | - * Returns the end of a message boundary. |
|---|
| 2825 | - * @access private |
|---|
| 2826 | - */ |
|---|
| 2827 | - function EndBoundary($boundary) { |
|---|
| 2828 | - return $this->LE . "--" . $boundary . "--" . $this->LE; |
|---|
| 2829 | - } |
|---|
| 2830 | + return $result; |
|---|
| 2831 | + } |
|---|
| 2832 | |
|---|
| 2833 | - /** |
|---|
| 2834 | - * Sets the message type. |
|---|
| 2835 | - * @access private |
|---|
| 2836 | - * @return void |
|---|
| 2837 | - */ |
|---|
| 2838 | - function SetMessageType() { |
|---|
| 2839 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) |
|---|
| 2840 | - $this->message_type = "plain"; |
|---|
| 2841 | - else |
|---|
| 2842 | - { |
|---|
| 2843 | - if(count($this->attachment) > 0) |
|---|
| 2844 | - $this->message_type = "attachments"; |
|---|
| 2845 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) |
|---|
| 2846 | - $this->message_type = "alt"; |
|---|
| 2847 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) |
|---|
| 2848 | - $this->message_type = "alt_attachments"; |
|---|
| 2849 | - } |
|---|
| 2850 | + /** |
|---|
| 2851 | + * Returns the start of a message boundary. |
|---|
| 2852 | + * @access private |
|---|
| 2853 | + */ |
|---|
| 2854 | + function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
|---|
| 2855 | + $result = ''; |
|---|
| 2856 | + if($charSet == '') { |
|---|
| 2857 | + $charSet = $this->CharSet; |
|---|
| 2858 | } |
|---|
| 2859 | - |
|---|
| 2860 | - /** |
|---|
| 2861 | - * Returns a formatted header line. |
|---|
| 2862 | - * @access private |
|---|
| 2863 | - * @return string |
|---|
| 2864 | - */ |
|---|
| 2865 | - function HeaderLine($name, $value) { |
|---|
| 2866 | - return $name . ": " . $value . $this->LE; |
|---|
| 2867 | + if($contentType == '') { |
|---|
| 2868 | + $contentType = $this->ContentType; |
|---|
| 2869 | } |
|---|
| 2870 | + if($encoding == '') { |
|---|
| 2871 | + $encoding = $this->Encoding; |
|---|
| 2872 | + } |
|---|
| 2873 | + $result .= $this->TextLine('--' . $boundary); |
|---|
| 2874 | + $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|---|
| 2875 | + $result .= $this->LE; |
|---|
| 2876 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|---|
| 2877 | + $result .= $this->LE; |
|---|
| 2878 | |
|---|
| 2879 | - /** |
|---|
| 2880 | - * Returns a formatted mail line. |
|---|
| 2881 | - * @access private |
|---|
| 2882 | - * @return string |
|---|
| 2883 | - */ |
|---|
| 2884 | - function TextLine($value) { |
|---|
| 2885 | - return $value . $this->LE; |
|---|
| 2886 | + return $result; |
|---|
| 2887 | + } |
|---|
| 2888 | + |
|---|
| 2889 | + /** |
|---|
| 2890 | + * Returns the end of a message boundary. |
|---|
| 2891 | + * @access private |
|---|
| 2892 | + */ |
|---|
| 2893 | + function EndBoundary($boundary) { |
|---|
| 2894 | + return $this->LE . '--' . $boundary . '--' . $this->LE; |
|---|
| 2895 | + } |
|---|
| 2896 | + |
|---|
| 2897 | + /** |
|---|
| 2898 | + * Sets the message type. |
|---|
| 2899 | + * @access private |
|---|
| 2900 | + * @return void |
|---|
| 2901 | + */ |
|---|
| 2902 | + function SetMessageType() { |
|---|
| 2903 | + if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|---|
| 2904 | + $this->message_type = 'plain'; |
|---|
| 2905 | + } else { |
|---|
| 2906 | + if(count($this->attachment) > 0) { |
|---|
| 2907 | + $this->message_type = 'attachments'; |
|---|
| 2908 | + } |
|---|
| 2909 | + if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|---|
| 2910 | + $this->message_type = 'alt'; |
|---|
| 2911 | + } |
|---|
| 2912 | + if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|---|
| 2913 | + $this->message_type = 'alt_attachments'; |
|---|
| 2914 | + } |
|---|
| 2915 | } |
|---|
| 2916 | + } |
|---|
| 2917 | |
|---|
| 2918 | - ///////////////////////////////////////////////// |
|---|
| 2919 | - // ATTACHMENT METHODS |
|---|
| 2920 | - ///////////////////////////////////////////////// |
|---|
| 2921 | + /* Returns a formatted header line. |
|---|
| 2922 | + * @access private |
|---|
| 2923 | + * @return string |
|---|
| 2924 | + */ |
|---|
| 2925 | + function HeaderLine($name, $value) { |
|---|
| 2926 | + return $name . ': ' . $value . $this->LE; |
|---|
| 2927 | + } |
|---|
| 2928 | |
|---|
| 2929 | - /** |
|---|
| 2930 | - * Adds an attachment from a path on the filesystem. |
|---|
| 2931 | - * Returns false if the file could not be found |
|---|
| 2932 | - * or accessed. |
|---|
| 2933 | - * @param string $path Path to the attachment. |
|---|
| 2934 | - * @param string $name Overrides the attachment name. |
|---|
| 2935 | - * @param string $encoding File encoding (see $Encoding). |
|---|
| 2936 | - * @param string $type File extension (MIME) type. |
|---|
| 2937 | - * @return bool |
|---|
| 2938 | - */ |
|---|
| 2939 | - function AddAttachment($path, $name = "", $encoding = "base64", |
|---|
| 2940 | - $type = "application/octet-stream") { |
|---|
| 2941 | - if(!@is_file($path)) |
|---|
| 2942 | - { |
|---|
| 2943 | - $this->SetError($this->Lang("file_access") . $path); |
|---|
| 2944 | - return false; |
|---|
| 2945 | - } |
|---|
| 2946 | + /** |
|---|
| 2947 | + * Returns a formatted mail line. |
|---|
| 2948 | + * @access private |
|---|
| 2949 | + * @return string |
|---|
| 2950 | + */ |
|---|
| 2951 | + function TextLine($value) { |
|---|
| 2952 | + return $value . $this->LE; |
|---|
| 2953 | + } |
|---|
| 2954 | |
|---|
| 2955 | - $filename = basename($path); |
|---|
| 2956 | - if($name == "") |
|---|
| 2957 | - $name = $filename; |
|---|
| 2958 | + ///////////////////////////////////////////////// |
|---|
| 2959 | + // CLASS METHODS, ATTACHMENTS |
|---|
| 2960 | + ///////////////////////////////////////////////// |
|---|
| 2961 | |
|---|
| 2962 | - $cur = count($this->attachment); |
|---|
| 2963 | - $this->attachment[$cur][0] = $path; |
|---|
| 2964 | - $this->attachment[$cur][1] = $filename; |
|---|
| 2965 | - $this->attachment[$cur][2] = $name; |
|---|
| 2966 | - $this->attachment[$cur][3] = $encoding; |
|---|
| 2967 | - $this->attachment[$cur][4] = $type; |
|---|
| 2968 | - $this->attachment[$cur][5] = false; // isStringAttachment |
|---|
| 2969 | - $this->attachment[$cur][6] = "attachment"; |
|---|
| 2970 | - $this->attachment[$cur][7] = 0; |
|---|
| 2971 | + /** |
|---|
| 2972 | + * Adds an attachment from a path on the filesystem. |
|---|
| 2973 | + * Returns false if the file could not be found |
|---|
| 2974 | + * or accessed. |
|---|
| 2975 | + * @param string $path Path to the attachment. |
|---|
| 2976 | + * @param string $name Overrides the attachment name. |
|---|
| 2977 | + * @param string $encoding File encoding (see $Encoding). |
|---|
| 2978 | + * @param string $type File extension (MIME) type. |
|---|
| 2979 | + * @return bool |
|---|
| 2980 | + */ |
|---|
| 2981 | + function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
|---|
| 2982 | + if(!@is_file($path)) { |
|---|
| 2983 | + $this->SetError($this->Lang('file_access') . $path); |
|---|
| 2984 | + return false; |
|---|
| 2985 | + } |
|---|
| 2986 | |
|---|
| 2987 | - return true; |
|---|
| 2988 | + $filename = basename($path); |
|---|
| 2989 | + if($name == '') { |
|---|
| 2990 | + $name = $filename; |
|---|
| 2991 | } |
|---|
| 2992 | |
|---|
| 2993 | - /** |
|---|
| 2994 | - * Attaches all fs, string, and binary attachments to the message. |
|---|
| 2995 | - * Returns an empty string on failure. |
|---|
| 2996 | - * @access private |
|---|
| 2997 | - * @return string |
|---|
| 2998 | - */ |
|---|
| 2999 | - function AttachAll() { |
|---|
| 3000 | - // Return text of body |
|---|
| 3001 | - $mime = array(); |
|---|
| 3002 | + $cur = count($this->attachment); |
|---|
| 3003 | + $this->attachment[$cur][0] = $path; |
|---|
| 3004 | + $this->attachment[$cur][1] = $filename; |
|---|
| 3005 | + $this->attachment[$cur][2] = $name; |
|---|
| 3006 | + $this->attachment[$cur][3] = $encoding; |
|---|
| 3007 | + $this->attachment[$cur][4] = $type; |
|---|
| 3008 | + $this->attachment[$cur][5] = false; // isStringAttachment |
|---|
| 3009 | + $this->attachment[$cur][6] = 'attachment'; |
|---|
| 3010 | + $this->attachment[$cur][7] = 0; |
|---|
| 3011 | |
|---|
| 3012 | - // Add all attachments |
|---|
| 3013 | - for($i = 0; $i < count($this->attachment); $i++) |
|---|
| 3014 | - { |
|---|
| 3015 | - // Check for string attachment |
|---|
| 3016 | - $bString = $this->attachment[$i][5]; |
|---|
| 3017 | - if ($bString) |
|---|
| 3018 | - $string = $this->attachment[$i][0]; |
|---|
| 3019 | - else |
|---|
| 3020 | - $path = $this->attachment[$i][0]; |
|---|
| 3021 | + return true; |
|---|
| 3022 | + } |
|---|
| 3023 | |
|---|
| 3024 | - $filename = $this->attachment[$i][1]; |
|---|
| 3025 | - $name = $this->attachment[$i][2]; |
|---|
| 3026 | - $encoding = $this->attachment[$i][3]; |
|---|
| 3027 | - $type = $this->attachment[$i][4]; |
|---|
| 3028 | - $disposition = $this->attachment[$i][6]; |
|---|
| 3029 | - $cid = $this->attachment[$i][7]; |
|---|
| 3030 | + /** |
|---|
| 3031 | + * Attaches all fs, string, and binary attachments to the message. |
|---|
| 3032 | + * Returns an empty string on failure. |
|---|
| 3033 | + * @access private |
|---|
| 3034 | + * @return string |
|---|
| 3035 | + */ |
|---|
| 3036 | + function AttachAll() { |
|---|
| 3037 | + /* Return text of body */ |
|---|
| 3038 | + $mime = array(); |
|---|
| 3039 | |
|---|
| 3040 | - $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|---|
| 3041 | - $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE); |
|---|
| 3042 | - $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|---|
| 3043 | + /* Add all attachments */ |
|---|
| 3044 | + for($i = 0; $i < count($this->attachment); $i++) { |
|---|
| 3045 | + /* Check for string attachment */ |
|---|
| 3046 | + $bString = $this->attachment[$i][5]; |
|---|
| 3047 | + if ($bString) { |
|---|
| 3048 | + $string = $this->attachment[$i][0]; |
|---|
| 3049 | + } else { |
|---|
| 3050 | + $path = $this->attachment[$i][0]; |
|---|
| 3051 | + } |
|---|
| 3052 | |
|---|
| 3053 | - if($disposition == "inline") |
|---|
| 3054 | - $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|---|
| 3055 | + $filename = $this->attachment[$i][1]; |
|---|
| 3056 | + $name = $this->attachment[$i][2]; |
|---|
| 3057 | + $encoding = $this->attachment[$i][3]; |
|---|
| 3058 | + $type = $this->attachment[$i][4]; |
|---|
| 3059 | + $disposition = $this->attachment[$i][6]; |
|---|
| 3060 | + $cid = $this->attachment[$i][7]; |
|---|
| 3061 | |
|---|
| 3062 | - $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", |
|---|
| 3063 | - $disposition, $name, $this->LE.$this->LE); |
|---|
| 3064 | + $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|---|
| 3065 | + $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE); |
|---|
| 3066 | + $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|---|
| 3067 | |
|---|
| 3068 | - // Encode as string attachment |
|---|
| 3069 | - if($bString) |
|---|
| 3070 | - { |
|---|
| 3071 | - $mime[] = $this->EncodeString($string, $encoding); |
|---|
| 3072 | - if($this->IsError()) { return ""; } |
|---|
| 3073 | - $mime[] = $this->LE.$this->LE; |
|---|
| 3074 | - } |
|---|
| 3075 | - else |
|---|
| 3076 | - { |
|---|
| 3077 | - $mime[] = $this->EncodeFile($path, $encoding); |
|---|
| 3078 | - if($this->IsError()) { return ""; } |
|---|
| 3079 | - $mime[] = $this->LE.$this->LE; |
|---|
| 3080 | - } |
|---|
| 3081 | - } |
|---|
| 3082 | + if($disposition == 'inline') { |
|---|
| 3083 | + $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|---|
| 3084 | + } |
|---|
| 3085 | |
|---|
| 3086 | - $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|---|
| 3087 | + $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE); |
|---|
| 3088 | |
|---|
| 3089 | - return join("", $mime); |
|---|
| 3090 | + /* Encode as string attachment */ |
|---|
| 3091 | + if($bString) { |
|---|
| 3092 | + $mime[] = $this->EncodeString($string, $encoding); |
|---|
| 3093 | + if($this->IsError()) { |
|---|
| 3094 | + return ''; |
|---|
| 3095 | + } |
|---|
| 3096 | + $mime[] = $this->LE.$this->LE; |
|---|
| 3097 | + } else { |
|---|
| 3098 | + $mime[] = $this->EncodeFile($path, $encoding); |
|---|
| 3099 | + if($this->IsError()) { |
|---|
| 3100 | + return ''; |
|---|
| 3101 | + } |
|---|
| 3102 | + $mime[] = $this->LE.$this->LE; |
|---|
| 3103 | + } |
|---|
| 3104 | } |
|---|
| 3105 | |
|---|
| 3106 | - /** |
|---|
| 3107 | - * Encodes attachment in requested format. Returns an |
|---|
| 3108 | - * empty string on failure. |
|---|
| 3109 | - * @access private |
|---|
| 3110 | - * @return string |
|---|
| 3111 | - */ |
|---|
| 3112 | - function EncodeFile ($path, $encoding = "base64") { |
|---|
| 3113 | - if(!@$fd = fopen($path, "rb")) |
|---|
| 3114 | - { |
|---|
| 3115 | - $this->SetError($this->Lang("file_open") . $path); |
|---|
| 3116 | - return ""; |
|---|
| 3117 | - } |
|---|
| 3118 | - $magic_quotes = get_magic_quotes_runtime(); |
|---|
| 3119 | - set_magic_quotes_runtime(0); |
|---|
| 3120 | - $file_buffer = fread($fd, filesize($path)); |
|---|
| 3121 | - $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|---|
| 3122 | - fclose($fd); |
|---|
| 3123 | - set_magic_quotes_runtime($magic_quotes); |
|---|
| 3124 | + $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|---|
| 3125 | |
|---|
| 3126 | - return $file_buffer; |
|---|
| 3127 | + return join('', $mime); |
|---|
| 3128 | + } |
|---|
| 3129 | + |
|---|
| 3130 | + /** |
|---|
| 3131 | + * Encodes attachment in requested format. Returns an |
|---|
| 3132 | + * empty string on failure. |
|---|
| 3133 | + * @access private |
|---|
| 3134 | + * @return string |
|---|
| 3135 | + */ |
|---|
| 3136 | + function EncodeFile ($path, $encoding = 'base64') { |
|---|
| 3137 | + if(!@$fd = fopen($path, 'rb')) { |
|---|
| 3138 | + $this->SetError($this->Lang('file_open') . $path); |
|---|
| 3139 | + return ''; |
|---|
| 3140 | } |
|---|
| 3141 | + $magic_quotes = get_magic_quotes_runtime(); |
|---|
| 3142 | + set_magic_quotes_runtime(0); |
|---|
| 3143 | + $file_buffer = fread($fd, filesize($path)); |
|---|
| 3144 | + $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|---|
| 3145 | + fclose($fd); |
|---|
| 3146 | + set_magic_quotes_runtime($magic_quotes); |
|---|
| 3147 | |
|---|
| 3148 | - /** |
|---|
| 3149 | - * Encodes string to requested format. Returns an |
|---|
| 3150 | - * empty string on failure. |
|---|
| 3151 | - * @access private |
|---|
| 3152 | - * @return string |
|---|
| 3153 | - */ |
|---|
| 3154 | - function EncodeString ($str, $encoding = "base64") { |
|---|
| 3155 | - $encoded = ""; |
|---|
| 3156 | - switch(strtolower($encoding)) { |
|---|
| 3157 | - case "base64": |
|---|
| 3158 | - // chunk_split is found in PHP >= 3.0.6 |
|---|
| 3159 | - $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|---|
| 3160 | - break; |
|---|
| 3161 | - case "7bit": |
|---|
| 3162 | - case "8bit": |
|---|
| 3163 | - $encoded = $this->FixEOL($str); |
|---|
| 3164 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|---|
| 3165 | - $encoded .= $this->LE; |
|---|
| 3166 | - break; |
|---|
| 3167 | - case "binary": |
|---|
| 3168 | - $encoded = $str; |
|---|
| 3169 | - break; |
|---|
| 3170 | - case "quoted-printable": |
|---|
| 3171 | - $encoded = $this->EncodeQP($str); |
|---|
| 3172 | - break; |
|---|
| 3173 | - default: |
|---|
| 3174 | - $this->SetError($this->Lang("encoding") . $encoding); |
|---|
| 3175 | - break; |
|---|
| 3176 | - } |
|---|
| 3177 | - return $encoded; |
|---|
| 3178 | + return $file_buffer; |
|---|
| 3179 | + } |
|---|
| 3180 | + |
|---|
| 3181 | + /** |
|---|
| 3182 | + * Encodes string to requested format. Returns an |
|---|
| 3183 | + * empty string on failure. |
|---|
| 3184 | + * @access private |
|---|
| 3185 | + * @return string |
|---|
| 3186 | + */ |
|---|
| 3187 | + function EncodeString ($str, $encoding = 'base64') { |
|---|
| 3188 | + $encoded = ''; |
|---|
| 3189 | + switch(strtolower($encoding)) { |
|---|
| 3190 | + case 'base64': |
|---|
| 3191 | + /* chunk_split is found in PHP >= 3.0.6 */ |
|---|
| 3192 | + $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|---|
| 3193 | + break; |
|---|
| 3194 | + case '7bit': |
|---|
| 3195 | + case '8bit': |
|---|
| 3196 | + $encoded = $this->FixEOL($str); |
|---|
| 3197 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|---|
| 3198 | + $encoded .= $this->LE; |
|---|
| 3199 | + break; |
|---|
| 3200 | + case 'binary': |
|---|
| 3201 | + $encoded = $str; |
|---|
| 3202 | + break; |
|---|
| 3203 | + case 'quoted-printable': |
|---|
| 3204 | + $encoded = $this->EncodeQP($str); |
|---|
| 3205 | + break; |
|---|
| 3206 | + default: |
|---|
| 3207 | + $this->SetError($this->Lang('encoding') . $encoding); |
|---|
| 3208 | + break; |
|---|
| 3209 | } |
|---|
| 3210 | + return $encoded; |
|---|
| 3211 | + } |
|---|
| 3212 | |
|---|
| 3213 | - /** |
|---|
| 3214 | - * Encode a header string to best of Q, B, quoted or none. |
|---|
| 3215 | - * @access private |
|---|
| 3216 | - * @return string |
|---|
| 3217 | - */ |
|---|
| 3218 | - function EncodeHeader ($str, $position = 'text') { |
|---|
| 3219 | - $x = 0; |
|---|
| 3220 | + /** |
|---|
| 3221 | + * Encode a header string to best of Q, B, quoted or none. |
|---|
| 3222 | + * @access private |
|---|
| 3223 | + * @return string |
|---|
| 3224 | + */ |
|---|
| 3225 | + function EncodeHeader ($str, $position = 'text') { |
|---|
| 3226 | + $x = 0; |
|---|
| 3227 | |
|---|
| 3228 | - switch (strtolower($position)) { |
|---|
| 3229 | - case 'phrase': |
|---|
| 3230 | - if (!preg_match('/[\200-\377]/', $str)) { |
|---|
| 3231 | - // Can't use addslashes as we don't know what value has magic_quotes_sybase. |
|---|
| 3232 | - $encoded = addcslashes($str, "\0..\37\177\\\""); |
|---|
| 3233 | - |
|---|
| 3234 | - if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) |
|---|
| 3235 | - return ($encoded); |
|---|
| 3236 | - else |
|---|
| 3237 | - return ("\"$encoded\""); |
|---|
| 3238 | + switch (strtolower($position)) { |
|---|
| 3239 | + case 'phrase': |
|---|
| 3240 | + if (!preg_match('/[\200-\377]/', $str)) { |
|---|
| 3241 | + /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */ |
|---|
| 3242 | + $encoded = addcslashes($str, "\0..\37\177\\\""); |
|---|
| 3243 | + if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|---|
| 3244 | + return ($encoded); |
|---|
| 3245 | + } else { |
|---|
| 3246 | + return ("\"$encoded\""); |
|---|
| 3247 | } |
|---|
| 3248 | - $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|---|
| 3249 | - break; |
|---|
| 3250 | - case 'comment': |
|---|
| 3251 | - $x = preg_match_all('/[()"]/', $str, $matches); |
|---|
| 3252 | - // Fall-through |
|---|
| 3253 | - case 'text': |
|---|
| 3254 | - default: |
|---|
| 3255 | - $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|---|
| 3256 | - break; |
|---|
| 3257 | - } |
|---|
| 3258 | + } |
|---|
| 3259 | + $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|---|
| 3260 | + break; |
|---|
| 3261 | + case 'comment': |
|---|
| 3262 | + $x = preg_match_all('/[()"]/', $str, $matches); |
|---|
| 3263 | + /* Fall-through */ |
|---|
| 3264 | + case 'text': |
|---|
| 3265 | + default: |
|---|
| 3266 | + $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|---|
| 3267 | + break; |
|---|
| 3268 | + } |
|---|
| 3269 | |
|---|
| 3270 | - if ($x == 0) |
|---|
| 3271 | - return ($str); |
|---|
| 3272 | + if ($x == 0) { |
|---|
| 3273 | + return ($str); |
|---|
| 3274 | + } |
|---|
| 3275 | |
|---|
| 3276 | - $maxlen = 75 - 7 - strlen($this->CharSet); |
|---|
| 3277 | - // Try to select the encoding which should produce the shortest output |
|---|
| 3278 | - if (strlen($str)/3 < $x) { |
|---|
| 3279 | - $encoding = 'B'; |
|---|
| 3280 | + $maxlen = 75 - 7 - strlen($this->CharSet); |
|---|
| 3281 | + /* Try to select the encoding which should produce the shortest output */ |
|---|
| 3282 | + if (strlen($str)/3 < $x) { |
|---|
| 3283 | + $encoding = 'B'; |
|---|
| 3284 | + if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|---|
| 3285 | + // Use a custom function which correctly encodes and wraps long |
|---|
| 3286 | + // multibyte strings without breaking lines within a character |
|---|
| 3287 | + $encoded = $this->Base64EncodeWrapMB($str); |
|---|
| 3288 | + } else { |
|---|
| 3289 | $encoded = base64_encode($str); |
|---|
| 3290 | $maxlen -= $maxlen % 4; |
|---|
| 3291 | $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|---|
| 3292 | - } else { |
|---|
| 3293 | - $encoding = 'Q'; |
|---|
| 3294 | - $encoded = $this->EncodeQ($str, $position); |
|---|
| 3295 | - $encoded = $this->WrapText($encoded, $maxlen, true); |
|---|
| 3296 | - $encoded = str_replace("=".$this->LE, "\n", trim($encoded)); |
|---|
| 3297 | } |
|---|
| 3298 | + } else { |
|---|
| 3299 | + $encoding = 'Q'; |
|---|
| 3300 | + $encoded = $this->EncodeQ($str, $position); |
|---|
| 3301 | + $encoded = $this->WrapText($encoded, $maxlen, true); |
|---|
| 3302 | + $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|---|
| 3303 | + } |
|---|
| 3304 | |
|---|
| 3305 | - $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|---|
| 3306 | - $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|---|
| 3307 | + $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|---|
| 3308 | + $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|---|
| 3309 | |
|---|
| 3310 | - return $encoded; |
|---|
| 3311 | + return $encoded; |
|---|
| 3312 | + } |
|---|
| 3313 | + |
|---|
| 3314 | + /** |
|---|
| 3315 | + * Checks if a string contains multibyte characters. |
|---|
| 3316 | + * @access private |
|---|
| 3317 | + * @param string $str multi-byte text to wrap encode |
|---|
| 3318 | + * @return bool |
|---|
| 3319 | + */ |
|---|
| 3320 | + function HasMultiBytes($str) { |
|---|
| 3321 | + if (function_exists('mb_strlen')) { |
|---|
| 3322 | + return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|---|
| 3323 | + } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|---|
| 3324 | + return False; |
|---|
| 3325 | } |
|---|
| 3326 | + } |
|---|
| 3327 | |
|---|
| 3328 | - /** |
|---|
| 3329 | - * Encode string to quoted-printable. |
|---|
| 3330 | - * @access private |
|---|
| 3331 | - * @return string |
|---|
| 3332 | - */ |
|---|
| 3333 | - function EncodeQP ($str) { |
|---|
| 3334 | - $encoded = $this->FixEOL($str); |
|---|
| 3335 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|---|
| 3336 | - $encoded .= $this->LE; |
|---|
| 3337 | + /** |
|---|
| 3338 | + * Correctly encodes and wraps long multibyte strings for mail headers |
|---|
| 3339 | + * without breaking lines within a character. |
|---|
| 3340 | + * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php |
|---|
| 3341 | + * @access private |
|---|
| 3342 | + * @param string $str multi-byte text to wrap encode |
|---|
| 3343 | + * @return string |
|---|
| 3344 | + */ |
|---|
| 3345 | + function Base64EncodeWrapMB($str) { |
|---|
| 3346 | + $start = "=?".$this->CharSet."?B?"; |
|---|
| 3347 | + $end = "?="; |
|---|
| 3348 | + $encoded = ""; |
|---|
| 3349 | |
|---|
| 3350 | - // Replace every high ascii, control and = characters |
|---|
| 3351 | - $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e', |
|---|
| 3352 | - "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3353 | - // Replace every spaces and tabs when it's the last character on a line |
|---|
| 3354 | - $encoded = preg_replace("/([\011\040])".$this->LE."/e", |
|---|
| 3355 | - "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded); |
|---|
| 3356 | + $mb_length = mb_strlen($str, $this->CharSet); |
|---|
| 3357 | + // Each line must have length <= 75, including $start and $end |
|---|
| 3358 | + $length = 75 - strlen($start) - strlen($end); |
|---|
| 3359 | + // Average multi-byte ratio |
|---|
| 3360 | + $ratio = $mb_length / strlen($str); |
|---|
| 3361 | + // Base64 has a 4:3 ratio |
|---|
| 3362 | + $offset = $avgLength = floor($length * $ratio * .75); |
|---|
| 3363 | |
|---|
| 3364 | - // Maximum line length of 76 characters before CRLF (74 + space + '=') |
|---|
| 3365 | - $encoded = $this->WrapText($encoded, 74, true); |
|---|
| 3366 | + for ($i = 0; $i < $mb_length; $i += $offset) { |
|---|
| 3367 | + $lookBack = 0; |
|---|
| 3368 | |
|---|
| 3369 | - return $encoded; |
|---|
| 3370 | + do { |
|---|
| 3371 | + $offset = $avgLength - $lookBack; |
|---|
| 3372 | + $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|---|
| 3373 | + $chunk = base64_encode($chunk); |
|---|
| 3374 | + $lookBack++; |
|---|
| 3375 | + } |
|---|
| 3376 | + while (strlen($chunk) > $length); |
|---|
| 3377 | + |
|---|
| 3378 | + $encoded .= $chunk . $this->LE; |
|---|
| 3379 | } |
|---|
| 3380 | |
|---|
| 3381 | - /** |
|---|
| 3382 | - * Encode string to q encoding. |
|---|
| 3383 | - * @access private |
|---|
| 3384 | - * @return string |
|---|
| 3385 | - */ |
|---|
| 3386 | - function EncodeQ ($str, $position = "text") { |
|---|
| 3387 | - // There should not be any EOL in the string |
|---|
| 3388 | - $encoded = preg_replace("[\r\n]", "", $str); |
|---|
| 3389 | + // Chomp the last linefeed |
|---|
| 3390 | + $encoded = substr($encoded, 0, -strlen($this->LE)); |
|---|
| 3391 | + return $encoded; |
|---|
| 3392 | + } |
|---|
| 3393 | |
|---|
| 3394 | - switch (strtolower($position)) { |
|---|
| 3395 | - case "phrase": |
|---|
| 3396 | - $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3397 | - break; |
|---|
| 3398 | - case "comment": |
|---|
| 3399 | - $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3400 | - case "text": |
|---|
| 3401 | - default: |
|---|
| 3402 | - // Replace every high ascii, control =, ? and _ characters |
|---|
| 3403 | - $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|---|
| 3404 | - "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3405 | - break; |
|---|
| 3406 | + /** |
|---|
| 3407 | + * Encode string to quoted-printable. |
|---|
| 3408 | + * @access private |
|---|
| 3409 | + * @return string |
|---|
| 3410 | + */ |
|---|
| 3411 | + function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) { |
|---|
| 3412 | + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|---|
| 3413 | + $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|---|
| 3414 | + $eol = "\r\n"; |
|---|
| 3415 | + $escape = '='; |
|---|
| 3416 | + $output = ''; |
|---|
| 3417 | + while( list(, $line) = each($lines) ) { |
|---|
| 3418 | + $linlen = strlen($line); |
|---|
| 3419 | + $newline = ''; |
|---|
| 3420 | + for($i = 0; $i < $linlen; $i++) { |
|---|
| 3421 | + $c = substr( $line, $i, 1 ); |
|---|
| 3422 | + $dec = ord( $c ); |
|---|
| 3423 | + if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|---|
| 3424 | + $c = '=2E'; |
|---|
| 3425 | } |
|---|
| 3426 | + if ( $dec == 32 ) { |
|---|
| 3427 | + if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|---|
| 3428 | + $c = '=20'; |
|---|
| 3429 | + } else if ( $space_conv ) { |
|---|
| 3430 | + $c = '=20'; |
|---|
| 3431 | + } |
|---|
| 3432 | + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|---|
| 3433 | + $h2 = floor($dec/16); |
|---|
| 3434 | + $h1 = floor($dec%16); |
|---|
| 3435 | + $c = $escape.$hex[$h2].$hex[$h1]; |
|---|
| 3436 | + } |
|---|
| 3437 | + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|---|
| 3438 | + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|---|
| 3439 | + $newline = ''; |
|---|
| 3440 | + // check if newline first character will be point or not |
|---|
| 3441 | + if ( $dec == 46 ) { |
|---|
| 3442 | + $c = '=2E'; |
|---|
| 3443 | + } |
|---|
| 3444 | + } |
|---|
| 3445 | + $newline .= $c; |
|---|
| 3446 | + } // end of for |
|---|
| 3447 | + $output .= $newline.$eol; |
|---|
| 3448 | + } // end of while |
|---|
| 3449 | + return trim($output); |
|---|
| 3450 | + } |
|---|
| 3451 | |
|---|
| 3452 | - // Replace every spaces to _ (more readable than =20) |
|---|
| 3453 | - $encoded = str_replace(" ", "_", $encoded); |
|---|
| 3454 | + /** |
|---|
| 3455 | + * Encode string to q encoding. |
|---|
| 3456 | + * @access private |
|---|
| 3457 | + * @return string |
|---|
| 3458 | + */ |
|---|
| 3459 | + function EncodeQ ($str, $position = 'text') { |
|---|
| 3460 | + /* There should not be any EOL in the string */ |
|---|
| 3461 | + $encoded = preg_replace("[\r\n]", '', $str); |
|---|
| 3462 | |
|---|
| 3463 | - return $encoded; |
|---|
| 3464 | + switch (strtolower($position)) { |
|---|
| 3465 | + case 'phrase': |
|---|
| 3466 | + $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3467 | + break; |
|---|
| 3468 | + case 'comment': |
|---|
| 3469 | + $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3470 | + case 'text': |
|---|
| 3471 | + default: |
|---|
| 3472 | + /* Replace every high ascii, control =, ? and _ characters */ |
|---|
| 3473 | + $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|---|
| 3474 | + "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|---|
| 3475 | + break; |
|---|
| 3476 | } |
|---|
| 3477 | |
|---|
| 3478 | - /** |
|---|
| 3479 | - * Adds a string or binary attachment (non-filesystem) to the list. |
|---|
| 3480 | - * This method can be used to attach ascii or binary data, |
|---|
| 3481 | - * such as a BLOB record from a database. |
|---|
| 3482 | - * @param string $string String attachment data. |
|---|
| 3483 | - * @param string $filename Name of the attachment. |
|---|
| 3484 | - * @param string $encoding File encoding (see $Encoding). |
|---|
| 3485 | - * @param string $type File extension (MIME) type. |
|---|
| 3486 | - * @return void |
|---|
| 3487 | - */ |
|---|
| 3488 | - function AddStringAttachment($string, $filename, $encoding = "base64", |
|---|
| 3489 | - $type = "application/octet-stream") { |
|---|
| 3490 | - // Append to $attachment array |
|---|
| 3491 | - $cur = count($this->attachment); |
|---|
| 3492 | - $this->attachment[$cur][0] = $string; |
|---|
| 3493 | - $this->attachment[$cur][1] = $filename; |
|---|
| 3494 | - $this->attachment[$cur][2] = $filename; |
|---|
| 3495 | - $this->attachment[$cur][3] = $encoding; |
|---|
| 3496 | - $this->attachment[$cur][4] = $type; |
|---|
| 3497 | - $this->attachment[$cur][5] = true; // isString |
|---|
| 3498 | - $this->attachment[$cur][6] = "attachment"; |
|---|
| 3499 | - $this->attachment[$cur][7] = 0; |
|---|
| 3500 | - } |
|---|
| 3501 | + /* Replace every spaces to _ (more readable than =20) */ |
|---|
| 3502 | + $encoded = str_replace(' ', '_', $encoded); |
|---|
| 3503 | |
|---|
| 3504 | - /** |
|---|
| 3505 | - * Adds an embedded attachment. This can include images, sounds, and |
|---|
| 3506 | - * just about any other document. Make sure to set the $type to an |
|---|
| 3507 | - * image type. For JPEG images use "image/jpeg" and for GIF images |
|---|
| 3508 | - * use "image/gif". |
|---|
| 3509 | - * @param string $path Path to the attachment. |
|---|
| 3510 | - * @param string $cid Content ID of the attachment. Use this to identify |
|---|
| 3511 | - * the Id for accessing the image in an HTML form. |
|---|
| 3512 | - * @param string $name Overrides the attachment name. |
|---|
| 3513 | - * @param string $encoding File encoding (see $Encoding). |
|---|
| 3514 | - * @param string $type File extension (MIME) type. |
|---|
| 3515 | - * @return bool |
|---|
| 3516 | - */ |
|---|
| 3517 | - function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", |
|---|
| 3518 | - $type = "application/octet-stream") { |
|---|
| 3519 | + return $encoded; |
|---|
| 3520 | + } |
|---|
| 3521 | |
|---|
| 3522 | - if(!@is_file($path)) |
|---|
| 3523 | - { |
|---|
| 3524 | - $this->SetError($this->Lang("file_access") . $path); |
|---|
| 3525 | - return false; |
|---|
| 3526 | - } |
|---|
| 3527 | + /** |
|---|
| 3528 | + * Adds a string or binary attachment (non-filesystem) to the list. |
|---|
| 3529 | + * This method can be used to attach ascii or binary data, |
|---|
| 3530 | + * such as a BLOB record from a database. |
|---|
| 3531 | + * @param string $string String attachment data. |
|---|
| 3532 | + * @param string $filename Name of the attachment. |
|---|
| 3533 | + * @param string $encoding File encoding (see $Encoding). |
|---|
| 3534 | + * @param string $type File extension (MIME) type. |
|---|
| 3535 | + * @return void |
|---|
| 3536 | + */ |
|---|
| 3537 | + function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { |
|---|
| 3538 | + /* Append to $attachment array */ |
|---|
| 3539 | + $cur = count($this->attachment); |
|---|
| 3540 | + $this->attachment[$cur][0] = $string; |
|---|
| 3541 | + $this->attachment[$cur][1] = $filename; |
|---|
| 3542 | + $this->attachment[$cur][2] = $filename; |
|---|
| 3543 | + $this->attachment[$cur][3] = $encoding; |
|---|
| 3544 | + $this->attachment[$cur][4] = $type; |
|---|
| 3545 | + $this->attachment[$cur][5] = true; // isString |
|---|
| 3546 | + $this->attachment[$cur][6] = 'attachment'; |
|---|
| 3547 | + $this->attachment[$cur][7] = 0; |
|---|
| 3548 | + } |
|---|
| 3549 | |
|---|
| 3550 | - $filename = basename($path); |
|---|
| 3551 | - if($name == "") |
|---|
| 3552 | - $name = $filename; |
|---|
| 3553 | + /** |
|---|
| 3554 | + * Adds an embedded attachment. This can include images, sounds, and |
|---|
| 3555 | + * just about any other document. Make sure to set the $type to an |
|---|
| 3556 | + * image type. For JPEG images use "image/jpeg" and for GIF images |
|---|
| 3557 | + * use "image/gif". |
|---|
| 3558 | + * @param string $path Path to the attachment. |
|---|
| 3559 | + * @param string $cid Content ID of the attachment. Use this to identify |
|---|
| 3560 | + * the Id for accessing the image in an HTML form. |
|---|
| 3561 | + * @param string $name Overrides the attachment name. |
|---|
| 3562 | + * @param string $encoding File encoding (see $Encoding). |
|---|
| 3563 | + * @param string $type File extension (MIME) type. |
|---|
| 3564 | + * @return bool |
|---|
| 3565 | + */ |
|---|
| 3566 | + function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
|---|
| 3567 | |
|---|
| 3568 | - // Append to $attachment array |
|---|
| 3569 | - $cur = count($this->attachment); |
|---|
| 3570 | - $this->attachment[$cur][0] = $path; |
|---|
| 3571 | - $this->attachment[$cur][1] = $filename; |
|---|
| 3572 | - $this->attachment[$cur][2] = $name; |
|---|
| 3573 | - $this->attachment[$cur][3] = $encoding; |
|---|
| 3574 | - $this->attachment[$cur][4] = $type; |
|---|
| 3575 | - $this->attachment[$cur][5] = false; // isStringAttachment |
|---|
| 3576 | - $this->attachment[$cur][6] = "inline"; |
|---|
| 3577 | - $this->attachment[$cur][7] = $cid; |
|---|
| 3578 | + if(!@is_file($path)) { |
|---|
| 3579 | + $this->SetError($this->Lang('file_access') . $path); |
|---|
| 3580 | + return false; |
|---|
| 3581 | + } |
|---|
| 3582 | |
|---|
| 3583 | - return true; |
|---|
| 3584 | + $filename = basename($path); |
|---|
| 3585 | + if($name == '') { |
|---|
| 3586 | + $name = $filename; |
|---|
| 3587 | } |
|---|
| 3588 | |
|---|
| 3589 | - /** |
|---|
| 3590 | - * Returns true if an inline attachment is present. |
|---|
| 3591 | - * @access private |
|---|
| 3592 | - * @return bool |
|---|
| 3593 | - */ |
|---|
| 3594 | - function InlineImageExists() { |
|---|
| 3595 | - $result = false; |
|---|
| 3596 | - for($i = 0; $i < count($this->attachment); $i++) |
|---|
| 3597 | - { |
|---|
| 3598 | - if($this->attachment[$i][6] == "inline") |
|---|
| 3599 | - { |
|---|
| 3600 | - $result = true; |
|---|
| 3601 | - break; |
|---|
| 3602 | - } |
|---|
| 3603 | - } |
|---|
| 3604 | + /* Append to $attachment array */ |
|---|
| 3605 | + $cur = count($this->attachment); |
|---|
| 3606 | + $this->attachment[$cur][0] = $path; |
|---|
| 3607 | + $this->attachment[$cur][1] = $filename; |
|---|
| 3608 | + $this->attachment[$cur][2] = $name; |
|---|
| 3609 | + $this->attachment[$cur][3] = $encoding; |
|---|
| 3610 | + $this->attachment[$cur][4] = $type; |
|---|
| 3611 | + $this->attachment[$cur][5] = false; |
|---|
| 3612 | + $this->attachment[$cur][6] = 'inline'; |
|---|
| 3613 | + $this->attachment[$cur][7] = $cid; |
|---|
| 3614 | |
|---|
| 3615 | - return $result; |
|---|
| 3616 | + return true; |
|---|
| 3617 | + } |
|---|
| 3618 | + |
|---|
| 3619 | + /** |
|---|
| 3620 | + * Returns true if an inline attachment is present. |
|---|
| 3621 | + * @access private |
|---|
| 3622 | + * @return bool |
|---|
| 3623 | + */ |
|---|
| 3624 | + function InlineImageExists() { |
|---|
| 3625 | + $result = false; |
|---|
| 3626 | + for($i = 0; $i < count($this->attachment); $i++) { |
|---|
| 3627 | + if($this->attachment[$i][6] == 'inline') { |
|---|
| 3628 | + $result = true; |
|---|
| 3629 | + break; |
|---|
| 3630 | + } |
|---|
| 3631 | } |
|---|
| 3632 | |
|---|
| 3633 | - ///////////////////////////////////////////////// |
|---|
| 3634 | - // MESSAGE RESET METHODS |
|---|
| 3635 | - ///////////////////////////////////////////////// |
|---|
| 3636 | + return $result; |
|---|
| 3637 | + } |
|---|
| 3638 | |
|---|
| 3639 | - /** |
|---|
| 3640 | - * Clears all recipients assigned in the TO array. Returns void. |
|---|
| 3641 | - * @return void |
|---|
| 3642 | - */ |
|---|
| 3643 | - function ClearAddresses() { |
|---|
| 3644 | - $this->to = array(); |
|---|
| 3645 | - } |
|---|
| 3646 | + ///////////////////////////////////////////////// |
|---|
| 3647 | + // CLASS METHODS, MESSAGE RESET |
|---|
| 3648 | + ///////////////////////////////////////////////// |
|---|
| 3649 | |
|---|
| 3650 | - /** |
|---|
| 3651 | - * Clears all recipients assigned in the CC array. Returns void. |
|---|
| 3652 | - * @return void |
|---|
| 3653 | - */ |
|---|
| 3654 | - function ClearCCs() { |
|---|
| 3655 | - $this->cc = array(); |
|---|
| 3656 | - } |
|---|
| 3657 | + /** |
|---|
| 3658 | + * Clears all recipients assigned in the TO array. Returns void. |
|---|
| 3659 | + * @return void |
|---|
| 3660 | + */ |
|---|
| 3661 | + function ClearAddresses() { |
|---|
| 3662 | + $this->to = array(); |
|---|
| 3663 | + } |
|---|
| 3664 | |
|---|
| 3665 | - /** |
|---|
| 3666 | - * Clears all recipients assigned in the BCC array. Returns void. |
|---|
| 3667 | - * @return void |
|---|
| 3668 | - */ |
|---|
| 3669 | - function ClearBCCs() { |
|---|
| 3670 | - $this->bcc = array(); |
|---|
| 3671 | - } |
|---|
| 3672 | + /** |
|---|
| 3673 | + * Clears all recipients assigned in the CC array. Returns void. |
|---|
| 3674 | + * @return void |
|---|
| 3675 | + */ |
|---|
| 3676 | + function ClearCCs() { |
|---|
| 3677 | + $this->cc = array(); |
|---|
| 3678 | + } |
|---|
| 3679 | |
|---|
| 3680 | - /** |
|---|
| 3681 | - * Clears all recipients assigned in the ReplyTo array. Returns void. |
|---|
| 3682 | - * @return void |
|---|
| 3683 | - */ |
|---|
| 3684 | - function ClearReplyTos() { |
|---|
| 3685 | - $this->ReplyTo = array(); |
|---|
| 3686 | - } |
|---|
| 3687 | + /** |
|---|
| 3688 | + * Clears all recipients assigned in the BCC array. Returns void. |
|---|
| 3689 | + * @return void |
|---|
| 3690 | + */ |
|---|
| 3691 | + function ClearBCCs() { |
|---|
| 3692 | + $this->bcc = array(); |
|---|
| 3693 | + } |
|---|
| 3694 | |
|---|
| 3695 | - /** |
|---|
| 3696 | - * Clears all recipients assigned in the TO, CC and BCC |
|---|
| 3697 | - * array. Returns void. |
|---|
| 3698 | - * @return void |
|---|
| 3699 | - */ |
|---|
| 3700 | - function ClearAllRecipients() { |
|---|
| 3701 | - $this->to = array(); |
|---|
| 3702 | - $this->cc = array(); |
|---|
| 3703 | - $this->bcc = array(); |
|---|
| 3704 | - } |
|---|
| 3705 | + /** |
|---|
| 3706 | + * Clears all recipients assigned in the ReplyTo array. Returns void. |
|---|
| 3707 | + * @return void |
|---|
| 3708 | + */ |
|---|
| 3709 | + function ClearReplyTos() { |
|---|
| 3710 | + $this->ReplyTo = array(); |
|---|
| 3711 | + } |
|---|
| 3712 | |
|---|
| 3713 | - /** |
|---|
| 3714 | - * Clears all previously set filesystem, string, and binary |
|---|
| 3715 | - * attachments. Returns void. |
|---|
| 3716 | - * @return void |
|---|
| 3717 | - */ |
|---|
| 3718 | - function ClearAttachments() { |
|---|
| 3719 | - $this->attachment = array(); |
|---|
| 3720 | - } |
|---|
| 3721 | + /** |
|---|
| 3722 | + * Clears all recipients assigned in the TO, CC and BCC |
|---|
| 3723 | + * array. Returns void. |
|---|
| 3724 | + * @return void |
|---|
| 3725 | + */ |
|---|
| 3726 | + function ClearAllRecipients() { |
|---|
| 3727 | + $this->to = array(); |
|---|
| 3728 | + $this->cc = array(); |
|---|
| 3729 | + $this->bcc = array(); |
|---|
| 3730 | + } |
|---|
| 3731 | |
|---|
| 3732 | - /** |
|---|
| 3733 | - * Clears all custom headers. Returns void. |
|---|
| 3734 | - * @return void |
|---|
| 3735 | - */ |
|---|
| 3736 | - function ClearCustomHeaders() { |
|---|
| 3737 | - $this->CustomHeader = array(); |
|---|
| 3738 | - } |
|---|
| 3739 | + /** |
|---|
| 3740 | + * Clears all previously set filesystem, string, and binary |
|---|
| 3741 | + * attachments. Returns void. |
|---|
| 3742 | + * @return void |
|---|
| 3743 | + */ |
|---|
| 3744 | + function ClearAttachments() { |
|---|
| 3745 | + $this->attachment = array(); |
|---|
| 3746 | + } |
|---|
| 3747 | |
|---|
| 3748 | + /** |
|---|
| 3749 | + * Clears all custom headers. Returns void. |
|---|
| 3750 | + * @return void |
|---|
| 3751 | + */ |
|---|
| 3752 | + function ClearCustomHeaders() { |
|---|
| 3753 | + $this->CustomHeader = array(); |
|---|
| 3754 | + } |
|---|
| 3755 | |
|---|
| 3756 | - ///////////////////////////////////////////////// |
|---|
| 3757 | - // MISCELLANEOUS METHODS |
|---|
| 3758 | - ///////////////////////////////////////////////// |
|---|
| 3759 | + ///////////////////////////////////////////////// |
|---|
| 3760 | + // CLASS METHODS, MISCELLANEOUS |
|---|
| 3761 | + ///////////////////////////////////////////////// |
|---|
| 3762 | |
|---|
| 3763 | - /** |
|---|
| 3764 | - * Adds the error message to the error container. |
|---|
| 3765 | - * Returns void. |
|---|
| 3766 | - * @access private |
|---|
| 3767 | - * @return void |
|---|
| 3768 | - */ |
|---|
| 3769 | - function SetError($msg) { |
|---|
| 3770 | - $this->error_count++; |
|---|
| 3771 | - $this->ErrorInfo = $msg; |
|---|
| 3772 | + /** |
|---|
| 3773 | + * Adds the error message to the error container. |
|---|
| 3774 | + * Returns void. |
|---|
| 3775 | + * @access private |
|---|
| 3776 | + * @return void |
|---|
| 3777 | + */ |
|---|
| 3778 | + function SetError($msg) { |
|---|
| 3779 | + $this->error_count++; |
|---|
| 3780 | + $this->ErrorInfo = $msg; |
|---|
| 3781 | + } |
|---|
| 3782 | + |
|---|
| 3783 | + /** |
|---|
| 3784 | + * Returns the proper RFC 822 formatted date. |
|---|
| 3785 | + * @access private |
|---|
| 3786 | + * @return string |
|---|
| 3787 | + */ |
|---|
| 3788 | + function RFCDate() { |
|---|
| 3789 | + $tz = date('Z'); |
|---|
| 3790 | + $tzs = ($tz < 0) ? '-' : '+'; |
|---|
| 3791 | + $tz = abs($tz); |
|---|
| 3792 | + $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|---|
| 3793 | + $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|---|
| 3794 | + |
|---|
| 3795 | + return $result; |
|---|
| 3796 | + } |
|---|
| 3797 | + |
|---|
| 3798 | + /** |
|---|
| 3799 | + * Returns the appropriate server variable. Should work with both |
|---|
| 3800 | + * PHP 4.1.0+ as well as older versions. Returns an empty string |
|---|
| 3801 | + * if nothing is found. |
|---|
| 3802 | + * @access private |
|---|
| 3803 | + * @return mixed |
|---|
| 3804 | + */ |
|---|
| 3805 | + function ServerVar($varName) { |
|---|
| 3806 | + global $HTTP_SERVER_VARS; |
|---|
| 3807 | + global $HTTP_ENV_VARS; |
|---|
| 3808 | + |
|---|
| 3809 | + if(!isset($_SERVER)) { |
|---|
| 3810 | + $_SERVER = $HTTP_SERVER_VARS; |
|---|
| 3811 | + if(!isset($_SERVER['REMOTE_ADDR'])) { |
|---|
| 3812 | + $_SERVER = $HTTP_ENV_VARS; // must be Apache |
|---|
| 3813 | + } |
|---|
| 3814 | } |
|---|
| 3815 | |
|---|
| 3816 | - /** |
|---|
| 3817 | - * Returns the proper RFC 822 formatted date. |
|---|
| 3818 | - * @access private |
|---|
| 3819 | - * @return string |
|---|
| 3820 | - */ |
|---|
| 3821 | - function RFCDate() { |
|---|
| 3822 | - $tz = date("Z"); |
|---|
| 3823 | - $tzs = ($tz < 0) ? "-" : "+"; |
|---|
| 3824 | - $tz = abs($tz); |
|---|
| 3825 | - $tz = ($tz/3600)*100 + ($tz%3600)/60; |
|---|
| 3826 | - $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz); |
|---|
| 3827 | + if(isset($_SERVER[$varName])) { |
|---|
| 3828 | + return $_SERVER[$varName]; |
|---|
| 3829 | + } else { |
|---|
| 3830 | + return ''; |
|---|
| 3831 | + } |
|---|
| 3832 | + } |
|---|
| 3833 | |
|---|
| 3834 | - return $result; |
|---|
| 3835 | + /** |
|---|
| 3836 | + * Returns the server hostname or 'localhost.localdomain' if unknown. |
|---|
| 3837 | + * @access private |
|---|
| 3838 | + * @return string |
|---|
| 3839 | + */ |
|---|
| 3840 | + function ServerHostname() { |
|---|
| 3841 | + if ($this->Hostname != '') { |
|---|
| 3842 | + $result = $this->Hostname; |
|---|
| 3843 | + } elseif ($this->ServerVar('SERVER_NAME') != '') { |
|---|
| 3844 | + $result = $this->ServerVar('SERVER_NAME'); |
|---|
| 3845 | + } else { |
|---|
| 3846 | + $result = 'localhost.localdomain'; |
|---|
| 3847 | } |
|---|
| 3848 | |
|---|
| 3849 | - /** |
|---|
| 3850 | - * Returns the appropriate server variable. Should work with both |
|---|
| 3851 | - * PHP 4.1.0+ as well as older versions. Returns an empty string |
|---|
| 3852 | - * if nothing is found. |
|---|
| 3853 | - * @access private |
|---|
| 3854 | - * @return mixed |
|---|
| 3855 | - */ |
|---|
| 3856 | - function ServerVar($varName) { |
|---|
| 3857 | - global $HTTP_SERVER_VARS; |
|---|
| 3858 | - global $HTTP_ENV_VARS; |
|---|
| 3859 | + return $result; |
|---|
| 3860 | + } |
|---|
| 3861 | |
|---|
| 3862 | - if(!isset($_SERVER)) |
|---|
| 3863 | - { |
|---|
| 3864 | - $_SERVER = $HTTP_SERVER_VARS; |
|---|
| 3865 | - if(!isset($_SERVER["REMOTE_ADDR"])) |
|---|
| 3866 | - $_SERVER = $HTTP_ENV_VARS; // must be Apache |
|---|
| 3867 | - } |
|---|
| 3868 | + /** |
|---|
| 3869 | + * Returns a message in the appropriate language. |
|---|
| 3870 | + * @access private |
|---|
| 3871 | + * @return string |
|---|
| 3872 | + */ |
|---|
| 3873 | + function Lang($key) { |
|---|
| 3874 | + if(count($this->language) < 1) { |
|---|
| 3875 | + $this->SetLanguage('en'); // set the default language |
|---|
| 3876 | + } |
|---|
| 3877 | |
|---|
| 3878 | - if(isset($_SERVER[$varName])) |
|---|
| 3879 | - return $_SERVER[$varName]; |
|---|
| 3880 | - else |
|---|
| 3881 | - return ""; |
|---|
| 3882 | + if(isset($this->language[$key])) { |
|---|
| 3883 | + return $this->language[$key]; |
|---|
| 3884 | + } else { |
|---|
| 3885 | + return 'Language string failed to load: ' . $key; |
|---|
| 3886 | } |
|---|
| 3887 | + } |
|---|
| 3888 | |
|---|
| 3889 | - /** |
|---|
| 3890 | - * Returns the server hostname or 'localhost.localdomain' if unknown. |
|---|
| 3891 | - * @access private |
|---|
| 3892 | - * @return string |
|---|
| 3893 | - */ |
|---|
| 3894 | - function ServerHostname() { |
|---|
| 3895 | - if ($this->Hostname != "") |
|---|
| 3896 | - $result = $this->Hostname; |
|---|
| 3897 | - elseif ($this->ServerVar('SERVER_NAME') != "") |
|---|
| 3898 | - $result = $this->ServerVar('SERVER_NAME'); |
|---|
| 3899 | - else |
|---|
| 3900 | - $result = "localhost.localdomain"; |
|---|
| 3901 | + /** |
|---|
| 3902 | + * Returns true if an error occurred. |
|---|
| 3903 | + * @return bool |
|---|
| 3904 | + */ |
|---|
| 3905 | + function IsError() { |
|---|
| 3906 | + return ($this->error_count > 0); |
|---|
| 3907 | + } |
|---|
| 3908 | |
|---|
| 3909 | - return $result; |
|---|
| 3910 | - } |
|---|
| 3911 | + /** |
|---|
| 3912 | + * Changes every end of line from CR or LF to CRLF. |
|---|
| 3913 | + * @access private |
|---|
| 3914 | + * @return string |
|---|
| 3915 | + */ |
|---|
| 3916 | + function FixEOL($str) { |
|---|
| 3917 | + $str = str_replace("\r\n", "\n", $str); |
|---|
| 3918 | + $str = str_replace("\r", "\n", $str); |
|---|
| 3919 | + $str = str_replace("\n", $this->LE, $str); |
|---|
| 3920 | + return $str; |
|---|
| 3921 | + } |
|---|
| 3922 | |
|---|
| 3923 | - /** |
|---|
| 3924 | - * Returns a message in the appropriate language. |
|---|
| 3925 | - * @access private |
|---|
| 3926 | - * @return string |
|---|
| 3927 | - */ |
|---|
| 3928 | - function Lang($key) { |
|---|
| 3929 | - if(count($this->language) < 1) |
|---|
| 3930 | - $this->SetLanguage("en"); // set the default language |
|---|
| 3931 | + /** |
|---|
| 3932 | + * Adds a custom header. |
|---|
| 3933 | + * @return void |
|---|
| 3934 | + */ |
|---|
| 3935 | + function AddCustomHeader($custom_header) { |
|---|
| 3936 | + $this->CustomHeader[] = explode(':', $custom_header, 2); |
|---|
| 3937 | + } |
|---|
| 3938 | |
|---|
| 3939 | - if(isset($this->language[$key])) |
|---|
| 3940 | - return $this->language[$key]; |
|---|
| 3941 | - else |
|---|
| 3942 | - return "Language string failed to load: " . $key; |
|---|
| 3943 | + /** |
|---|
| 3944 | + * Evaluates the message and returns modifications for inline images and backgrounds |
|---|
| 3945 | + * @access public |
|---|
| 3946 | + * @return $message |
|---|
| 3947 | + */ |
|---|
| 3948 | + function MsgHTML($message,$basedir='') { |
|---|
| 3949 | + preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|---|
| 3950 | + if(isset($images[2])) { |
|---|
| 3951 | + foreach($images[2] as $i => $url) { |
|---|
| 3952 | + // do not change urls for absolute images (thanks to corvuscorax) |
|---|
| 3953 | + if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) { |
|---|
| 3954 | + $filename = basename($url); |
|---|
| 3955 | + $directory = dirname($url); |
|---|
| 3956 | + ($directory == '.')?$directory='':''; |
|---|
| 3957 | + $cid = 'cid:' . md5($filename); |
|---|
| 3958 | + $fileParts = split("\.", $filename); |
|---|
| 3959 | + $ext = $fileParts[1]; |
|---|
| 3960 | + $mimeType = $this->_mime_types($ext); |
|---|
| 3961 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|---|
| 3962 | + if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; } |
|---|
| 3963 | + $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType); |
|---|
| 3964 | + if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|---|
| 3965 | + $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|---|
| 3966 | + } |
|---|
| 3967 | + } |
|---|
| 3968 | + } |
|---|
| 3969 | } |
|---|
| 3970 | + $this->IsHTML(true); |
|---|
| 3971 | + $this->Body = $message; |
|---|
| 3972 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|---|
| 3973 | + if ( !empty($textMsg) && empty($this->AltBody) ) { |
|---|
| 3974 | + $this->AltBody = $textMsg; |
|---|
| 3975 | + } |
|---|
| 3976 | + if ( empty($this->AltBody) ) { |
|---|
| 3977 | + $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n"; |
|---|
| 3978 | + } |
|---|
| 3979 | + } |
|---|
| 3980 | |
|---|
| 3981 | - /** |
|---|
| 3982 | - * Returns true if an error occurred. |
|---|
| 3983 | - * @return bool |
|---|
| 3984 | - */ |
|---|
| 3985 | - function IsError() { |
|---|
| 3986 | - return ($this->error_count > 0); |
|---|
| 3987 | + /** |
|---|
| 3988 | + * Gets the mime type of the embedded or inline image |
|---|
| 3989 | + * @access private |
|---|
| 3990 | + * @return mime type of ext |
|---|
| 3991 | + */ |
|---|
| 3992 | + function _mime_types($ext = '') { |
|---|
| 3993 | + $mimes = array( |
|---|
| 3994 | + 'hqx' => 'application/mac-binhex40', |
|---|
| 3995 | + 'cpt' => 'application/mac-compactpro', |
|---|
| 3996 | + 'doc' => 'application/msword', |
|---|
| 3997 | + 'bin' => 'application/macbinary', |
|---|
| 3998 | + 'dms' => 'application/octet-stream', |
|---|
| 3999 | + 'lha' => 'application/octet-stream', |
|---|
| 4000 | + 'lzh' => 'application/octet-stream', |
|---|
| 4001 | + 'exe' => 'application/octet-stream', |
|---|
| 4002 | + 'class' => 'application/octet-stream', |
|---|
| 4003 | + 'psd' => 'application/octet-stream', |
|---|
| 4004 | + 'so' => 'application/octet-stream', |
|---|
| 4005 | + 'sea' => 'application/octet-stream', |
|---|
| 4006 | + 'dll' => 'application/octet-stream', |
|---|
| 4007 | + 'oda' => 'application/oda', |
|---|
| 4008 | + 'pdf' => 'application/pdf', |
|---|
| 4009 | + 'ai' => 'application/postscript', |
|---|
| 4010 | + 'eps' => 'application/postscript', |
|---|
| 4011 | + 'ps' => 'application/postscript', |
|---|
| 4012 | + 'smi' => 'application/smil', |
|---|
| 4013 | + 'smil' => 'application/smil', |
|---|
| 4014 | + 'mif' => 'application/vnd.mif', |
|---|
| 4015 | + 'xls' => 'application/vnd.ms-excel', |
|---|
| 4016 | + 'ppt' => 'application/vnd.ms-powerpoint', |
|---|
| 4017 | + 'wbxml' => 'application/vnd.wap.wbxml', |
|---|
| 4018 | + 'wmlc' => 'application/vnd.wap.wmlc', |
|---|
| 4019 | + 'dcr' => 'application/x-director', |
|---|
| 4020 | + 'dir' => 'application/x-director', |
|---|
| 4021 | + 'dxr' => 'application/x-director', |
|---|
| 4022 | + 'dvi' => 'application/x-dvi', |
|---|
| 4023 | + 'gtar' => 'application/x-gtar', |
|---|
| 4024 | + 'php' => 'application/x-httpd-php', |
|---|
| 4025 | + 'php4' => 'application/x-httpd-php', |
|---|
| 4026 | + 'php3' => 'application/x-httpd-php', |
|---|
| 4027 | + 'phtml' => 'application/x-httpd-php', |
|---|
| 4028 | + 'phps' => 'application/x-httpd-php-source', |
|---|
| 4029 | + 'js' => 'application/x-javascript', |
|---|
| 4030 | + 'swf' => 'application/x-shockwave-flash', |
|---|
| 4031 | + 'sit' => 'application/x-stuffit', |
|---|
| 4032 | + 'tar' => 'application/x-tar', |
|---|
| 4033 | + 'tgz' => 'application/x-tar', |
|---|
| 4034 | + 'xhtml' => 'application/xhtml+xml', |
|---|
| 4035 | + 'xht' => 'application/xhtml+xml', |
|---|
| 4036 | + 'zip' => 'application/zip', |
|---|
| 4037 | + 'mid' => 'audio/midi', |
|---|
| 4038 | + 'midi' => 'audio/midi', |
|---|
| 4039 | + 'mpga' => 'audio/mpeg', |
|---|
| 4040 | + 'mp2' => 'audio/mpeg', |
|---|
| 4041 | + 'mp3' => 'audio/mpeg', |
|---|
| 4042 | + 'aif' => 'audio/x-aiff', |
|---|
| 4043 | + 'aiff' => 'audio/x-aiff', |
|---|
| 4044 | + 'aifc' => 'audio/x-aiff', |
|---|
| 4045 | + 'ram' => 'audio/x-pn-realaudio', |
|---|
| 4046 | + 'rm' => 'audio/x-pn-realaudio', |
|---|
| 4047 | + 'rpm' => 'audio/x-pn-realaudio-plugin', |
|---|
| 4048 | + 'ra' => 'audio/x-realaudio', |
|---|
| 4049 | + 'rv' => 'video/vnd.rn-realvideo', |
|---|
| 4050 | + 'wav' => 'audio/x-wav', |
|---|
| 4051 | + 'bmp' => 'image/bmp', |
|---|
| 4052 | + 'gif' => 'image/gif', |
|---|
| 4053 | + 'jpeg' => 'image/jpeg', |
|---|
| 4054 | + 'jpg' => 'image/jpeg', |
|---|
| 4055 | + 'jpe' => 'image/jpeg', |
|---|
| 4056 | + 'png' => 'image/png', |
|---|
| 4057 | + 'tiff' => 'image/tiff', |
|---|
| 4058 | + 'tif' => 'image/tiff', |
|---|
| 4059 | + 'css' => 'text/css', |
|---|
| 4060 | + 'html' => 'text/html', |
|---|
| 4061 | + 'htm' => 'text/html', |
|---|
| 4062 | + 'shtml' => 'text/html', |
|---|
| 4063 | + 'txt' => 'text/plain', |
|---|
| 4064 | + 'text' => 'text/plain', |
|---|
| 4065 | + 'log' => 'text/plain', |
|---|
| 4066 | + 'rtx' => 'text/richtext', |
|---|
| 4067 | + 'rtf' => 'text/rtf', |
|---|
| 4068 | + 'xml' => 'text/xml', |
|---|
| 4069 | + 'xsl' => 'text/xml', |
|---|
| 4070 | + 'mpeg' => 'video/mpeg', |
|---|
| 4071 | + 'mpg' => 'video/mpeg', |
|---|
| 4072 | + 'mpe' => 'video/mpeg', |
|---|
| 4073 | + 'qt' => 'video/quicktime', |
|---|
| 4074 | + 'mov' => 'video/quicktime', |
|---|
| 4075 | + 'avi' => 'video/x-msvideo', |
|---|
| 4076 | + 'movie' => 'video/x-sgi-movie', |
|---|
| 4077 | + 'doc' => 'application/msword', |
|---|
| 4078 | + 'word' => 'application/msword', |
|---|
| 4079 | + 'xl' => 'application/excel', |
|---|
| 4080 | + 'eml' => 'message/rfc822' |
|---|
| 4081 | + ); |
|---|
| 4082 | + return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|---|
| 4083 | + } |
|---|
| 4084 | + |
|---|
| 4085 | + /** |
|---|
| 4086 | + * Set (or reset) Class Objects (variables) |
|---|
| 4087 | + * |
|---|
| 4088 | + * Usage Example: |
|---|
| 4089 | + * $page->set('X-Priority', '3'); |
|---|
| 4090 | + * |
|---|
| 4091 | + * @access public |
|---|
| 4092 | + * @param string $name Parameter Name |
|---|
| 4093 | + * @param mixed $value Parameter Value |
|---|
| 4094 | + * NOTE: will not work with arrays, there are no arrays to set/reset |
|---|
| 4095 | + */ |
|---|
| 4096 | + function set ( $name, $value = '' ) { |
|---|
| 4097 | + if ( isset($this->$name) ) { |
|---|
| 4098 | + $this->$name = $value; |
|---|
| 4099 | + } else { |
|---|
| 4100 | + $this->SetError('Cannot set or reset variable ' . $name); |
|---|
| 4101 | + return false; |
|---|
| 4102 | } |
|---|
| 4103 | + } |
|---|
| 4104 | |
|---|
| 4105 | - /** |
|---|
| 4106 | - * Changes every end of line from CR or LF to CRLF. |
|---|
| 4107 | - * @access private |
|---|
| 4108 | - * @return string |
|---|
| 4109 | - */ |
|---|
| 4110 | - function FixEOL($str) { |
|---|
| 4111 | - $str = str_replace("\r\n", "\n", $str); |
|---|
| 4112 | - $str = str_replace("\r", "\n", $str); |
|---|
| 4113 | - $str = str_replace("\n", $this->LE, $str); |
|---|
| 4114 | - return $str; |
|---|
| 4115 | + /** |
|---|
| 4116 | + * Read a file from a supplied filename and return it. |
|---|
| 4117 | + * |
|---|
| 4118 | + * @access public |
|---|
| 4119 | + * @param string $filename Parameter File Name |
|---|
| 4120 | + */ |
|---|
| 4121 | + function getFile($filename) { |
|---|
| 4122 | + $return = ''; |
|---|
| 4123 | + if ($fp = fopen($filename, 'rb')) { |
|---|
| 4124 | + while (!feof($fp)) { |
|---|
| 4125 | + $return .= fread($fp, 1024); |
|---|
| 4126 | + } |
|---|
| 4127 | + fclose($fp); |
|---|
| 4128 | + return $return; |
|---|
| 4129 | + } else { |
|---|
| 4130 | + return false; |
|---|
| 4131 | } |
|---|
| 4132 | + } |
|---|
| 4133 | |
|---|
| 4134 | - /** |
|---|
| 4135 | - * Adds a custom header. |
|---|
| 4136 | - * @return void |
|---|
| 4137 | - */ |
|---|
| 4138 | - function AddCustomHeader($custom_header) { |
|---|
| 4139 | - $this->CustomHeader[] = explode(":", $custom_header, 2); |
|---|
| 4140 | - } |
|---|
| 4141 | + /** |
|---|
| 4142 | + * Strips newlines to prevent header injection. |
|---|
| 4143 | + * @access private |
|---|
| 4144 | + * @param string $str String |
|---|
| 4145 | + * @return string |
|---|
| 4146 | + */ |
|---|
| 4147 | + function SecureHeader($str) { |
|---|
| 4148 | + $str = trim($str); |
|---|
| 4149 | + $str = str_replace("\r", "", $str); |
|---|
| 4150 | + $str = str_replace("\n", "", $str); |
|---|
| 4151 | + return $str; |
|---|
| 4152 | + } |
|---|
| 4153 | + |
|---|
| 4154 | + /** |
|---|
| 4155 | + * Set the private key file and password to sign the message. |
|---|
| 4156 | + * |
|---|
| 4157 | + * @access public |
|---|
| 4158 | + * @param string $key_filename Parameter File Name |
|---|
| 4159 | + * @param string $key_pass Password for private key |
|---|
| 4160 | + */ |
|---|
| 4161 | + function Sign($key_filename, $key_pass) { |
|---|
| 4162 | + $this->sign_key_file = $key_filename; |
|---|
| 4163 | + $this->sign_key_pass = $key_pass; |
|---|
| 4164 | + } |
|---|
| 4165 | + |
|---|
| 4166 | } |
|---|
| 4167 | |
|---|
| 4168 | ?> |
|---|
| 4169 | Index: wp-includes/class-smtp.php |
|---|
| 4170 | =================================================================== |
|---|
| 4171 | --- wp-includes/class-smtp.php (revision 8571) |
|---|
| 4172 | +++ wp-includes/class-smtp.php (working copy) |
|---|
| 4173 | @@ -1,1043 +1,1060 @@ |
|---|
| 4174 | <?php |
|---|
| 4175 | -/** |
|---|
| 4176 | - * SMTP - PHP SMTP class |
|---|
| 4177 | - * |
|---|
| 4178 | - * Define an SMTP class that can be used to connect and communicate with any |
|---|
| 4179 | - * SMTP server. It implements all the SMTP functions defined in RFC821 except |
|---|
| 4180 | - * TURN. |
|---|
| 4181 | - * |
|---|
| 4182 | - * @version 1.02 |
|---|
| 4183 | - * @author Chris Ryan |
|---|
| 4184 | - * @license LGPL |
|---|
| 4185 | - * @package PHPMailer |
|---|
| 4186 | - */ |
|---|
| 4187 | +/*~ class.smtp.php |
|---|
| 4188 | +.---------------------------------------------------------------------------. |
|---|
| 4189 | +| Software: PHPMailer - PHP email class | |
|---|
| 4190 | +| Version: 2.0.2 | |
|---|
| 4191 | +| Contact: via sourceforge.net support pages (also www.codeworxtech.com) | |
|---|
| 4192 | +| Info: http://phpmailer.sourceforge.net | |
|---|
| 4193 | +| Support: http://sourceforge.net/projects/phpmailer/ | |
|---|
| 4194 | +| ------------------------------------------------------------------------- | |
|---|
| 4195 | +| Author: Andy Prevost (project admininistrator) | |
|---|
| 4196 | +| Author: Brent R. Matzelle (original founder) | |
|---|
| 4197 | +| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. | |
|---|
| 4198 | +| Copyright (c) 2001-2003, Brent R. Matzelle | |
|---|
| 4199 | +| ------------------------------------------------------------------------- | |
|---|
| 4200 | +| License: Distributed under the Lesser General Public License (LGPL) | |
|---|
| 4201 | +| http://www.gnu.org/copyleft/lesser.html | |
|---|
| 4202 | +| This program is distributed in the hope that it will be useful - WITHOUT | |
|---|
| 4203 | +| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
|---|
| 4204 | +| FITNESS FOR A PARTICULAR PURPOSE. | |
|---|
| 4205 | +| ------------------------------------------------------------------------- | |
|---|
| 4206 | +| We offer a number of paid services (www.codeworxtech.com): | |
|---|
| 4207 | +| - Web Hosting on highly optimized fast and secure servers | |
|---|
| 4208 | +| - Technology Consulting | |
|---|
| 4209 | +| - Oursourcing (highly qualified programmers and graphic designers) | |
|---|
| 4210 | +'---------------------------------------------------------------------------' |
|---|
| 4211 | |
|---|
| 4212 | /** |
|---|
| 4213 | * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP |
|---|
| 4214 | * commands except TURN which will always return a not implemented |
|---|
| 4215 | * error. SMTP also provides some utility methods for sending mail |
|---|
| 4216 | * to an SMTP server. |
|---|
| 4217 | - * |
|---|
| 4218 | * @package PHPMailer |
|---|
| 4219 | * @author Chris Ryan |
|---|
| 4220 | */ |
|---|
| 4221 | + |
|---|
| 4222 | class SMTP |
|---|
| 4223 | { |
|---|
| 4224 | - /** |
|---|
| 4225 | - * SMTP server port |
|---|
| 4226 | - * @var int |
|---|
| 4227 | - */ |
|---|
| 4228 | - var $SMTP_PORT = 25; |
|---|
| 4229 | + /** |
|---|
| 4230 | + * SMTP server port |
|---|
| 4231 | + * @var int |
|---|
| 4232 | + */ |
|---|
| 4233 | + var $SMTP_PORT = 25; |
|---|
| 4234 | |
|---|
| 4235 | - /** |
|---|
| 4236 | - * SMTP reply line ending |
|---|
| 4237 | - * @var string |
|---|
| 4238 | - */ |
|---|
| 4239 | - var $CRLF = "\r\n"; |
|---|
| 4240 | + /** |
|---|
| 4241 | + * SMTP reply line ending |
|---|
| 4242 | + * @var string |
|---|
| 4243 | + */ |
|---|
| 4244 | + var $CRLF = "\r\n"; |
|---|
| 4245 | |
|---|
| 4246 | - /** |
|---|
| 4247 | - * Sets whether debugging is turned on |
|---|
| 4248 | - * @var bool |
|---|
| 4249 | - */ |
|---|
| 4250 | - var $do_debug; # the level of debug to perform |
|---|
| 4251 | + /** |
|---|
| 4252 | + * Sets whether debugging is turned on |
|---|
| 4253 | + * @var bool |
|---|
| 4254 | + */ |
|---|
| 4255 | + var $do_debug; # the level of debug to perform |
|---|
| 4256 | |
|---|
| 4257 | - /**#@+ |
|---|
| 4258 | - * @access private |
|---|
| 4259 | - */ |
|---|
| 4260 | - var $smtp_conn; # the socket to the server |
|---|
| 4261 | - var $error; # error if any on the last call |
|---|
| 4262 | - var $helo_rply; # the reply the server sent to us for HELO |
|---|
| 4263 | - /**#@-*/ |
|---|
| 4264 | + /** |
|---|
| 4265 | + * Sets VERP use on/off (default is off) |
|---|
| 4266 | + * @var bool |
|---|
| 4267 | + */ |
|---|
| 4268 | + var $do_verp = false; |
|---|
| 4269 | |
|---|
| 4270 | - /** |
|---|
| 4271 | - * Initialize the class so that the data is in a known state. |
|---|
| 4272 | - * @access public |
|---|
| 4273 | - * @return void |
|---|
| 4274 | - */ |
|---|
| 4275 | - function SMTP() { |
|---|
| 4276 | - $this->smtp_conn = 0; |
|---|
| 4277 | - $this->error = null; |
|---|
| 4278 | - $this->helo_rply = null; |
|---|
| 4279 | + /**#@+ |
|---|
| 4280 | + * @access private |
|---|
| 4281 | + */ |
|---|
| 4282 | + var $smtp_conn; # the socket to the server |
|---|
| 4283 | + var $error; # error if any on the last call |
|---|
| 4284 | + var $helo_rply; # the reply the server sent to us for HELO |
|---|
| 4285 | + /**#@-*/ |
|---|
| 4286 | |
|---|
| 4287 | - $this->do_debug = 0; |
|---|
| 4288 | - } |
|---|
| 4289 | + /** |
|---|
| 4290 | + * Initialize the class so that the data is in a known state. |
|---|
| 4291 | + * @access public |
|---|
| 4292 | + * @return void |
|---|
| 4293 | + */ |
|---|
| 4294 | + function SMTP() { |
|---|
| 4295 | + $this->smtp_conn = 0; |
|---|
| 4296 | + $this->error = null; |
|---|
| 4297 | + $this->helo_rply = null; |
|---|
| 4298 | |
|---|
| 4299 | - /************************************************************* |
|---|
| 4300 | - * CONNECTION FUNCTIONS * |
|---|
| 4301 | - ***********************************************************/ |
|---|
| 4302 | + $this->do_debug = 0; |
|---|
| 4303 | + } |
|---|
| 4304 | |
|---|
| 4305 | - /** |
|---|
| 4306 | - * Connect to the server specified on the port specified. |
|---|
| 4307 | - * If the port is not specified use the default SMTP_PORT. |
|---|
| 4308 | - * If tval is specified then a connection will try and be |
|---|
| 4309 | - * established with the server for that number of seconds. |
|---|
| 4310 | - * If tval is not specified the default is 30 seconds to |
|---|
| 4311 | - * try on the connection. |
|---|
| 4312 | - * |
|---|
| 4313 | - * SMTP CODE SUCCESS: 220 |
|---|
| 4314 | - * SMTP CODE FAILURE: 421 |
|---|
| 4315 | - * @access public |
|---|
| 4316 | - * @return bool |
|---|
| 4317 | - */ |
|---|
| 4318 | - function Connect($host,$port=0,$tval=30) { |
|---|
| 4319 | - # set the error val to null so there is no confusion |
|---|
| 4320 | - $this->error = null; |
|---|
| 4321 | + /************************************************************* |
|---|
| 4322 | + * CONNECTION FUNCTIONS * |
|---|
| 4323 | + ***********************************************************/ |
|---|
| 4324 | |
|---|
| 4325 | - # make sure we are __not__ connected |
|---|
| 4326 | - if($this->connected()) { |
|---|
| 4327 | - # ok we are connected! what should we do? |
|---|
| 4328 | - # for now we will just give an error saying we |
|---|
| 4329 | - # are already connected |
|---|
| 4330 | - $this->error = |
|---|
| 4331 | - array("error" => "Already connected to a server"); |
|---|
| 4332 | - return false; |
|---|
| 4333 | - } |
|---|
| 4334 | + /** |
|---|
| 4335 | + * Connect to the server specified on the port specified. |
|---|
| 4336 | + * If the port is not specified use the default SMTP_PORT. |
|---|
| 4337 | + * If tval is specified then a connection will try and be |
|---|
| 4338 | + * established with the server for that number of seconds. |
|---|
| 4339 | + * If tval is not specified the default is 30 seconds to |
|---|
| 4340 | + * try on the connection. |
|---|
| 4341 | + * |
|---|
| 4342 | + * SMTP CODE SUCCESS: 220 |
|---|
| 4343 | + * SMTP CODE FAILURE: 421 |
|---|
| 4344 | + * @access public |
|---|
| 4345 | + * @return bool |
|---|
| 4346 | + */ |
|---|
| 4347 | + function Connect($host,$port=0,$tval=30) { |
|---|
| 4348 | + # set the error val to null so there is no confusion |
|---|
| 4349 | + $this->error = null; |
|---|
| 4350 | |
|---|
| 4351 | - if(empty($port)) { |
|---|
| 4352 | - $port = $this->SMTP_PORT; |
|---|
| 4353 | - } |
|---|
| 4354 | + # make sure we are __not__ connected |
|---|
| 4355 | + if($this->connected()) { |
|---|
| 4356 | + # ok we are connected! what should we do? |
|---|
| 4357 | + # for now we will just give an error saying we |
|---|
| 4358 | + # are already connected |
|---|
| 4359 | + $this->error = array("error" => "Already connected to a server"); |
|---|
| 4360 | + return false; |
|---|
| 4361 | + } |
|---|
| 4362 | |
|---|
| 4363 | - #connect to the smtp server |
|---|
| 4364 | - $this->smtp_conn = fsockopen($host, # the host of the server |
|---|
| 4365 | - $port, # the port to use |
|---|
| 4366 | - $errno, # error number if any |
|---|
| 4367 | - $errstr, # error message if any |
|---|
| 4368 | - $tval); # give up after ? secs |
|---|
| 4369 | - # verify we connected properly |
|---|
| 4370 | - if(empty($this->smtp_conn)) { |
|---|
| 4371 | - $this->error = array("error" => "Failed to connect to server", |
|---|
| 4372 | - "errno" => $errno, |
|---|
| 4373 | - "errstr" => $errstr); |
|---|
| 4374 | - if($this->do_debug >= 1) { |
|---|
| 4375 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4376 | - ": $errstr ($errno)" . $this->CRLF; |
|---|
| 4377 | - } |
|---|
| 4378 | - return false; |
|---|
| 4379 | - } |
|---|
| 4380 | + if(empty($port)) { |
|---|
| 4381 | + $port = $this->SMTP_PORT; |
|---|
| 4382 | + } |
|---|
| 4383 | |
|---|
| 4384 | - # sometimes the SMTP server takes a little longer to respond |
|---|
| 4385 | - # so we will give it a longer timeout for the first read |
|---|
| 4386 | - // Windows still does not have support for this timeout function |
|---|
| 4387 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|---|
| 4388 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|---|
| 4389 | + #connect to the smtp server |
|---|
| 4390 | + $this->smtp_conn = fsockopen($host, # the host of the server |
|---|
| 4391 | + $port, # the port to use |
|---|
| 4392 | + $errno, # error number if any |
|---|
| 4393 | + $errstr, # error message if any |
|---|
| 4394 | + $tval); # give up after ? secs |
|---|
| 4395 | + # verify we connected properly |
|---|
| 4396 | + if(empty($this->smtp_conn)) { |
|---|
| 4397 | + $this->error = array("error" => "Failed to connect to server", |
|---|
| 4398 | + "errno" => $errno, |
|---|
| 4399 | + "errstr" => $errstr); |
|---|
| 4400 | + if($this->do_debug >= 1) { |
|---|
| 4401 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4402 | + ": $errstr ($errno)" . $this->CRLF; |
|---|
| 4403 | + } |
|---|
| 4404 | + return false; |
|---|
| 4405 | + } |
|---|
| 4406 | |
|---|
| 4407 | - # get any announcement stuff |
|---|
| 4408 | - $announce = $this->get_lines(); |
|---|
| 4409 | + # sometimes the SMTP server takes a little longer to respond |
|---|
| 4410 | + # so we will give it a longer timeout for the first read |
|---|
| 4411 | + // Windows still does not have support for this timeout function |
|---|
| 4412 | + if(substr(PHP_OS, 0, 3) != "WIN") |
|---|
| 4413 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|---|
| 4414 | |
|---|
| 4415 | - # set the timeout of any socket functions at 1/10 of a second |
|---|
| 4416 | - //if(function_exists("socket_set_timeout")) |
|---|
| 4417 | - // socket_set_timeout($this->smtp_conn, 0, 100000); |
|---|
| 4418 | + # get any announcement stuff |
|---|
| 4419 | + $announce = $this->get_lines(); |
|---|
| 4420 | |
|---|
| 4421 | - if($this->do_debug >= 2) { |
|---|
| 4422 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|---|
| 4423 | - } |
|---|
| 4424 | + # set the timeout of any socket functions at 1/10 of a second |
|---|
| 4425 | + //if(function_exists("socket_set_timeout")) |
|---|
| 4426 | + // socket_set_timeout($this->smtp_conn, 0, 100000); |
|---|
| 4427 | |
|---|
| 4428 | - return true; |
|---|
| 4429 | + if($this->do_debug >= 2) { |
|---|
| 4430 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce; |
|---|
| 4431 | } |
|---|
| 4432 | |
|---|
| 4433 | - /** |
|---|
| 4434 | - * Performs SMTP authentication. Must be run after running the |
|---|
| 4435 | - * Hello() method. Returns true if successfully authenticated. |
|---|
| 4436 | - * @access public |
|---|
| 4437 | - * @return bool |
|---|
| 4438 | - */ |
|---|
| 4439 | - function Authenticate($username, $password) { |
|---|
| 4440 | - // Start authentication |
|---|
| 4441 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|---|
| 4442 | + return true; |
|---|
| 4443 | + } |
|---|
| 4444 | |
|---|
| 4445 | - $rply = $this->get_lines(); |
|---|
| 4446 | - $code = substr($rply,0,3); |
|---|
| 4447 | + /** |
|---|
| 4448 | + * Performs SMTP authentication. Must be run after running the |
|---|
| 4449 | + * Hello() method. Returns true if successfully authenticated. |
|---|
| 4450 | + * @access public |
|---|
| 4451 | + * @return bool |
|---|
| 4452 | + */ |
|---|
| 4453 | + function Authenticate($username, $password) { |
|---|
| 4454 | + // Start authentication |
|---|
| 4455 | + fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|---|
| 4456 | |
|---|
| 4457 | - if($code != 334) { |
|---|
| 4458 | - $this->error = |
|---|
| 4459 | - array("error" => "AUTH not accepted from server", |
|---|
| 4460 | - "smtp_code" => $code, |
|---|
| 4461 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4462 | - if($this->do_debug >= 1) { |
|---|
| 4463 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4464 | - ": " . $rply . $this->CRLF; |
|---|
| 4465 | - } |
|---|
| 4466 | - return false; |
|---|
| 4467 | - } |
|---|
| 4468 | + $rply = $this->get_lines(); |
|---|
| 4469 | + $code = substr($rply,0,3); |
|---|
| 4470 | |
|---|
| 4471 | - // Send encoded username |
|---|
| 4472 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|---|
| 4473 | + if($code != 334) { |
|---|
| 4474 | + $this->error = |
|---|
| 4475 | + array("error" => "AUTH not accepted from server", |
|---|
| 4476 | + "smtp_code" => $code, |
|---|
| 4477 | + "smtp_msg" => substr($rply,4)); |
|---|
| 4478 | + if($this->do_debug >= 1) { |
|---|
| 4479 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4480 | + ": " . $rply . $this->CRLF; |
|---|
| 4481 | + } |
|---|
| 4482 | + return false; |
|---|
| 4483 | + } |
|---|
| 4484 | |
|---|
| 4485 | - $rply = $this->get_lines(); |
|---|
| 4486 | - $code = substr($rply,0,3); |
|---|
| 4487 | + // Send encoded username |
|---|
| 4488 | + fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|---|
| 4489 | |
|---|
| 4490 | - if($code != 334) { |
|---|
| 4491 | - $this->error = |
|---|
| 4492 | - array("error" => "Username not accepted from server", |
|---|
| 4493 | - "smtp_code" => $code, |
|---|
| 4494 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4495 | - if($this->do_debug >= 1) { |
|---|
| 4496 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4497 | - ": " . $rply . $this->CRLF; |
|---|
| 4498 | - } |
|---|
| 4499 | - return false; |
|---|
| 4500 | - } |
|---|
| 4501 | + $rply = $this->get_lines(); |
|---|
| 4502 | + $code = substr($rply,0,3); |
|---|
| 4503 | |
|---|
| 4504 | - // Send encoded password |
|---|
| 4505 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|---|
| 4506 | + if($code != 334) { |
|---|
| 4507 | + $this->error = |
|---|
| 4508 | + array("error" => "Username not accepted from server", |
|---|
| 4509 | + "smtp_code" => $code, |
|---|
| 4510 | + "smtp_msg" => substr($rply,4)); |
|---|
| 4511 | + if($this->do_debug >= 1) { |
|---|
| 4512 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4513 | + ": " . $rply . $this->CRLF; |
|---|
| 4514 | + } |
|---|
| 4515 | + return false; |
|---|
| 4516 | + } |
|---|
| 4517 | |
|---|
| 4518 | - $rply = $this->get_lines(); |
|---|
| 4519 | - $code = substr($rply,0,3); |
|---|
| 4520 | + // Send encoded password |
|---|
| 4521 | + fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|---|
| 4522 | |
|---|
| 4523 | - if($code != 235) { |
|---|
| 4524 | - $this->error = |
|---|
| 4525 | - array("error" => "Password not accepted from server", |
|---|
| 4526 | - "smtp_code" => $code, |
|---|
| 4527 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4528 | - if($this->do_debug >= 1) { |
|---|
| 4529 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4530 | - ": " . $rply . $this->CRLF; |
|---|
| 4531 | - } |
|---|
| 4532 | - return false; |
|---|
| 4533 | - } |
|---|
| 4534 | + $rply = $this->get_lines(); |
|---|
| 4535 | + $code = substr($rply,0,3); |
|---|
| 4536 | |
|---|
| 4537 | - return true; |
|---|
| 4538 | + if($code != 235) { |
|---|
| 4539 | + $this->error = |
|---|
| 4540 | + array("error" => "Password not accepted from server", |
|---|
| 4541 | + "smtp_code" => $code, |
|---|
| 4542 | + "smtp_msg" => substr($rply,4)); |
|---|
| 4543 | + if($this->do_debug >= 1) { |
|---|
| 4544 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4545 | + ": " . $rply . $this->CRLF; |
|---|
| 4546 | + } |
|---|
| 4547 | + return false; |
|---|
| 4548 | } |
|---|
| 4549 | |
|---|
| 4550 | - /** |
|---|
| 4551 | - * Returns true if connected to a server otherwise false |
|---|
| 4552 | - * @access private |
|---|
| 4553 | - * @return bool |
|---|
| 4554 | - */ |
|---|
| 4555 | - function Connected() { |
|---|
| 4556 | - if(!empty($this->smtp_conn)) { |
|---|
| 4557 | - $sock_status = socket_get_status($this->smtp_conn); |
|---|
| 4558 | - if($sock_status["eof"]) { |
|---|
| 4559 | - # hmm this is an odd situation... the socket is |
|---|
| 4560 | - # valid but we aren't connected anymore |
|---|
| 4561 | - if($this->do_debug >= 1) { |
|---|
| 4562 | - echo "SMTP -> NOTICE:" . $this->CRLF . |
|---|
| 4563 | - "EOF caught while checking if connected"; |
|---|
| 4564 | - } |
|---|
| 4565 | - $this->Close(); |
|---|
| 4566 | - return false; |
|---|
| 4567 | - } |
|---|
| 4568 | - return true; # everything looks good |
|---|
| 4569 | + return true; |
|---|
| 4570 | + } |
|---|
| 4571 | + |
|---|
| 4572 | + /** |
|---|
| 4573 | + * Returns true if connected to a server otherwise false |
|---|
| 4574 | + * @access private |
|---|
| 4575 | + * @return bool |
|---|
| 4576 | + */ |
|---|
| 4577 | + function Connected() { |
|---|
| 4578 | + if(!empty($this->smtp_conn)) { |
|---|
| 4579 | + $sock_status = socket_get_status($this->smtp_conn); |
|---|
| 4580 | + if($sock_status["eof"]) { |
|---|
| 4581 | + # hmm this is an odd situation... the socket is |
|---|
| 4582 | + # valid but we are not connected anymore |
|---|
| 4583 | + if($this->do_debug >= 1) { |
|---|
| 4584 | + echo "SMTP -> NOTICE:" . $this->CRLF . |
|---|
| 4585 | + "EOF caught while checking if connected"; |
|---|
| 4586 | } |
|---|
| 4587 | + $this->Close(); |
|---|
| 4588 | return false; |
|---|
| 4589 | + } |
|---|
| 4590 | + return true; # everything looks good |
|---|
| 4591 | } |
|---|
| 4592 | + return false; |
|---|
| 4593 | + } |
|---|
| 4594 | |
|---|
| 4595 | - /** |
|---|
| 4596 | - * Closes the socket and cleans up the state of the class. |
|---|
| 4597 | - * It is not considered good to use this function without |
|---|
| 4598 | - * first trying to use QUIT. |
|---|
| 4599 | - * @access public |
|---|
| 4600 | - * @return void |
|---|
| 4601 | - */ |
|---|
| 4602 | - function Close() { |
|---|
| 4603 | - $this->error = null; # so there is no confusion |
|---|
| 4604 | - $this->helo_rply = null; |
|---|
| 4605 | - if(!empty($this->smtp_conn)) { |
|---|
| 4606 | - # close the connection and cleanup |
|---|
| 4607 | - fclose($this->smtp_conn); |
|---|
| 4608 | - $this->smtp_conn = 0; |
|---|
| 4609 | - } |
|---|
| 4610 | + /** |
|---|
| 4611 | + * Closes the socket and cleans up the state of the class. |
|---|
| 4612 | + * It is not considered good to use this function without |
|---|
| 4613 | + * first trying to use QUIT. |
|---|
| 4614 | + * @access public |
|---|
| 4615 | + * @return void |
|---|
| 4616 | + */ |
|---|
| 4617 | + function Close() { |
|---|
| 4618 | + $this->error = null; # so there is no confusion |
|---|
| 4619 | + $this->helo_rply = null; |
|---|
| 4620 | + if(!empty($this->smtp_conn)) { |
|---|
| 4621 | + # close the connection and cleanup |
|---|
| 4622 | + fclose($this->smtp_conn); |
|---|
| 4623 | + $this->smtp_conn = 0; |
|---|
| 4624 | } |
|---|
| 4625 | + } |
|---|
| 4626 | |
|---|
| 4627 | + /*************************************************************** |
|---|
| 4628 | + * SMTP COMMANDS * |
|---|
| 4629 | + *************************************************************/ |
|---|
| 4630 | |
|---|
| 4631 | - /*************************************************************** |
|---|
| 4632 | - * SMTP COMMANDS * |
|---|
| 4633 | - *************************************************************/ |
|---|
| 4634 | + /** |
|---|
| 4635 | + * Issues a data command and sends the msg_data to the server |
|---|
| 4636 | + * finializing the mail transaction. $msg_data is the message |
|---|
| 4637 | + * that is to be send with the headers. Each header needs to be |
|---|
| 4638 | + * on a single line followed by a <CRLF> with the message headers |
|---|
| 4639 | + * and the message body being seperated by and additional <CRLF>. |
|---|
| 4640 | + * |
|---|
| 4641 | + * Implements rfc 821: DATA <CRLF> |
|---|
| 4642 | + * |
|---|
| 4643 | + * SMTP CODE INTERMEDIATE: 354 |
|---|
| 4644 | + * [data] |
|---|
| 4645 | + * <CRLF>.<CRLF> |
|---|
| 4646 | + * SMTP CODE SUCCESS: 250 |
|---|
| 4647 | + * SMTP CODE FAILURE: 552,554,451,452 |
|---|
| 4648 | + * SMTP CODE FAILURE: 451,554 |
|---|
| 4649 | + * SMTP CODE ERROR : 500,501,503,421 |
|---|
| 4650 | + * @access public |
|---|
| 4651 | + * @return bool |
|---|
| 4652 | + */ |
|---|
| 4653 | + function Data($msg_data) { |
|---|
| 4654 | + $this->error = null; # so no confusion is caused |
|---|
| 4655 | |
|---|
| 4656 | - /** |
|---|
| 4657 | - * Issues a data command and sends the msg_data to the server |
|---|
| 4658 | - * finializing the mail transaction. $msg_data is the message |
|---|
| 4659 | - * that is to be send with the headers. Each header needs to be |
|---|
| 4660 | - * on a single line followed by a <CRLF> with the message headers |
|---|
| 4661 | - * and the message body being separated by and additional <CRLF>. |
|---|
| 4662 | - * |
|---|
| 4663 | - * Implements rfc 821: DATA <CRLF> |
|---|
| 4664 | - * |
|---|
| 4665 | - * SMTP CODE INTERMEDIATE: 354 |
|---|
| 4666 | - * [data] |
|---|
| 4667 | - * <CRLF>.<CRLF> |
|---|
| 4668 | - * SMTP CODE SUCCESS: 250 |
|---|
| 4669 | - * SMTP CODE FAILURE: 552,554,451,452 |
|---|
| 4670 | - * SMTP CODE FAILURE: 451,554 |
|---|
| 4671 | - * SMTP CODE ERROR : 500,501,503,421 |
|---|
| 4672 | - * @access public |
|---|
| 4673 | - * @return bool |
|---|
| 4674 | - */ |
|---|
| 4675 | - function Data($msg_data) { |
|---|
| 4676 | - $this->error = null; # so no confusion is caused |
|---|
| 4677 | + if(!$this->connected()) { |
|---|
| 4678 | + $this->error = array( |
|---|
| 4679 | + "error" => "Called Data() without being connected"); |
|---|
| 4680 | + return false; |
|---|
| 4681 | + } |
|---|
| 4682 | |
|---|
| 4683 | - if(!$this->connected()) { |
|---|
| 4684 | - $this->error = array( |
|---|
| 4685 | - "error" => "Called Data() without being connected"); |
|---|
| 4686 | - return false; |
|---|
| 4687 | - } |
|---|
| 4688 | + fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|---|
| 4689 | |
|---|
| 4690 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|---|
| 4691 | + $rply = $this->get_lines(); |
|---|
| 4692 | + $code = substr($rply,0,3); |
|---|
| 4693 | |
|---|
| 4694 | - $rply = $this->get_lines(); |
|---|
| 4695 | - $code = substr($rply,0,3); |
|---|
| 4696 | + if($this->do_debug >= 2) { |
|---|
| 4697 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4698 | + } |
|---|
| 4699 | |
|---|
| 4700 | - if($this->do_debug >= 2) { |
|---|
| 4701 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4702 | - } |
|---|
| 4703 | + if($code != 354) { |
|---|
| 4704 | + $this->error = |
|---|
| 4705 | + array("error" => "DATA command not accepted from server", |
|---|
| 4706 | + "smtp_code" => $code, |
|---|
| 4707 | + "smtp_msg" => substr($rply,4)); |
|---|
| 4708 | + if($this->do_debug >= 1) { |
|---|
| 4709 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4710 | + ": " . $rply . $this->CRLF; |
|---|
| 4711 | + } |
|---|
| 4712 | + return false; |
|---|
| 4713 | + } |
|---|
| 4714 | |
|---|
| 4715 | - if($code != 354) { |
|---|
| 4716 | - $this->error = |
|---|
| 4717 | - array("error" => "DATA command not accepted from server", |
|---|
| 4718 | - "smtp_code" => $code, |
|---|
| 4719 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4720 | - if($this->do_debug >= 1) { |
|---|
| 4721 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4722 | - ": " . $rply . $this->CRLF; |
|---|
| 4723 | - } |
|---|
| 4724 | - return false; |
|---|
| 4725 | - } |
|---|
| 4726 | + # the server is ready to accept data! |
|---|
| 4727 | + # according to rfc 821 we should not send more than 1000 |
|---|
| 4728 | + # including the CRLF |
|---|
| 4729 | + # characters on a single line so we will break the data up |
|---|
| 4730 | + # into lines by \r and/or \n then if needed we will break |
|---|
| 4731 | + # each of those into smaller lines to fit within the limit. |
|---|
| 4732 | + # in addition we will be looking for lines that start with |
|---|
| 4733 | + # a period '.' and append and additional period '.' to that |
|---|
| 4734 | + # line. NOTE: this does not count towards are limit. |
|---|
| 4735 | |
|---|
| 4736 | - # the server is ready to accept data! |
|---|
| 4737 | - # according to rfc 821 we should not send more than 1000 |
|---|
| 4738 | - # including the CRLF |
|---|
| 4739 | - # characters on a single line so we will break the data up |
|---|
| 4740 | - # into lines by \r and/or \n then if needed we will break |
|---|
| 4741 | - # each of those into smaller lines to fit within the limit. |
|---|
| 4742 | - # in addition we will be looking for lines that start with |
|---|
| 4743 | - # a period '.' and append and additional period '.' to that |
|---|
| 4744 | - # line. NOTE: this does not count towards are limit. |
|---|
| 4745 | + # normalize the line breaks so we know the explode works |
|---|
| 4746 | + $msg_data = str_replace("\r\n","\n",$msg_data); |
|---|
| 4747 | + $msg_data = str_replace("\r","\n",$msg_data); |
|---|
| 4748 | + $lines = explode("\n",$msg_data); |
|---|
| 4749 | |
|---|
| 4750 | - # normalize the line breaks so we know the explode works |
|---|
| 4751 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|---|
| 4752 | - $msg_data = str_replace("\r","\n",$msg_data); |
|---|
| 4753 | - $lines = explode("\n",$msg_data); |
|---|
| 4754 | + # we need to find a good way to determine is headers are |
|---|
| 4755 | + # in the msg_data or if it is a straight msg body |
|---|
| 4756 | + # currently I am assuming rfc 822 definitions of msg headers |
|---|
| 4757 | + # and if the first field of the first line (':' sperated) |
|---|
| 4758 | + # does not contain a space then it _should_ be a header |
|---|
| 4759 | + # and we can process all lines before a blank "" line as |
|---|
| 4760 | + # headers. |
|---|
| 4761 | + $field = substr($lines[0],0,strpos($lines[0],":")); |
|---|
| 4762 | + $in_headers = false; |
|---|
| 4763 | + if(!empty($field) && !strstr($field," ")) { |
|---|
| 4764 | + $in_headers = true; |
|---|
| 4765 | + } |
|---|
| 4766 | |
|---|
| 4767 | - # we need to find a good way to determine is headers are |
|---|
| 4768 | - # in the msg_data or if it is a straight msg body |
|---|
| 4769 | - # currently I'm assuming rfc 822 definitions of msg headers |
|---|
| 4770 | - # and if the first field of the first line (':' sperated) |
|---|
| 4771 | - # does not contain a space then it _should_ be a header |
|---|
| 4772 | - # and we can process all lines before a blank "" line as |
|---|
| 4773 | - # headers. |
|---|
| 4774 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|---|
| 4775 | + $max_line_length = 998; # used below; set here for ease in change |
|---|
| 4776 | + |
|---|
| 4777 | + while(list(,$line) = @each($lines)) { |
|---|
| 4778 | + $lines_out = null; |
|---|
| 4779 | + if($line == "" && $in_headers) { |
|---|
| 4780 | $in_headers = false; |
|---|
| 4781 | - if(!empty($field) && !strstr($field," ")) { |
|---|
| 4782 | - $in_headers = true; |
|---|
| 4783 | - } |
|---|
| 4784 | + } |
|---|
| 4785 | + # ok we need to break this line up into several |
|---|
| 4786 | + # smaller lines |
|---|
| 4787 | + while(strlen($line) > $max_line_length) { |
|---|
| 4788 | + $pos = strrpos(substr($line,0,$max_line_length)," "); |
|---|
| 4789 | |
|---|
| 4790 | - $max_line_length = 998; # used below; set here for ease in change |
|---|
| 4791 | - |
|---|
| 4792 | - while(list(,$line) = @each($lines)) { |
|---|
| 4793 | - $lines_out = null; |
|---|
| 4794 | - if($line == "" && $in_headers) { |
|---|
| 4795 | - $in_headers = false; |
|---|
| 4796 | - } |
|---|
| 4797 | - # ok we need to break this line up into several |
|---|
| 4798 | - # smaller lines |
|---|
| 4799 | - while(strlen($line) > $max_line_length) { |
|---|
| 4800 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|---|
| 4801 | - |
|---|
| 4802 | - # Patch to fix DOS attack |
|---|
| 4803 | - if(!$pos) { |
|---|
| 4804 | - $pos = $max_line_length - 1; |
|---|
| 4805 | - } |
|---|
| 4806 | - |
|---|
| 4807 | - $lines_out[] = substr($line,0,$pos); |
|---|
| 4808 | - $line = substr($line,$pos + 1); |
|---|
| 4809 | - # if we are processing headers we need to |
|---|
| 4810 | - # add a LWSP-char to the front of the new line |
|---|
| 4811 | - # rfc 822 on long msg headers |
|---|
| 4812 | - if($in_headers) { |
|---|
| 4813 | - $line = "\t" . $line; |
|---|
| 4814 | - } |
|---|
| 4815 | - } |
|---|
| 4816 | - $lines_out[] = $line; |
|---|
| 4817 | - |
|---|
| 4818 | - # now send the lines to the server |
|---|
| 4819 | - while(list(,$line_out) = @each($lines_out)) { |
|---|
| 4820 | - if(strlen($line_out) > 0) |
|---|
| 4821 | - { |
|---|
| 4822 | - if(substr($line_out, 0, 1) == ".") { |
|---|
| 4823 | - $line_out = "." . $line_out; |
|---|
| 4824 | - } |
|---|
| 4825 | - } |
|---|
| 4826 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|---|
| 4827 | - } |
|---|
| 4828 | + # Patch to fix DOS attack |
|---|
| 4829 | + if(!$pos) { |
|---|
| 4830 | + $pos = $max_line_length - 1; |
|---|
| 4831 | } |
|---|
| 4832 | |
|---|
| 4833 | - # ok all the message data has been sent so lets get this |
|---|
| 4834 | - # over with aleady |
|---|
| 4835 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|---|
| 4836 | - |
|---|
| 4837 | - $rply = $this->get_lines(); |
|---|
| 4838 | - $code = substr($rply,0,3); |
|---|
| 4839 | - |
|---|
| 4840 | - if($this->do_debug >= 2) { |
|---|
| 4841 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4842 | + $lines_out[] = substr($line,0,$pos); |
|---|
| 4843 | + $line = substr($line,$pos + 1); |
|---|
| 4844 | + # if we are processing headers we need to |
|---|
| 4845 | + # add a LWSP-char to the front of the new line |
|---|
| 4846 | + # rfc 822 on long msg headers |
|---|
| 4847 | + if($in_headers) { |
|---|
| 4848 | + $line = "\t" . $line; |
|---|
| 4849 | } |
|---|
| 4850 | + } |
|---|
| 4851 | + $lines_out[] = $line; |
|---|
| 4852 | |
|---|
| 4853 | - if($code != 250) { |
|---|
| 4854 | - $this->error = |
|---|
| 4855 | - array("error" => "DATA not accepted from server", |
|---|
| 4856 | - "smtp_code" => $code, |
|---|
| 4857 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4858 | - if($this->do_debug >= 1) { |
|---|
| 4859 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4860 | - ": " . $rply . $this->CRLF; |
|---|
| 4861 | - } |
|---|
| 4862 | - return false; |
|---|
| 4863 | + # now send the lines to the server |
|---|
| 4864 | + while(list(,$line_out) = @each($lines_out)) { |
|---|
| 4865 | + if(strlen($line_out) > 0) |
|---|
| 4866 | + { |
|---|
| 4867 | + if(substr($line_out, 0, 1) == ".") { |
|---|
| 4868 | + $line_out = "." . $line_out; |
|---|
| 4869 | + } |
|---|
| 4870 | } |
|---|
| 4871 | - return true; |
|---|
| 4872 | + fputs($this->smtp_conn,$line_out . $this->CRLF); |
|---|
| 4873 | + } |
|---|
| 4874 | } |
|---|
| 4875 | |
|---|
| 4876 | - /** |
|---|
| 4877 | - * Expand takes the name and asks the server to list all the |
|---|
| 4878 | - * people who are members of the _list_. Expand will return |
|---|
| 4879 | - * back and array of the result or false if an error occurs. |
|---|
| 4880 | - * Each value in the array returned has the format of: |
|---|
| 4881 | - * [ <full-name> <sp> ] <path> |
|---|
| 4882 | - * The definition of <path> is defined in rfc 821 |
|---|
| 4883 | - * |
|---|
| 4884 | - * Implements rfc 821: EXPN <SP> <string> <CRLF> |
|---|
| 4885 | - * |
|---|
| 4886 | - * SMTP CODE SUCCESS: 250 |
|---|
| 4887 | - * SMTP CODE FAILURE: 550 |
|---|
| 4888 | - * SMTP CODE ERROR : 500,501,502,504,421 |
|---|
| 4889 | - * @access public |
|---|
| 4890 | - * @return string array |
|---|
| 4891 | - */ |
|---|
| 4892 | - function Expand($name) { |
|---|
| 4893 | - $this->error = null; # so no confusion is caused |
|---|
| 4894 | + # ok all the message data has been sent so lets get this |
|---|
| 4895 | + # over with aleady |
|---|
| 4896 | + fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|---|
| 4897 | |
|---|
| 4898 | - if(!$this->connected()) { |
|---|
| 4899 | - $this->error = array( |
|---|
| 4900 | - "error" => "Called Expand() without being connected"); |
|---|
| 4901 | - return false; |
|---|
| 4902 | - } |
|---|
| 4903 | + $rply = $this->get_lines(); |
|---|
| 4904 | + $code = substr($rply,0,3); |
|---|
| 4905 | |
|---|
| 4906 | - fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|---|
| 4907 | + if($this->do_debug >= 2) { |
|---|
| 4908 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4909 | + } |
|---|
| 4910 | |
|---|
| 4911 | - $rply = $this->get_lines(); |
|---|
| 4912 | - $code = substr($rply,0,3); |
|---|
| 4913 | + if($code != 250) { |
|---|
| 4914 | + $this->error = |
|---|
| 4915 | + array("error" => "DATA not accepted from server", |
|---|
| 4916 | + "smtp_code" => $code, |
|---|
| 4917 | + "smtp_msg" => substr($rply,4)); |
|---|
| 4918 | + if($this->do_debug >= 1) { |
|---|
| 4919 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4920 | + ": " . $rply . $this->CRLF; |
|---|
| 4921 | + } |
|---|
| 4922 | + return false; |
|---|
| 4923 | + } |
|---|
| 4924 | + return true; |
|---|
| 4925 | + } |
|---|
| 4926 | |
|---|
| 4927 | - if($this->do_debug >= 2) { |
|---|
| 4928 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4929 | - } |
|---|
| 4930 | + /** |
|---|
| 4931 | + * Expand takes the name and asks the server to list all the |
|---|
| 4932 | + * people who are members of the _list_. Expand will return |
|---|
| 4933 | + * back and array of the result or false if an error occurs. |
|---|
| 4934 | + * Each value in the array returned has the format of: |
|---|
| 4935 | + * [ <full-name> <sp> ] <path> |
|---|
| 4936 | + * The definition of <path> is defined in rfc 821 |
|---|
| 4937 | + * |
|---|
| 4938 | + * Implements rfc 821: EXPN <SP> <string> <CRLF> |
|---|
| 4939 | + * |
|---|
| 4940 | + * SMTP CODE SUCCESS: 250 |
|---|
| 4941 | + * SMTP CODE FAILURE: 550 |
|---|
| 4942 | + * SMTP CODE ERROR : 500,501,502,504,421 |
|---|
| 4943 | + * @access public |
|---|
| 4944 | + * @return string array |
|---|
| 4945 | + */ |
|---|
| 4946 | + function Expand($name) { |
|---|
| 4947 | + $this->error = null; # so no confusion is caused |
|---|
| 4948 | |
|---|
| 4949 | - if($code != 250) { |
|---|
| 4950 | - $this->error = |
|---|
| 4951 | - array("error" => "EXPN not accepted from server", |
|---|
| 4952 | - "smtp_code" => $code, |
|---|
| 4953 | - "smtp_msg" => substr($rply,4)); |
|---|
| 4954 | - if($this->do_debug >= 1) { |
|---|
| 4955 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 4956 | - ": " . $rply . $this->CRLF; |
|---|
| 4957 | - } |
|---|
| 4958 | - return false; |
|---|
| 4959 | - } |
|---|
| 4960 | + if(!$this->connected()) { |
|---|
| 4961 | + $this->error = array( |
|---|
| 4962 | + "error" => "Called Expand() without being connected"); |
|---|
| 4963 | + return false; |
|---|
| 4964 | + } |
|---|
| 4965 | |
|---|
| 4966 | - # parse the reply and place in our array to return to user |
|---|
| 4967 | - $entries = explode($this->CRLF,$rply); |
|---|
| 4968 | - while(list(,$l) = @each($entries)) { |
|---|
| 4969 | - $list[] = substr($l,4); |
|---|
| 4970 | - } |
|---|
| 4971 | + fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF); |
|---|
| 4972 | |
|---|
| 4973 | - return $list; |
|---|
| 4974 | + $rply = $this->get_lines(); |
|---|
| 4975 | + $code = substr($rply,0,3); |
|---|
| 4976 | + |
|---|
| 4977 | + if($this->do_debug >= 2) { |
|---|
| 4978 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 4979 | } |
|---|
| 4980 | |
|---|
| 4981 | - /** |
|---|
| 4982 | - * Sends the HELO command to the smtp server. |
|---|
| 4983 | - * This makes sure that we and the server are in |
|---|
| 4984 | - * the same known state. |
|---|
| 4985 | - * |
|---|
| 4986 | - * Implements from rfc 821: HELO <SP> <domain> <CRLF> |
|---|
| 4987 | - * |
|---|
| 4988 | - * SMTP CODE SUCCESS: 250 |
|---|
| 4989 | - * SMTP CODE ERROR : 500, 501, 504, 421 |
|---|
| 4990 | - * @access public |
|---|
| 4991 | - * @return bool |
|---|
| 4992 | - */ |
|---|
| 4993 | - function Hello($host="") { |
|---|
| 4994 | - $this->error = null; # so no confusion is caused |
|---|
| 4995 | + if($code != 250) { |
|---|
| 4996 | + $this->error = |
|---|
| 4997 | + array("error" => "EXPN not accepted from server", |
|---|
| 4998 | + "smtp_code" => $code, |
|---|
| 4999 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5000 | + if($this->do_debug >= 1) { |
|---|
| 5001 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5002 | + ": " . $rply . $this->CRLF; |
|---|
| 5003 | + } |
|---|
| 5004 | + return false; |
|---|
| 5005 | + } |
|---|
| 5006 | |
|---|
| 5007 | - if(!$this->connected()) { |
|---|
| 5008 | - $this->error = array( |
|---|
| 5009 | - "error" => "Called Hello() without being connected"); |
|---|
| 5010 | - return false; |
|---|
| 5011 | - } |
|---|
| 5012 | + # parse the reply and place in our array to return to user |
|---|
| 5013 | + $entries = explode($this->CRLF,$rply); |
|---|
| 5014 | + while(list(,$l) = @each($entries)) { |
|---|
| 5015 | + $list[] = substr($l,4); |
|---|
| 5016 | + } |
|---|
| 5017 | |
|---|
| 5018 | - # if a hostname for the HELO wasn't specified determine |
|---|
| 5019 | - # a suitable one to send |
|---|
| 5020 | - if(empty($host)) { |
|---|
| 5021 | - # we need to determine some sort of appopiate default |
|---|
| 5022 | - # to send to the server |
|---|
| 5023 | - $host = "localhost"; |
|---|
| 5024 | - } |
|---|
| 5025 | + return $list; |
|---|
| 5026 | + } |
|---|
| 5027 | |
|---|
| 5028 | - // Send extended hello first (RFC 2821) |
|---|
| 5029 | - if(!$this->SendHello("EHLO", $host)) |
|---|
| 5030 | - { |
|---|
| 5031 | - if(!$this->SendHello("HELO", $host)) |
|---|
| 5032 | - return false; |
|---|
| 5033 | - } |
|---|
| 5034 | + /** |
|---|
| 5035 | + * Sends the HELO command to the smtp server. |
|---|
| 5036 | + * This makes sure that we and the server are in |
|---|
| 5037 | + * the same known state. |
|---|
| 5038 | + * |
|---|
| 5039 | + * Implements from rfc 821: HELO <SP> <domain> <CRLF> |
|---|
| 5040 | + * |
|---|
| 5041 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5042 | + * SMTP CODE ERROR : 500, 501, 504, 421 |
|---|
| 5043 | + * @access public |
|---|
| 5044 | + * @return bool |
|---|
| 5045 | + */ |
|---|
| 5046 | + function Hello($host="") { |
|---|
| 5047 | + $this->error = null; # so no confusion is caused |
|---|
| 5048 | |
|---|
| 5049 | - return true; |
|---|
| 5050 | + if(!$this->connected()) { |
|---|
| 5051 | + $this->error = array( |
|---|
| 5052 | + "error" => "Called Hello() without being connected"); |
|---|
| 5053 | + return false; |
|---|
| 5054 | } |
|---|
| 5055 | |
|---|
| 5056 | - /** |
|---|
| 5057 | - * Sends a HELO/EHLO command. |
|---|
| 5058 | - * @access private |
|---|
| 5059 | - * @return bool |
|---|
| 5060 | - */ |
|---|
| 5061 | - function SendHello($hello, $host) { |
|---|
| 5062 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|---|
| 5063 | + # if a hostname for the HELO was not specified determine |
|---|
| 5064 | + # a suitable one to send |
|---|
| 5065 | + if(empty($host)) { |
|---|
| 5066 | + # we need to determine some sort of appopiate default |
|---|
| 5067 | + # to send to the server |
|---|
| 5068 | + $host = "localhost"; |
|---|
| 5069 | + } |
|---|
| 5070 | |
|---|
| 5071 | - $rply = $this->get_lines(); |
|---|
| 5072 | - $code = substr($rply,0,3); |
|---|
| 5073 | + // Send extended hello first (RFC 2821) |
|---|
| 5074 | + if(!$this->SendHello("EHLO", $host)) |
|---|
| 5075 | + { |
|---|
| 5076 | + if(!$this->SendHello("HELO", $host)) |
|---|
| 5077 | + return false; |
|---|
| 5078 | + } |
|---|
| 5079 | |
|---|
| 5080 | - if($this->do_debug >= 2) { |
|---|
| 5081 | - echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|---|
| 5082 | - } |
|---|
| 5083 | + return true; |
|---|
| 5084 | + } |
|---|
| 5085 | |
|---|
| 5086 | - if($code != 250) { |
|---|
| 5087 | - $this->error = |
|---|
| 5088 | - array("error" => $hello . " not accepted from server", |
|---|
| 5089 | - "smtp_code" => $code, |
|---|
| 5090 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5091 | - if($this->do_debug >= 1) { |
|---|
| 5092 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5093 | - ": " . $rply . $this->CRLF; |
|---|
| 5094 | - } |
|---|
| 5095 | - return false; |
|---|
| 5096 | - } |
|---|
| 5097 | + /** |
|---|
| 5098 | + * Sends a HELO/EHLO command. |
|---|
| 5099 | + * @access private |
|---|
| 5100 | + * @return bool |
|---|
| 5101 | + */ |
|---|
| 5102 | + function SendHello($hello, $host) { |
|---|
| 5103 | + fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|---|
| 5104 | |
|---|
| 5105 | - $this->helo_rply = $rply; |
|---|
| 5106 | + $rply = $this->get_lines(); |
|---|
| 5107 | + $code = substr($rply,0,3); |
|---|
| 5108 | |
|---|
| 5109 | - return true; |
|---|
| 5110 | + if($this->do_debug >= 2) { |
|---|
| 5111 | + echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply; |
|---|
| 5112 | } |
|---|
| 5113 | |
|---|
| 5114 | - /** |
|---|
| 5115 | - * Gets help information on the keyword specified. If the keyword |
|---|
| 5116 | - * is not specified then returns generic help, ussually contianing |
|---|
| 5117 | - * A list of keywords that help is available on. This function |
|---|
| 5118 | - * returns the results back to the user. It is up to the user to |
|---|
| 5119 | - * handle the returned data. If an error occurs then false is |
|---|
| 5120 | - * returned with $this->error set appropiately. |
|---|
| 5121 | - * |
|---|
| 5122 | - * Implements rfc 821: HELP [ <SP> <string> ] <CRLF> |
|---|
| 5123 | - * |
|---|
| 5124 | - * SMTP CODE SUCCESS: 211,214 |
|---|
| 5125 | - * SMTP CODE ERROR : 500,501,502,504,421 |
|---|
| 5126 | - * @access public |
|---|
| 5127 | - * @return string |
|---|
| 5128 | - */ |
|---|
| 5129 | - function Help($keyword="") { |
|---|
| 5130 | - $this->error = null; # to avoid confusion |
|---|
| 5131 | + if($code != 250) { |
|---|
| 5132 | + $this->error = |
|---|
| 5133 | + array("error" => $hello . " not accepted from server", |
|---|
| 5134 | + "smtp_code" => $code, |
|---|
| 5135 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5136 | + if($this->do_debug >= 1) { |
|---|
| 5137 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5138 | + ": " . $rply . $this->CRLF; |
|---|
| 5139 | + } |
|---|
| 5140 | + return false; |
|---|
| 5141 | + } |
|---|
| 5142 | |
|---|
| 5143 | - if(!$this->connected()) { |
|---|
| 5144 | - $this->error = array( |
|---|
| 5145 | - "error" => "Called Help() without being connected"); |
|---|
| 5146 | - return false; |
|---|
| 5147 | - } |
|---|
| 5148 | + $this->helo_rply = $rply; |
|---|
| 5149 | |
|---|
| 5150 | - $extra = ""; |
|---|
| 5151 | - if(!empty($keyword)) { |
|---|
| 5152 | - $extra = " " . $keyword; |
|---|
| 5153 | - } |
|---|
| 5154 | + return true; |
|---|
| 5155 | + } |
|---|
| 5156 | |
|---|
| 5157 | - fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|---|
| 5158 | + /** |
|---|
| 5159 | + * Gets help information on the keyword specified. If the keyword |
|---|
| 5160 | + * is not specified then returns generic help, ussually contianing |
|---|
| 5161 | + * A list of keywords that help is available on. This function |
|---|
| 5162 | + * returns the results back to the user. It is up to the user to |
|---|
| 5163 | + * handle the returned data. If an error occurs then false is |
|---|
| 5164 | + * returned with $this->error set appropiately. |
|---|
| 5165 | + * |
|---|
| 5166 | + * Implements rfc 821: HELP [ <SP> <string> ] <CRLF> |
|---|
| 5167 | + * |
|---|
| 5168 | + * SMTP CODE SUCCESS: 211,214 |
|---|
| 5169 | + * SMTP CODE ERROR : 500,501,502,504,421 |
|---|
| 5170 | + * @access public |
|---|
| 5171 | + * @return string |
|---|
| 5172 | + */ |
|---|
| 5173 | + function Help($keyword="") { |
|---|
| 5174 | + $this->error = null; # to avoid confusion |
|---|
| 5175 | |
|---|
| 5176 | - $rply = $this->get_lines(); |
|---|
| 5177 | - $code = substr($rply,0,3); |
|---|
| 5178 | + if(!$this->connected()) { |
|---|
| 5179 | + $this->error = array( |
|---|
| 5180 | + "error" => "Called Help() without being connected"); |
|---|
| 5181 | + return false; |
|---|
| 5182 | + } |
|---|
| 5183 | |
|---|
| 5184 | - if($this->do_debug >= 2) { |
|---|
| 5185 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5186 | - } |
|---|
| 5187 | + $extra = ""; |
|---|
| 5188 | + if(!empty($keyword)) { |
|---|
| 5189 | + $extra = " " . $keyword; |
|---|
| 5190 | + } |
|---|
| 5191 | |
|---|
| 5192 | - if($code != 211 && $code != 214) { |
|---|
| 5193 | - $this->error = |
|---|
| 5194 | - array("error" => "HELP not accepted from server", |
|---|
| 5195 | - "smtp_code" => $code, |
|---|
| 5196 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5197 | - if($this->do_debug >= 1) { |
|---|
| 5198 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5199 | - ": " . $rply . $this->CRLF; |
|---|
| 5200 | - } |
|---|
| 5201 | - return false; |
|---|
| 5202 | - } |
|---|
| 5203 | + fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF); |
|---|
| 5204 | |
|---|
| 5205 | - return $rply; |
|---|
| 5206 | + $rply = $this->get_lines(); |
|---|
| 5207 | + $code = substr($rply,0,3); |
|---|
| 5208 | + |
|---|
| 5209 | + if($this->do_debug >= 2) { |
|---|
| 5210 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5211 | } |
|---|
| 5212 | |
|---|
| 5213 | - /** |
|---|
| 5214 | - * Starts a mail transaction from the email address specified in |
|---|
| 5215 | - * $from. Returns true if successful or false otherwise. If True |
|---|
| 5216 | - * the mail transaction is started and then one or more Recipient |
|---|
| 5217 | - * commands may be called followed by a Data command. |
|---|
| 5218 | - * |
|---|
| 5219 | - * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5220 | - * |
|---|
| 5221 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5222 | - * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5223 | - * SMTP CODE SUCCESS: 500,501,421 |
|---|
| 5224 | - * @access public |
|---|
| 5225 | - * @return bool |
|---|
| 5226 | - */ |
|---|
| 5227 | - function Mail($from) { |
|---|
| 5228 | - $this->error = null; # so no confusion is caused |
|---|
| 5229 | + if($code != 211 && $code != 214) { |
|---|
| 5230 | + $this->error = |
|---|
| 5231 | + array("error" => "HELP not accepted from server", |
|---|
| 5232 | + "smtp_code" => $code, |
|---|
| 5233 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5234 | + if($this->do_debug >= 1) { |
|---|
| 5235 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5236 | + ": " . $rply . $this->CRLF; |
|---|
| 5237 | + } |
|---|
| 5238 | + return false; |
|---|
| 5239 | + } |
|---|
| 5240 | |
|---|
| 5241 | - if(!$this->connected()) { |
|---|
| 5242 | - $this->error = array( |
|---|
| 5243 | - "error" => "Called Mail() without being connected"); |
|---|
| 5244 | - return false; |
|---|
| 5245 | - } |
|---|
| 5246 | + return $rply; |
|---|
| 5247 | + } |
|---|
| 5248 | |
|---|
| 5249 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF); |
|---|
| 5250 | + /** |
|---|
| 5251 | + * Starts a mail transaction from the email address specified in |
|---|
| 5252 | + * $from. Returns true if successful or false otherwise. If True |
|---|
| 5253 | + * the mail transaction is started and then one or more Recipient |
|---|
| 5254 | + * commands may be called followed by a Data command. |
|---|
| 5255 | + * |
|---|
| 5256 | + * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5257 | + * |
|---|
| 5258 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5259 | + * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5260 | + * SMTP CODE SUCCESS: 500,501,421 |
|---|
| 5261 | + * @access public |
|---|
| 5262 | + * @return bool |
|---|
| 5263 | + */ |
|---|
| 5264 | + function Mail($from) { |
|---|
| 5265 | + $this->error = null; # so no confusion is caused |
|---|
| 5266 | |
|---|
| 5267 | - $rply = $this->get_lines(); |
|---|
| 5268 | - $code = substr($rply,0,3); |
|---|
| 5269 | + if(!$this->connected()) { |
|---|
| 5270 | + $this->error = array( |
|---|
| 5271 | + "error" => "Called Mail() without being connected"); |
|---|
| 5272 | + return false; |
|---|
| 5273 | + } |
|---|
| 5274 | |
|---|
| 5275 | - if($this->do_debug >= 2) { |
|---|
| 5276 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5277 | - } |
|---|
| 5278 | + $useVerp = ($this->do_verp ? "XVERP" : ""); |
|---|
| 5279 | + fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|---|
| 5280 | |
|---|
| 5281 | - if($code != 250) { |
|---|
| 5282 | - $this->error = |
|---|
| 5283 | - array("error" => "MAIL not accepted from server", |
|---|
| 5284 | - "smtp_code" => $code, |
|---|
| 5285 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5286 | - if($this->do_debug >= 1) { |
|---|
| 5287 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5288 | - ": " . $rply . $this->CRLF; |
|---|
| 5289 | - } |
|---|
| 5290 | - return false; |
|---|
| 5291 | - } |
|---|
| 5292 | - return true; |
|---|
| 5293 | + $rply = $this->get_lines(); |
|---|
| 5294 | + $code = substr($rply,0,3); |
|---|
| 5295 | + |
|---|
| 5296 | + if($this->do_debug >= 2) { |
|---|
| 5297 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5298 | } |
|---|
| 5299 | |
|---|
| 5300 | - /** |
|---|
| 5301 | - * Sends the command NOOP to the SMTP server. |
|---|
| 5302 | - * |
|---|
| 5303 | - * Implements from rfc 821: NOOP <CRLF> |
|---|
| 5304 | - * |
|---|
| 5305 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5306 | - * SMTP CODE ERROR : 500, 421 |
|---|
| 5307 | - * @access public |
|---|
| 5308 | - * @return bool |
|---|
| 5309 | - */ |
|---|
| 5310 | - function Noop() { |
|---|
| 5311 | - $this->error = null; # so no confusion is caused |
|---|
| 5312 | + if($code != 250) { |
|---|
| 5313 | + $this->error = |
|---|
| 5314 | + array("error" => "MAIL not accepted from server", |
|---|
| 5315 | + "smtp_code" => $code, |
|---|
| 5316 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5317 | + if($this->do_debug >= 1) { |
|---|
| 5318 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5319 | + ": " . $rply . $this->CRLF; |
|---|
| 5320 | + } |
|---|
| 5321 | + return false; |
|---|
| 5322 | + } |
|---|
| 5323 | + return true; |
|---|
| 5324 | + } |
|---|
| 5325 | |
|---|
| 5326 | - if(!$this->connected()) { |
|---|
| 5327 | - $this->error = array( |
|---|
| 5328 | - "error" => "Called Noop() without being connected"); |
|---|
| 5329 | - return false; |
|---|
| 5330 | - } |
|---|
| 5331 | + /** |
|---|
| 5332 | + * Sends the command NOOP to the SMTP server. |
|---|
| 5333 | + * |
|---|
| 5334 | + * Implements from rfc 821: NOOP <CRLF> |
|---|
| 5335 | + * |
|---|
| 5336 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5337 | + * SMTP CODE ERROR : 500, 421 |
|---|
| 5338 | + * @access public |
|---|
| 5339 | + * @return bool |
|---|
| 5340 | + */ |
|---|
| 5341 | + function Noop() { |
|---|
| 5342 | + $this->error = null; # so no confusion is caused |
|---|
| 5343 | |
|---|
| 5344 | - fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|---|
| 5345 | + if(!$this->connected()) { |
|---|
| 5346 | + $this->error = array( |
|---|
| 5347 | + "error" => "Called Noop() without being connected"); |
|---|
| 5348 | + return false; |
|---|
| 5349 | + } |
|---|
| 5350 | |
|---|
| 5351 | - $rply = $this->get_lines(); |
|---|
| 5352 | - $code = substr($rply,0,3); |
|---|
| 5353 | + fputs($this->smtp_conn,"NOOP" . $this->CRLF); |
|---|
| 5354 | |
|---|
| 5355 | - if($this->do_debug >= 2) { |
|---|
| 5356 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5357 | - } |
|---|
| 5358 | + $rply = $this->get_lines(); |
|---|
| 5359 | + $code = substr($rply,0,3); |
|---|
| 5360 | |
|---|
| 5361 | - if($code != 250) { |
|---|
| 5362 | - $this->error = |
|---|
| 5363 | - array("error" => "NOOP not accepted from server", |
|---|
| 5364 | - "smtp_code" => $code, |
|---|
| 5365 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5366 | - if($this->do_debug >= 1) { |
|---|
| 5367 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5368 | - ": " . $rply . $this->CRLF; |
|---|
| 5369 | - } |
|---|
| 5370 | - return false; |
|---|
| 5371 | - } |
|---|
| 5372 | - return true; |
|---|
| 5373 | + if($this->do_debug >= 2) { |
|---|
| 5374 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5375 | } |
|---|
| 5376 | |
|---|
| 5377 | - /** |
|---|
| 5378 | - * Sends the quit command to the server and then closes the socket |
|---|
| 5379 | - * if there is no error or the $close_on_error argument is true. |
|---|
| 5380 | - * |
|---|
| 5381 | - * Implements from rfc 821: QUIT <CRLF> |
|---|
| 5382 | - * |
|---|
| 5383 | - * SMTP CODE SUCCESS: 221 |
|---|
| 5384 | - * SMTP CODE ERROR : 500 |
|---|
| 5385 | - * @access public |
|---|
| 5386 | - * @return bool |
|---|
| 5387 | - */ |
|---|
| 5388 | - function Quit($close_on_error=true) { |
|---|
| 5389 | - $this->error = null; # so there is no confusion |
|---|
| 5390 | + if($code != 250) { |
|---|
| 5391 | + $this->error = |
|---|
| 5392 | + array("error" => "NOOP not accepted from server", |
|---|
| 5393 | + "smtp_code" => $code, |
|---|
| 5394 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5395 | + if($this->do_debug >= 1) { |
|---|
| 5396 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5397 | + ": " . $rply . $this->CRLF; |
|---|
| 5398 | + } |
|---|
| 5399 | + return false; |
|---|
| 5400 | + } |
|---|
| 5401 | + return true; |
|---|
| 5402 | + } |
|---|
| 5403 | |
|---|
| 5404 | - if(!$this->connected()) { |
|---|
| 5405 | - $this->error = array( |
|---|
| 5406 | - "error" => "Called Quit() without being connected"); |
|---|
| 5407 | - return false; |
|---|
| 5408 | - } |
|---|
| 5409 | + /** |
|---|
| 5410 | + * Sends the quit command to the server and then closes the socket |
|---|
| 5411 | + * if there is no error or the $close_on_error argument is true. |
|---|
| 5412 | + * |
|---|
| 5413 | + * Implements from rfc 821: QUIT <CRLF> |
|---|
| 5414 | + * |
|---|
| 5415 | + * SMTP CODE SUCCESS: 221 |
|---|
| 5416 | + * SMTP CODE ERROR : 500 |
|---|
| 5417 | + * @access public |
|---|
| 5418 | + * @return bool |
|---|
| 5419 | + */ |
|---|
| 5420 | + function Quit($close_on_error=true) { |
|---|
| 5421 | + $this->error = null; # so there is no confusion |
|---|
| 5422 | |
|---|
| 5423 | - # send the quit command to the server |
|---|
| 5424 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|---|
| 5425 | + if(!$this->connected()) { |
|---|
| 5426 | + $this->error = array( |
|---|
| 5427 | + "error" => "Called Quit() without being connected"); |
|---|
| 5428 | + return false; |
|---|
| 5429 | + } |
|---|
| 5430 | |
|---|
| 5431 | - # get any good-bye messages |
|---|
| 5432 | - $byemsg = $this->get_lines(); |
|---|
| 5433 | + # send the quit command to the server |
|---|
| 5434 | + fputs($this->smtp_conn,"quit" . $this->CRLF); |
|---|
| 5435 | |
|---|
| 5436 | - if($this->do_debug >= 2) { |
|---|
| 5437 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|---|
| 5438 | - } |
|---|
| 5439 | + # get any good-bye messages |
|---|
| 5440 | + $byemsg = $this->get_lines(); |
|---|
| 5441 | |
|---|
| 5442 | - $rval = true; |
|---|
| 5443 | - $e = null; |
|---|
| 5444 | + if($this->do_debug >= 2) { |
|---|
| 5445 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg; |
|---|
| 5446 | + } |
|---|
| 5447 | |
|---|
| 5448 | - $code = substr($byemsg,0,3); |
|---|
| 5449 | - if($code != 221) { |
|---|
| 5450 | - # use e as a tmp var cause Close will overwrite $this->error |
|---|
| 5451 | - $e = array("error" => "SMTP server rejected quit command", |
|---|
| 5452 | - "smtp_code" => $code, |
|---|
| 5453 | - "smtp_rply" => substr($byemsg,4)); |
|---|
| 5454 | - $rval = false; |
|---|
| 5455 | - if($this->do_debug >= 1) { |
|---|
| 5456 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|---|
| 5457 | - $byemsg . $this->CRLF; |
|---|
| 5458 | - } |
|---|
| 5459 | - } |
|---|
| 5460 | + $rval = true; |
|---|
| 5461 | + $e = null; |
|---|
| 5462 | |
|---|
| 5463 | - if(empty($e) || $close_on_error) { |
|---|
| 5464 | - $this->Close(); |
|---|
| 5465 | - } |
|---|
| 5466 | + $code = substr($byemsg,0,3); |
|---|
| 5467 | + if($code != 221) { |
|---|
| 5468 | + # use e as a tmp var cause Close will overwrite $this->error |
|---|
| 5469 | + $e = array("error" => "SMTP server rejected quit command", |
|---|
| 5470 | + "smtp_code" => $code, |
|---|
| 5471 | + "smtp_rply" => substr($byemsg,4)); |
|---|
| 5472 | + $rval = false; |
|---|
| 5473 | + if($this->do_debug >= 1) { |
|---|
| 5474 | + echo "SMTP -> ERROR: " . $e["error"] . ": " . |
|---|
| 5475 | + $byemsg . $this->CRLF; |
|---|
| 5476 | + } |
|---|
| 5477 | + } |
|---|
| 5478 | |
|---|
| 5479 | - return $rval; |
|---|
| 5480 | + if(empty($e) || $close_on_error) { |
|---|
| 5481 | + $this->Close(); |
|---|
| 5482 | } |
|---|
| 5483 | |
|---|
| 5484 | - /** |
|---|
| 5485 | - * Sends the command RCPT to the SMTP server with the TO: argument of $to. |
|---|
| 5486 | - * Returns true if the recipient was accepted false if it was rejected. |
|---|
| 5487 | - * |
|---|
| 5488 | - * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|---|
| 5489 | - * |
|---|
| 5490 | - * SMTP CODE SUCCESS: 250,251 |
|---|
| 5491 | - * SMTP CODE FAILURE: 550,551,552,553,450,451,452 |
|---|
| 5492 | - * SMTP CODE ERROR : 500,501,503,421 |
|---|
| 5493 | - * @access public |
|---|
| 5494 | - * @return bool |
|---|
| 5495 | - */ |
|---|
| 5496 | - function Recipient($to) { |
|---|
| 5497 | - $this->error = null; # so no confusion is caused |
|---|
| 5498 | + return $rval; |
|---|
| 5499 | + } |
|---|
| 5500 | |
|---|
| 5501 | - if(!$this->connected()) { |
|---|
| 5502 | - $this->error = array( |
|---|
| 5503 | - "error" => "Called Recipient() without being connected"); |
|---|
| 5504 | - return false; |
|---|
| 5505 | - } |
|---|
| 5506 | + /** |
|---|
| 5507 | + * Sends the command RCPT to the SMTP server with the TO: argument of $to. |
|---|
| 5508 | + * Returns true if the recipient was accepted false if it was rejected. |
|---|
| 5509 | + * |
|---|
| 5510 | + * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|---|
| 5511 | + * |
|---|
| 5512 | + * SMTP CODE SUCCESS: 250,251 |
|---|
| 5513 | + * SMTP CODE FAILURE: 550,551,552,553,450,451,452 |
|---|
| 5514 | + * SMTP CODE ERROR : 500,501,503,421 |
|---|
| 5515 | + * @access public |
|---|
| 5516 | + * @return bool |
|---|
| 5517 | + */ |
|---|
| 5518 | + function Recipient($to) { |
|---|
| 5519 | + $this->error = null; # so no confusion is caused |
|---|
| 5520 | |
|---|
| 5521 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|---|
| 5522 | + if(!$this->connected()) { |
|---|
| 5523 | + $this->error = array( |
|---|
| 5524 | + "error" => "Called Recipient() without being connected"); |
|---|
| 5525 | + return false; |
|---|
| 5526 | + } |
|---|
| 5527 | |
|---|
| 5528 | - $rply = $this->get_lines(); |
|---|
| 5529 | - $code = substr($rply,0,3); |
|---|
| 5530 | + fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|---|
| 5531 | |
|---|
| 5532 | - if($this->do_debug >= 2) { |
|---|
| 5533 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5534 | - } |
|---|
| 5535 | + $rply = $this->get_lines(); |
|---|
| 5536 | + $code = substr($rply,0,3); |
|---|
| 5537 | |
|---|
| 5538 | - if($code != 250 && $code != 251) { |
|---|
| 5539 | - $this->error = |
|---|
| 5540 | - array("error" => "RCPT not accepted from server", |
|---|
| 5541 | - "smtp_code" => $code, |
|---|
| 5542 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5543 | - if($this->do_debug >= 1) { |
|---|
| 5544 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5545 | - ": " . $rply . $this->CRLF; |
|---|
| 5546 | - } |
|---|
| 5547 | - return false; |
|---|
| 5548 | - } |
|---|
| 5549 | - return true; |
|---|
| 5550 | + if($this->do_debug >= 2) { |
|---|
| 5551 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5552 | } |
|---|
| 5553 | |
|---|
| 5554 | - /** |
|---|
| 5555 | - * Sends the RSET command to abort and transaction that is |
|---|
| 5556 | - * currently in progress. Returns true if successful false |
|---|
| 5557 | - * otherwise. |
|---|
| 5558 | - * |
|---|
| 5559 | - * Implements rfc 821: RSET <CRLF> |
|---|
| 5560 | - * |
|---|
| 5561 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5562 | - * SMTP CODE ERROR : 500,501,504,421 |
|---|
| 5563 | - * @access public |
|---|
| 5564 | - * @return bool |
|---|
| 5565 | - */ |
|---|
| 5566 | - function Reset() { |
|---|
| 5567 | - $this->error = null; # so no confusion is caused |
|---|
| 5568 | + if($code != 250 && $code != 251) { |
|---|
| 5569 | + $this->error = |
|---|
| 5570 | + array("error" => "RCPT not accepted from server", |
|---|
| 5571 | + "smtp_code" => $code, |
|---|
| 5572 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5573 | + if($this->do_debug >= 1) { |
|---|
| 5574 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5575 | + ": " . $rply . $this->CRLF; |
|---|
| 5576 | + } |
|---|
| 5577 | + return false; |
|---|
| 5578 | + } |
|---|
| 5579 | + return true; |
|---|
| 5580 | + } |
|---|
| 5581 | |
|---|
| 5582 | - if(!$this->connected()) { |
|---|
| 5583 | - $this->error = array( |
|---|
| 5584 | - "error" => "Called Reset() without being connected"); |
|---|
| 5585 | - return false; |
|---|
| 5586 | - } |
|---|
| 5587 | + /** |
|---|
| 5588 | + * Sends the RSET command to abort and transaction that is |
|---|
| 5589 | + * currently in progress. Returns true if successful false |
|---|
| 5590 | + * otherwise. |
|---|
| 5591 | + * |
|---|
| 5592 | + * Implements rfc 821: RSET <CRLF> |
|---|
| 5593 | + * |
|---|
| 5594 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5595 | + * SMTP CODE ERROR : 500,501,504,421 |
|---|
| 5596 | + * @access public |
|---|
| 5597 | + * @return bool |
|---|
| 5598 | + */ |
|---|
| 5599 | + function Reset() { |
|---|
| 5600 | + $this->error = null; # so no confusion is caused |
|---|
| 5601 | |
|---|
| 5602 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|---|
| 5603 | + if(!$this->connected()) { |
|---|
| 5604 | + $this->error = array( |
|---|
| 5605 | + "error" => "Called Reset() without being connected"); |
|---|
| 5606 | + return false; |
|---|
| 5607 | + } |
|---|
| 5608 | |
|---|
| 5609 | - $rply = $this->get_lines(); |
|---|
| 5610 | - $code = substr($rply,0,3); |
|---|
| 5611 | + fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|---|
| 5612 | |
|---|
| 5613 | - if($this->do_debug >= 2) { |
|---|
| 5614 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5615 | - } |
|---|
| 5616 | + $rply = $this->get_lines(); |
|---|
| 5617 | + $code = substr($rply,0,3); |
|---|
| 5618 | |
|---|
| 5619 | - if($code != 250) { |
|---|
| 5620 | - $this->error = |
|---|
| 5621 | - array("error" => "RSET failed", |
|---|
| 5622 | - "smtp_code" => $code, |
|---|
| 5623 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5624 | - if($this->do_debug >= 1) { |
|---|
| 5625 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5626 | - ": " . $rply . $this->CRLF; |
|---|
| 5627 | - } |
|---|
| 5628 | - return false; |
|---|
| 5629 | - } |
|---|
| 5630 | + if($this->do_debug >= 2) { |
|---|
| 5631 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5632 | + } |
|---|
| 5633 | |
|---|
| 5634 | - return true; |
|---|
| 5635 | + if($code != 250) { |
|---|
| 5636 | + $this->error = |
|---|
| 5637 | + array("error" => "RSET failed", |
|---|
| 5638 | + "smtp_code" => $code, |
|---|
| 5639 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5640 | + if($this->do_debug >= 1) { |
|---|
| 5641 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5642 | + ": " . $rply . $this->CRLF; |
|---|
| 5643 | + } |
|---|
| 5644 | + return false; |
|---|
| 5645 | } |
|---|
| 5646 | |
|---|
| 5647 | - /** |
|---|
| 5648 | - * Starts a mail transaction from the email address specified in |
|---|
| 5649 | - * $from. Returns true if successful or false otherwise. If True |
|---|
| 5650 | - * the mail transaction is started and then one or more Recipient |
|---|
| 5651 | - * commands may be called followed by a Data command. This command |
|---|
| 5652 | - * will send the message to the users terminal if they are logged |
|---|
| 5653 | - * in. |
|---|
| 5654 | - * |
|---|
| 5655 | - * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5656 | - * |
|---|
| 5657 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5658 | - * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5659 | - * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5660 | - * @access public |
|---|
| 5661 | - * @return bool |
|---|
| 5662 | - */ |
|---|
| 5663 | - function Send($from) { |
|---|
| 5664 | - $this->error = null; # so no confusion is caused |
|---|
| 5665 | + return true; |
|---|
| 5666 | + } |
|---|
| 5667 | |
|---|
| 5668 | - if(!$this->connected()) { |
|---|
| 5669 | - $this->error = array( |
|---|
| 5670 | - "error" => "Called Send() without being connected"); |
|---|
| 5671 | - return false; |
|---|
| 5672 | - } |
|---|
| 5673 | + /** |
|---|
| 5674 | + * Starts a mail transaction from the email address specified in |
|---|
| 5675 | + * $from. Returns true if successful or false otherwise. If True |
|---|
| 5676 | + * the mail transaction is started and then one or more Recipient |
|---|
| 5677 | + * commands may be called followed by a Data command. This command |
|---|
| 5678 | + * will send the message to the users terminal if they are logged |
|---|
| 5679 | + * in. |
|---|
| 5680 | + * |
|---|
| 5681 | + * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5682 | + * |
|---|
| 5683 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5684 | + * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5685 | + * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5686 | + * @access public |
|---|
| 5687 | + * @return bool |
|---|
| 5688 | + */ |
|---|
| 5689 | + function Send($from) { |
|---|
| 5690 | + $this->error = null; # so no confusion is caused |
|---|
| 5691 | |
|---|
| 5692 | - fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); |
|---|
| 5693 | + if(!$this->connected()) { |
|---|
| 5694 | + $this->error = array( |
|---|
| 5695 | + "error" => "Called Send() without being connected"); |
|---|
| 5696 | + return false; |
|---|
| 5697 | + } |
|---|
| 5698 | |
|---|
| 5699 | - $rply = $this->get_lines(); |
|---|
| 5700 | - $code = substr($rply,0,3); |
|---|
| 5701 | + fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF); |
|---|
| 5702 | |
|---|
| 5703 | - if($this->do_debug >= 2) { |
|---|
| 5704 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5705 | - } |
|---|
| 5706 | + $rply = $this->get_lines(); |
|---|
| 5707 | + $code = substr($rply,0,3); |
|---|
| 5708 | |
|---|
| 5709 | - if($code != 250) { |
|---|
| 5710 | - $this->error = |
|---|
| 5711 | - array("error" => "SEND not accepted from server", |
|---|
| 5712 | - "smtp_code" => $code, |
|---|
| 5713 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5714 | - if($this->do_debug >= 1) { |
|---|
| 5715 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5716 | - ": " . $rply . $this->CRLF; |
|---|
| 5717 | - } |
|---|
| 5718 | - return false; |
|---|
| 5719 | - } |
|---|
| 5720 | - return true; |
|---|
| 5721 | + if($this->do_debug >= 2) { |
|---|
| 5722 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5723 | } |
|---|
| 5724 | |
|---|
| 5725 | - /** |
|---|
| 5726 | - * Starts a mail transaction from the email address specified in |
|---|
| 5727 | - * $from. Returns true if successful or false otherwise. If True |
|---|
| 5728 | - * the mail transaction is started and then one or more Recipient |
|---|
| 5729 | - * commands may be called followed by a Data command. This command |
|---|
| 5730 | - * will send the message to the users terminal if they are logged |
|---|
| 5731 | - * in and send them an email. |
|---|
| 5732 | - * |
|---|
| 5733 | - * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5734 | - * |
|---|
| 5735 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5736 | - * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5737 | - * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5738 | - * @access public |
|---|
| 5739 | - * @return bool |
|---|
| 5740 | - */ |
|---|
| 5741 | - function SendAndMail($from) { |
|---|
| 5742 | - $this->error = null; # so no confusion is caused |
|---|
| 5743 | + if($code != 250) { |
|---|
| 5744 | + $this->error = |
|---|
| 5745 | + array("error" => "SEND not accepted from server", |
|---|
| 5746 | + "smtp_code" => $code, |
|---|
| 5747 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5748 | + if($this->do_debug >= 1) { |
|---|
| 5749 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5750 | + ": " . $rply . $this->CRLF; |
|---|
| 5751 | + } |
|---|
| 5752 | + return false; |
|---|
| 5753 | + } |
|---|
| 5754 | + return true; |
|---|
| 5755 | + } |
|---|
| 5756 | |
|---|
| 5757 | - if(!$this->connected()) { |
|---|
| 5758 | - $this->error = array( |
|---|
| 5759 | - "error" => "Called SendAndMail() without being connected"); |
|---|
| 5760 | - return false; |
|---|
| 5761 | - } |
|---|
| 5762 | + /** |
|---|
| 5763 | + * Starts a mail transaction from the email address specified in |
|---|
| 5764 | + * $from. Returns true if successful or false otherwise. If True |
|---|
| 5765 | + * the mail transaction is started and then one or more Recipient |
|---|
| 5766 | + * commands may be called followed by a Data command. This command |
|---|
| 5767 | + * will send the message to the users terminal if they are logged |
|---|
| 5768 | + * in and send them an email. |
|---|
| 5769 | + * |
|---|
| 5770 | + * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5771 | + * |
|---|
| 5772 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5773 | + * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5774 | + * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5775 | + * @access public |
|---|
| 5776 | + * @return bool |
|---|
| 5777 | + */ |
|---|
| 5778 | + function SendAndMail($from) { |
|---|
| 5779 | + $this->error = null; # so no confusion is caused |
|---|
| 5780 | |
|---|
| 5781 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|---|
| 5782 | + if(!$this->connected()) { |
|---|
| 5783 | + $this->error = array( |
|---|
| 5784 | + "error" => "Called SendAndMail() without being connected"); |
|---|
| 5785 | + return false; |
|---|
| 5786 | + } |
|---|
| 5787 | |
|---|
| 5788 | - $rply = $this->get_lines(); |
|---|
| 5789 | - $code = substr($rply,0,3); |
|---|
| 5790 | + fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|---|
| 5791 | |
|---|
| 5792 | - if($this->do_debug >= 2) { |
|---|
| 5793 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5794 | - } |
|---|
| 5795 | + $rply = $this->get_lines(); |
|---|
| 5796 | + $code = substr($rply,0,3); |
|---|
| 5797 | |
|---|
| 5798 | - if($code != 250) { |
|---|
| 5799 | - $this->error = |
|---|
| 5800 | - array("error" => "SAML not accepted from server", |
|---|
| 5801 | - "smtp_code" => $code, |
|---|
| 5802 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5803 | - if($this->do_debug >= 1) { |
|---|
| 5804 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5805 | - ": " . $rply . $this->CRLF; |
|---|
| 5806 | - } |
|---|
| 5807 | - return false; |
|---|
| 5808 | - } |
|---|
| 5809 | - return true; |
|---|
| 5810 | + if($this->do_debug >= 2) { |
|---|
| 5811 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5812 | } |
|---|
| 5813 | |
|---|
| 5814 | - /** |
|---|
| 5815 | - * Starts a mail transaction from the email address specified in |
|---|
| 5816 | - * $from. Returns true if successful or false otherwise. If True |
|---|
| 5817 | - * the mail transaction is started and then one or more Recipient |
|---|
| 5818 | - * commands may be called followed by a Data command. This command |
|---|
| 5819 | - * will send the message to the users terminal if they are logged |
|---|
| 5820 | - * in or mail it to them if they are not. |
|---|
| 5821 | - * |
|---|
| 5822 | - * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5823 | - * |
|---|
| 5824 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5825 | - * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5826 | - * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5827 | - * @access public |
|---|
| 5828 | - * @return bool |
|---|
| 5829 | - */ |
|---|
| 5830 | - function SendOrMail($from) { |
|---|
| 5831 | - $this->error = null; # so no confusion is caused |
|---|
| 5832 | + if($code != 250) { |
|---|
| 5833 | + $this->error = |
|---|
| 5834 | + array("error" => "SAML not accepted from server", |
|---|
| 5835 | + "smtp_code" => $code, |
|---|
| 5836 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5837 | + if($this->do_debug >= 1) { |
|---|
| 5838 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5839 | + ": " . $rply . $this->CRLF; |
|---|
| 5840 | + } |
|---|
| 5841 | + return false; |
|---|
| 5842 | + } |
|---|
| 5843 | + return true; |
|---|
| 5844 | + } |
|---|
| 5845 | |
|---|
| 5846 | - if(!$this->connected()) { |
|---|
| 5847 | - $this->error = array( |
|---|
| 5848 | - "error" => "Called SendOrMail() without being connected"); |
|---|
| 5849 | - return false; |
|---|
| 5850 | - } |
|---|
| 5851 | + /** |
|---|
| 5852 | + * Starts a mail transaction from the email address specified in |
|---|
| 5853 | + * $from. Returns true if successful or false otherwise. If True |
|---|
| 5854 | + * the mail transaction is started and then one or more Recipient |
|---|
| 5855 | + * commands may be called followed by a Data command. This command |
|---|
| 5856 | + * will send the message to the users terminal if they are logged |
|---|
| 5857 | + * in or mail it to them if they are not. |
|---|
| 5858 | + * |
|---|
| 5859 | + * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF> |
|---|
| 5860 | + * |
|---|
| 5861 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5862 | + * SMTP CODE SUCCESS: 552,451,452 |
|---|
| 5863 | + * SMTP CODE SUCCESS: 500,501,502,421 |
|---|
| 5864 | + * @access public |
|---|
| 5865 | + * @return bool |
|---|
| 5866 | + */ |
|---|
| 5867 | + function SendOrMail($from) { |
|---|
| 5868 | + $this->error = null; # so no confusion is caused |
|---|
| 5869 | |
|---|
| 5870 | - fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); |
|---|
| 5871 | + if(!$this->connected()) { |
|---|
| 5872 | + $this->error = array( |
|---|
| 5873 | + "error" => "Called SendOrMail() without being connected"); |
|---|
| 5874 | + return false; |
|---|
| 5875 | + } |
|---|
| 5876 | |
|---|
| 5877 | - $rply = $this->get_lines(); |
|---|
| 5878 | - $code = substr($rply,0,3); |
|---|
| 5879 | + fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF); |
|---|
| 5880 | |
|---|
| 5881 | - if($this->do_debug >= 2) { |
|---|
| 5882 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5883 | - } |
|---|
| 5884 | + $rply = $this->get_lines(); |
|---|
| 5885 | + $code = substr($rply,0,3); |
|---|
| 5886 | |
|---|
| 5887 | - if($code != 250) { |
|---|
| 5888 | - $this->error = |
|---|
| 5889 | - array("error" => "SOML not accepted from server", |
|---|
| 5890 | - "smtp_code" => $code, |
|---|
| 5891 | - "smtp_msg" => substr($rply,4)); |
|---|
| 5892 | - if($this->do_debug >= 1) { |
|---|
| 5893 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5894 | - ": " . $rply . $this->CRLF; |
|---|
| 5895 | - } |
|---|
| 5896 | - return false; |
|---|
| 5897 | - } |
|---|
| 5898 | - return true; |
|---|
| 5899 | + if($this->do_debug >= 2) { |
|---|
| 5900 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 5901 | } |
|---|
| 5902 | |
|---|
| 5903 | - /** |
|---|
| 5904 | - * This is an optional command for SMTP that this class does not |
|---|
| 5905 | - * support. This method is here to make the RFC821 Definition |
|---|
| 5906 | - * complete for this class and __may__ be implimented in the future |
|---|
| 5907 | - * |
|---|
| 5908 | - * Implements from rfc 821: TURN <CRLF> |
|---|
| 5909 | - * |
|---|
| 5910 | - * SMTP CODE SUCCESS: 250 |
|---|
| 5911 | - * SMTP CODE FAILURE: 502 |
|---|
| 5912 | - * SMTP CODE ERROR : 500, 503 |
|---|
| 5913 | - * @access public |
|---|
| 5914 | - * @return bool |
|---|
| 5915 | - */ |
|---|
| 5916 | - function Turn() { |
|---|
| 5917 | - $this->error = array("error" => "This method, TURN, of the SMTP ". |
|---|
| 5918 | - "is not implemented"); |
|---|
| 5919 | - if($this->do_debug >= 1) { |
|---|
| 5920 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; |
|---|
| 5921 | - } |
|---|
| 5922 | - return false; |
|---|
| 5923 | + if($code != 250) { |
|---|
| 5924 | + $this->error = |
|---|
| 5925 | + array("error" => "SOML not accepted from server", |
|---|
| 5926 | + "smtp_code" => $code, |
|---|
| 5927 | + "smtp_msg" => substr($rply,4)); |
|---|
| 5928 | + if($this->do_debug >= 1) { |
|---|
| 5929 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 5930 | + ": " . $rply . $this->CRLF; |
|---|
| 5931 | + } |
|---|
| 5932 | + return false; |
|---|
| 5933 | } |
|---|
| 5934 | + return true; |
|---|
| 5935 | + } |
|---|
| 5936 | |
|---|
| 5937 | - /** |
|---|
| 5938 | - * Verifies that the name is recognized by the server. |
|---|
| 5939 | - * Returns false if the name could not be verified otherwise |
|---|
| 5940 | - * the response from the server is returned. |
|---|
| 5941 | - * |
|---|
| 5942 | - * Implements rfc 821: VRFY <SP> <string> <CRLF> |
|---|
| 5943 | - * |
|---|
| 5944 | - * SMTP CODE SUCCESS: 250,251 |
|---|
| 5945 | - * SMTP CODE FAILURE: 550,551,553 |
|---|
| 5946 | - * SMTP CODE ERROR : 500,501,502,421 |
|---|
| 5947 | - * @access public |
|---|
| 5948 | - * @return int |
|---|
| 5949 | - */ |
|---|
| 5950 | - function Verify($name) { |
|---|
| 5951 | - $this->error = null; # so no confusion is caused |
|---|
| 5952 | + /** |
|---|
| 5953 | + * This is an optional command for SMTP that this class does not |
|---|
| 5954 | + * support. This method is here to make the RFC821 Definition |
|---|
| 5955 | + * complete for this class and __may__ be implimented in the future |
|---|
| 5956 | + * |
|---|
| 5957 | + * Implements from rfc 821: TURN <CRLF> |
|---|
| 5958 | + * |
|---|
| 5959 | + * SMTP CODE SUCCESS: 250 |
|---|
| 5960 | + * SMTP CODE FAILURE: 502 |
|---|
| 5961 | + * SMTP CODE ERROR : 500, 503 |
|---|
| 5962 | + * @access public |
|---|
| 5963 | + * @return bool |
|---|
| 5964 | + */ |
|---|
| 5965 | + function Turn() { |
|---|
| 5966 | + $this->error = array("error" => "This method, TURN, of the SMTP ". |
|---|
| 5967 | + "is not implemented"); |
|---|
| 5968 | + if($this->do_debug >= 1) { |
|---|
| 5969 | + echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF; |
|---|
| 5970 | + } |
|---|
| 5971 | + return false; |
|---|
| 5972 | + } |
|---|
| 5973 | |
|---|
| 5974 | - if(!$this->connected()) { |
|---|
| 5975 | - $this->error = array( |
|---|
| 5976 | - "error" => "Called Verify() without being connected"); |
|---|
| 5977 | - return false; |
|---|
| 5978 | - } |
|---|
| 5979 | + /** |
|---|
| 5980 | + * Verifies that the name is recognized by the server. |
|---|
| 5981 | + * Returns false if the name could not be verified otherwise |
|---|
| 5982 | + * the response from the server is returned. |
|---|
| 5983 | + * |
|---|
| 5984 | + * Implements rfc 821: VRFY <SP> <string> <CRLF> |
|---|
| 5985 | + * |
|---|
| 5986 | + * SMTP CODE SUCCESS: 250,251 |
|---|
| 5987 | + * SMTP CODE FAILURE: 550,551,553 |
|---|
| 5988 | + * SMTP CODE ERROR : 500,501,502,421 |
|---|
| 5989 | + * @access public |
|---|
| 5990 | + * @return int |
|---|
| 5991 | + */ |
|---|
| 5992 | + function Verify($name) { |
|---|
| 5993 | + $this->error = null; # so no confusion is caused |
|---|
| 5994 | |
|---|
| 5995 | - fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); |
|---|
| 5996 | + if(!$this->connected()) { |
|---|
| 5997 | + $this->error = array( |
|---|
| 5998 | + "error" => "Called Verify() without being connected"); |
|---|
| 5999 | + return false; |
|---|
| 6000 | + } |
|---|
| 6001 | |
|---|
| 6002 | - $rply = $this->get_lines(); |
|---|
| 6003 | - $code = substr($rply,0,3); |
|---|
| 6004 | + fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF); |
|---|
| 6005 | |
|---|
| 6006 | - if($this->do_debug >= 2) { |
|---|
| 6007 | - echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 6008 | - } |
|---|
| 6009 | + $rply = $this->get_lines(); |
|---|
| 6010 | + $code = substr($rply,0,3); |
|---|
| 6011 | |
|---|
| 6012 | - if($code != 250 && $code != 251) { |
|---|
| 6013 | - $this->error = |
|---|
| 6014 | - array("error" => "VRFY failed on name '$name'", |
|---|
| 6015 | - "smtp_code" => $code, |
|---|
| 6016 | - "smtp_msg" => substr($rply,4)); |
|---|
| 6017 | - if($this->do_debug >= 1) { |
|---|
| 6018 | - echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 6019 | - ": " . $rply . $this->CRLF; |
|---|
| 6020 | - } |
|---|
| 6021 | - return false; |
|---|
| 6022 | - } |
|---|
| 6023 | - return $rply; |
|---|
| 6024 | + if($this->do_debug >= 2) { |
|---|
| 6025 | + echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply; |
|---|
| 6026 | } |
|---|
| 6027 | |
|---|
| 6028 | - /******************************************************************* |
|---|
| 6029 | - * INTERNAL FUNCTIONS * |
|---|
| 6030 | - ******************************************************************/ |
|---|
| 6031 | + if($code != 250 && $code != 251) { |
|---|
| 6032 | + $this->error = |
|---|
| 6033 | + array("error" => "VRFY failed on name '$name'", |
|---|
| 6034 | + "smtp_code" => $code, |
|---|
| 6035 | + "smtp_msg" => substr($rply,4)); |
|---|
| 6036 | + if($this->do_debug >= 1) { |
|---|
| 6037 | + echo "SMTP -> ERROR: " . $this->error["error"] . |
|---|
| 6038 | + ": " . $rply . $this->CRLF; |
|---|
| 6039 | + } |
|---|
| 6040 | + return false; |
|---|
| 6041 | + } |
|---|
| 6042 | + return $rply; |
|---|
| 6043 | + } |
|---|
| 6044 | |
|---|
| 6045 | - /** |
|---|
| 6046 | - * Read in as many lines as possible |
|---|
| 6047 | - * either before eof or socket timeout occurs on the operation. |
|---|
| 6048 | - * With SMTP we can tell if we have more lines to read if the |
|---|
| 6049 | - * 4th character is '-' symbol. If it is a space then we don't |
|---|
| 6050 | - * need to read anything else. |
|---|
| 6051 | - * @access private |
|---|
| 6052 | - * @return string |
|---|
| 6053 | - */ |
|---|
| 6054 | - function get_lines() { |
|---|
| 6055 | - $data = ""; |
|---|
| 6056 | - while($str = fgets($this->smtp_conn,515)) { |
|---|
| 6057 | - if($this->do_debug >= 4) { |
|---|
| 6058 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . |
|---|
| 6059 | - $this->CRLF; |
|---|
| 6060 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . |
|---|
| 6061 | - $this->CRLF; |
|---|
| 6062 | - } |
|---|
| 6063 | - $data .= $str; |
|---|
| 6064 | - if($this->do_debug >= 4) { |
|---|
| 6065 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; |
|---|
| 6066 | - } |
|---|
| 6067 | - # if the 4th character is a space then we are done reading |
|---|
| 6068 | - # so just break the loop |
|---|
| 6069 | - if(substr($str,3,1) == " ") { break; } |
|---|
| 6070 | - } |
|---|
| 6071 | - return $data; |
|---|
| 6072 | + /******************************************************************* |
|---|
| 6073 | + * INTERNAL FUNCTIONS * |
|---|
| 6074 | + ******************************************************************/ |
|---|
| 6075 | + |
|---|
| 6076 | + /** |
|---|
| 6077 | + * Read in as many lines as possible |
|---|
| 6078 | + * either before eof or socket timeout occurs on the operation. |
|---|
| 6079 | + * With SMTP we can tell if we have more lines to read if the |
|---|
| 6080 | + * 4th character is '-' symbol. If it is a space then we don't |
|---|
| 6081 | + * need to read anything else. |
|---|
| 6082 | + * @access private |
|---|
| 6083 | + * @return string |
|---|
| 6084 | + */ |
|---|
| 6085 | + function get_lines() { |
|---|
| 6086 | + $data = ""; |
|---|
| 6087 | + while($str = @fgets($this->smtp_conn,515)) { |
|---|
| 6088 | + if($this->do_debug >= 4) { |
|---|
| 6089 | + echo "SMTP -> get_lines(): \$data was \"$data\"" . |
|---|
| 6090 | + $this->CRLF; |
|---|
| 6091 | + echo "SMTP -> get_lines(): \$str is \"$str\"" . |
|---|
| 6092 | + $this->CRLF; |
|---|
| 6093 | + } |
|---|
| 6094 | + $data .= $str; |
|---|
| 6095 | + if($this->do_debug >= 4) { |
|---|
| 6096 | + echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF; |
|---|
| 6097 | + } |
|---|
| 6098 | + # if the 4th character is a space then we are done reading |
|---|
| 6099 | + # so just break the loop |
|---|
| 6100 | + if(substr($str,3,1) == " ") { break; } |
|---|
| 6101 | } |
|---|
| 6102 | + return $data; |
|---|
| 6103 | + } |
|---|
| 6104 | |
|---|
| 6105 | } |
|---|
| 6106 | |
|---|
| 6107 | Index: wp-admin/includes/user.php |
|---|
| 6108 | =================================================================== |
|---|
| 6109 | --- wp-admin/includes/user.php (revision 8571) |
|---|
| 6110 | +++ wp-admin/includes/user.php (working copy) |
|---|
| 6111 | @@ -71,7 +71,7 @@ |
|---|
| 6112 | else if ( isset( $_POST['rich_editing'] ) ) |
|---|
| 6113 | $user->rich_editing = $_POST['rich_editing']; |
|---|
| 6114 | else |
|---|
| 6115 | - $user->rich_editing = 'false'; |
|---|
| 6116 | + $user->rich_editing = 'true'; |
|---|
| 6117 | |
|---|
| 6118 | if ( !$update ) |
|---|
| 6119 | $user->admin_color = 'fresh'; // Default to fresh for new users. |
|---|
| 6120 | Index: wp-admin/update.php |
|---|
| 6121 | =================================================================== |
|---|
| 6122 | --- wp-admin/update.php (revision 8571) |
|---|
| 6123 | +++ wp-admin/update.php (working copy) |
|---|
| 6124 | @@ -41,6 +41,7 @@ |
|---|
| 6125 | echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>'; |
|---|
| 6126 | } |
|---|
| 6127 | } |
|---|
| 6128 | + printf( __( 'Return to <a href="%s">Plugins</a>' ), 'plugins.php' ); |
|---|
| 6129 | echo '</div>'; |
|---|
| 6130 | } |
|---|
| 6131 | |
|---|
| 6132 | Index: wp-admin/user-edit.php |
|---|
| 6133 | =================================================================== |
|---|
| 6134 | --- wp-admin/user-edit.php (revision 8571) |
|---|
| 6135 | +++ wp-admin/user-edit.php (working copy) |
|---|
| 6136 | @@ -170,7 +170,7 @@ |
|---|
| 6137 | <?php if ( rich_edit_exists() ) : // don't bother showing the option if the editor has been removed ?> |
|---|
| 6138 | <tr> |
|---|
| 6139 | <th scope="row"><?php _e('Visual Editor')?></th> |
|---|
| 6140 | - <td><label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="true" <?php checked('true', $profileuser->rich_editing); ?> /> <?php _e('Use the visual editor when writing'); ?></label></td> |
|---|
| 6141 | + <td><label for="rich_editing"><input name="rich_editing" type="checkbox" id="rich_editing" value="false" <?php checked('false', $profileuser->rich_editing); ?> /> <?php _e('Disable the visual editor when writing'); ?></label></td> |
|---|
| 6142 | </tr> |
|---|
| 6143 | <?php endif; ?> |
|---|
| 6144 | <?php if (count($_wp_admin_css_colors) > 1 ) : ?> |
|---|