mp-wp_genesis 1 <?php
mp-wp_genesis 2 /*~ class.phpmailer.php
mp-wp_genesis 3 .---------------------------------------------------------------------------.
mp-wp_genesis 4 | Software: PHPMailer - PHP email class |
mp-wp_genesis 5 | Version: 2.0.2 |
mp-wp_genesis 6 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
mp-wp_genesis 7 | Info: http://phpmailer.sourceforge.net |
mp-wp_genesis 8 | Support: http://sourceforge.net/projects/phpmailer/ |
mp-wp_genesis 9 | ------------------------------------------------------------------------- |
mp-wp_genesis 10 | Author: Andy Prevost (project admininistrator) |
mp-wp_genesis 11 | Author: Brent R. Matzelle (original founder) |
mp-wp_genesis 12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
mp-wp_genesis 13 | Copyright (c) 2001-2003, Brent R. Matzelle |
mp-wp_genesis 14 | ------------------------------------------------------------------------- |
mp-wp_genesis 15 | License: Distributed under the Lesser General Public License (LGPL) |
mp-wp_genesis 16 | http://www.gnu.org/copyleft/lesser.html |
mp-wp_genesis 17 | This program is distributed in the hope that it will be useful - WITHOUT |
mp-wp_genesis 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mp-wp_genesis 19 | FITNESS FOR A PARTICULAR PURPOSE. |
mp-wp_genesis 20 | ------------------------------------------------------------------------- |
mp-wp_genesis 21 | We offer a number of paid services (www.codeworxtech.com): |
mp-wp_genesis 22 | - Web Hosting on highly optimized fast and secure servers |
mp-wp_genesis 23 | - Technology Consulting |
mp-wp_genesis 24 | - Oursourcing (highly qualified programmers and graphic designers) |
mp-wp_genesis 25 '---------------------------------------------------------------------------'
mp-wp_genesis 26 */
mp-wp_genesis 27 /**
mp-wp_genesis 28 * PHPMailer - PHP email transport class
mp-wp_genesis 29 * @package PHPMailer
mp-wp_genesis 30 * @author Andy Prevost
mp-wp_genesis 31 * @copyright 2004 - 2008 Andy Prevost
mp-wp_genesis 32 */
mp-wp_genesis 33
mp-wp_genesis 34 class PHPMailer {
mp-wp_genesis 35
mp-wp_genesis 36 /////////////////////////////////////////////////
mp-wp_genesis 37 // PROPERTIES, PUBLIC
mp-wp_genesis 38 /////////////////////////////////////////////////
mp-wp_genesis 39
mp-wp_genesis 40 /**
mp-wp_genesis 41 * Email priority (1 = High, 3 = Normal, 5 = low).
mp-wp_genesis 42 * @var int
mp-wp_genesis 43 */
mp-wp_genesis 44 var $Priority = 3;
mp-wp_genesis 45
mp-wp_genesis 46 /**
mp-wp_genesis 47 * Sets the CharSet of the message.
mp-wp_genesis 48 * @var string
mp-wp_genesis 49 */
mp-wp_genesis 50 var $CharSet = 'iso-8859-1';
mp-wp_genesis 51
mp-wp_genesis 52 /**
mp-wp_genesis 53 * Sets the Content-type of the message.
mp-wp_genesis 54 * @var string
mp-wp_genesis 55 */
mp-wp_genesis 56 var $ContentType = 'text/plain';
mp-wp_genesis 57
mp-wp_genesis 58 /**
mp-wp_genesis 59 * Sets the Encoding of the message. Options for this are "8bit",
mp-wp_genesis 60 * "7bit", "binary", "base64", and "quoted-printable".
mp-wp_genesis 61 * @var string
mp-wp_genesis 62 */
mp-wp_genesis 63 var $Encoding = '8bit';
mp-wp_genesis 64
mp-wp_genesis 65 /**
mp-wp_genesis 66 * Holds the most recent mailer error message.
mp-wp_genesis 67 * @var string
mp-wp_genesis 68 */
mp-wp_genesis 69 var $ErrorInfo = '';
mp-wp_genesis 70
mp-wp_genesis 71 /**
mp-wp_genesis 72 * Sets the From email address for the message.
mp-wp_genesis 73 * @var string
mp-wp_genesis 74 */
mp-wp_genesis 75 var $From = 'root@localhost';
mp-wp_genesis 76
mp-wp_genesis 77 /**
mp-wp_genesis 78 * Sets the From name of the message.
mp-wp_genesis 79 * @var string
mp-wp_genesis 80 */
mp-wp_genesis 81 var $FromName = 'Root User';
mp-wp_genesis 82
mp-wp_genesis 83 /**
mp-wp_genesis 84 * Sets the Sender email (Return-Path) of the message. If not empty,
mp-wp_genesis 85 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
mp-wp_genesis 86 * @var string
mp-wp_genesis 87 */
mp-wp_genesis 88 var $Sender = '';
mp-wp_genesis 89
mp-wp_genesis 90 /**
mp-wp_genesis 91 * Sets the Subject of the message.
mp-wp_genesis 92 * @var string
mp-wp_genesis 93 */
mp-wp_genesis 94 var $Subject = '';
mp-wp_genesis 95
mp-wp_genesis 96 /**
mp-wp_genesis 97 * Sets the Body of the message. This can be either an HTML or text body.
mp-wp_genesis 98 * If HTML then run IsHTML(true).
mp-wp_genesis 99 * @var string
mp-wp_genesis 100 */
mp-wp_genesis 101 var $Body = '';
mp-wp_genesis 102
mp-wp_genesis 103 /**
mp-wp_genesis 104 * Sets the text-only body of the message. This automatically sets the
mp-wp_genesis 105 * email to multipart/alternative. This body can be read by mail
mp-wp_genesis 106 * clients that do not have HTML email capability such as mutt. Clients
mp-wp_genesis 107 * that can read HTML will view the normal Body.
mp-wp_genesis 108 * @var string
mp-wp_genesis 109 */
mp-wp_genesis 110 var $AltBody = '';
mp-wp_genesis 111
mp-wp_genesis 112 /**
mp-wp_genesis 113 * Sets word wrapping on the body of the message to a given number of
mp-wp_genesis 114 * characters.
mp-wp_genesis 115 * @var int
mp-wp_genesis 116 */
mp-wp_genesis 117 var $WordWrap = 0;
mp-wp_genesis 118
mp-wp_genesis 119 /**
mp-wp_genesis 120 * Method to send mail: ("mail", "sendmail", or "smtp").
mp-wp_genesis 121 * @var string
mp-wp_genesis 122 */
mp-wp_genesis 123 var $Mailer = 'mail';
mp-wp_genesis 124
mp-wp_genesis 125 /**
mp-wp_genesis 126 * Sets the path of the sendmail program.
mp-wp_genesis 127 * @var string
mp-wp_genesis 128 */
mp-wp_genesis 129 var $Sendmail = '/usr/sbin/sendmail';
mp-wp_genesis 130
mp-wp_genesis 131 /**
mp-wp_genesis 132 * Path to PHPMailer plugins. This is now only useful if the SMTP class
mp-wp_genesis 133 * is in a different directory than the PHP include path.
mp-wp_genesis 134 * @var string
mp-wp_genesis 135 */
mp-wp_genesis 136 var $PluginDir = '';
mp-wp_genesis 137
mp-wp_genesis 138 /**
mp-wp_genesis 139 * Holds PHPMailer version.
mp-wp_genesis 140 * @var string
mp-wp_genesis 141 */
mp-wp_genesis 142 var $Version = "2.0.2";
mp-wp_genesis 143
mp-wp_genesis 144 /**
mp-wp_genesis 145 * Sets the email address that a reading confirmation will be sent.
mp-wp_genesis 146 * @var string
mp-wp_genesis 147 */
mp-wp_genesis 148 var $ConfirmReadingTo = '';
mp-wp_genesis 149
mp-wp_genesis 150 /**
mp-wp_genesis 151 * Sets the hostname to use in Message-Id and Received headers
mp-wp_genesis 152 * and as default HELO string. If empty, the value returned
mp-wp_genesis 153 * by SERVER_NAME is used or 'localhost.localdomain'.
mp-wp_genesis 154 * @var string
mp-wp_genesis 155 */
mp-wp_genesis 156 var $Hostname = '';
mp-wp_genesis 157
mp-wp_genesis 158 /**
mp-wp_genesis 159 * Sets the message ID to be used in the Message-Id header.
mp-wp_genesis 160 * If empty, a unique id will be generated.
mp-wp_genesis 161 * @var string
mp-wp_genesis 162 */
mp-wp_genesis 163 var $MessageID = '';
mp-wp_genesis 164
mp-wp_genesis 165 /////////////////////////////////////////////////
mp-wp_genesis 166 // PROPERTIES FOR SMTP
mp-wp_genesis 167 /////////////////////////////////////////////////
mp-wp_genesis 168
mp-wp_genesis 169 /**
mp-wp_genesis 170 * Sets the SMTP hosts. All hosts must be separated by a
mp-wp_genesis 171 * semicolon. You can also specify a different port
mp-wp_genesis 172 * for each host by using this format: [hostname:port]
mp-wp_genesis 173 * (e.g. "smtp1.example.com:25;smtp2.example.com").
mp-wp_genesis 174 * Hosts will be tried in order.
mp-wp_genesis 175 * @var string
mp-wp_genesis 176 */
mp-wp_genesis 177 var $Host = 'localhost';
mp-wp_genesis 178
mp-wp_genesis 179 /**
mp-wp_genesis 180 * Sets the default SMTP server port.
mp-wp_genesis 181 * @var int
mp-wp_genesis 182 */
mp-wp_genesis 183 var $Port = 25;
mp-wp_genesis 184
mp-wp_genesis 185 /**
mp-wp_genesis 186 * Sets the SMTP HELO of the message (Default is $Hostname).
mp-wp_genesis 187 * @var string
mp-wp_genesis 188 */
mp-wp_genesis 189 var $Helo = '';
mp-wp_genesis 190
mp-wp_genesis 191 /**
mp-wp_genesis 192 * Sets connection prefix.
mp-wp_genesis 193 * Options are "", "ssl" or "tls"
mp-wp_genesis 194 * @var string
mp-wp_genesis 195 */
mp-wp_genesis 196 var $SMTPSecure = "";
mp-wp_genesis 197
mp-wp_genesis 198 /**
mp-wp_genesis 199 * Sets SMTP authentication. Utilizes the Username and Password variables.
mp-wp_genesis 200 * @var bool
mp-wp_genesis 201 */
mp-wp_genesis 202 var $SMTPAuth = false;
mp-wp_genesis 203
mp-wp_genesis 204 /**
mp-wp_genesis 205 * Sets SMTP username.
mp-wp_genesis 206 * @var string
mp-wp_genesis 207 */
mp-wp_genesis 208 var $Username = '';
mp-wp_genesis 209
mp-wp_genesis 210 /**
mp-wp_genesis 211 * Sets SMTP password.
mp-wp_genesis 212 * @var string
mp-wp_genesis 213 */
mp-wp_genesis 214 var $Password = '';
mp-wp_genesis 215
mp-wp_genesis 216 /**
mp-wp_genesis 217 * Sets the SMTP server timeout in seconds. This function will not
mp-wp_genesis 218 * work with the win32 version.
mp-wp_genesis 219 * @var int
mp-wp_genesis 220 */
mp-wp_genesis 221 var $Timeout = 10;
mp-wp_genesis 222
mp-wp_genesis 223 /**
mp-wp_genesis 224 * Sets SMTP class debugging on or off.
mp-wp_genesis 225 * @var bool
mp-wp_genesis 226 */
mp-wp_genesis 227 var $SMTPDebug = false;
mp-wp_genesis 228
mp-wp_genesis 229 /**
mp-wp_genesis 230 * Prevents the SMTP connection from being closed after each mail
mp-wp_genesis 231 * sending. If this is set to true then to close the connection
mp-wp_genesis 232 * requires an explicit call to SmtpClose().
mp-wp_genesis 233 * @var bool
mp-wp_genesis 234 */
mp-wp_genesis 235 var $SMTPKeepAlive = false;
mp-wp_genesis 236
mp-wp_genesis 237 /**
mp-wp_genesis 238 * Provides the ability to have the TO field process individual
mp-wp_genesis 239 * emails, instead of sending to entire TO addresses
mp-wp_genesis 240 * @var bool
mp-wp_genesis 241 */
mp-wp_genesis 242 var $SingleTo = false;
mp-wp_genesis 243
mp-wp_genesis 244 /////////////////////////////////////////////////
mp-wp_genesis 245 // PROPERTIES, PRIVATE
mp-wp_genesis 246 /////////////////////////////////////////////////
mp-wp_genesis 247
mp-wp_genesis 248 var $smtp = NULL;
mp-wp_genesis 249 var $to = array();
mp-wp_genesis 250 var $cc = array();
mp-wp_genesis 251 var $bcc = array();
mp-wp_genesis 252 var $ReplyTo = array();
mp-wp_genesis 253 var $attachment = array();
mp-wp_genesis 254 var $CustomHeader = array();
mp-wp_genesis 255 var $message_type = '';
mp-wp_genesis 256 var $boundary = array();
mp-wp_genesis 257 var $language = array();
mp-wp_genesis 258 var $error_count = 0;
mp-wp_genesis 259 var $LE = "\n";
mp-wp_genesis 260 var $sign_key_file = "";
mp-wp_genesis 261 var $sign_key_pass = "";
mp-wp_genesis 262
mp-wp_genesis 263 /////////////////////////////////////////////////
mp-wp_genesis 264 // METHODS, VARIABLES
mp-wp_genesis 265 /////////////////////////////////////////////////
mp-wp_genesis 266
mp-wp_genesis 267 /**
mp-wp_genesis 268 * Sets message type to HTML.
mp-wp_genesis 269 * @param bool $bool
mp-wp_genesis 270 * @return void
mp-wp_genesis 271 */
mp-wp_genesis 272 function IsHTML($bool) {
mp-wp_genesis 273 if($bool == true) {
mp-wp_genesis 274 $this->ContentType = 'text/html';
mp-wp_genesis 275 } else {
mp-wp_genesis 276 $this->ContentType = 'text/plain';
mp-wp_genesis 277 }
mp-wp_genesis 278 }
mp-wp_genesis 279
mp-wp_genesis 280 /**
mp-wp_genesis 281 * Sets Mailer to send message using SMTP.
mp-wp_genesis 282 * @return void
mp-wp_genesis 283 */
mp-wp_genesis 284 function IsSMTP() {
mp-wp_genesis 285 $this->Mailer = 'smtp';
mp-wp_genesis 286 }
mp-wp_genesis 287
mp-wp_genesis 288 /**
mp-wp_genesis 289 * Sets Mailer to send message using PHP mail() function.
mp-wp_genesis 290 * @return void
mp-wp_genesis 291 */
mp-wp_genesis 292 function IsMail() {
mp-wp_genesis 293 $this->Mailer = 'mail';
mp-wp_genesis 294 }
mp-wp_genesis 295
mp-wp_genesis 296 /**
mp-wp_genesis 297 * Sets Mailer to send message using the $Sendmail program.
mp-wp_genesis 298 * @return void
mp-wp_genesis 299 */
mp-wp_genesis 300 function IsSendmail() {
mp-wp_genesis 301 $this->Mailer = 'sendmail';
mp-wp_genesis 302 }
mp-wp_genesis 303
mp-wp_genesis 304 /**
mp-wp_genesis 305 * Sets Mailer to send message using the qmail MTA.
mp-wp_genesis 306 * @return void
mp-wp_genesis 307 */
mp-wp_genesis 308 function IsQmail() {
mp-wp_genesis 309 $this->Sendmail = '/var/qmail/bin/sendmail';
mp-wp_genesis 310 $this->Mailer = 'sendmail';
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 /////////////////////////////////////////////////
mp-wp_genesis 314 // METHODS, RECIPIENTS
mp-wp_genesis 315 /////////////////////////////////////////////////
mp-wp_genesis 316
mp-wp_genesis 317 /**
mp-wp_genesis 318 * Adds a "To" address.
mp-wp_genesis 319 * @param string $address
mp-wp_genesis 320 * @param string $name
mp-wp_genesis 321 * @return void
mp-wp_genesis 322 */
mp-wp_genesis 323 function AddAddress($address, $name = '') {
mp-wp_genesis 324 $cur = count($this->to);
mp-wp_genesis 325 $this->to[$cur][0] = trim($address);
mp-wp_genesis 326 $this->to[$cur][1] = $name;
mp-wp_genesis 327 }
mp-wp_genesis 328
mp-wp_genesis 329 /**
mp-wp_genesis 330 * Adds a "Cc" address. Note: this function works
mp-wp_genesis 331 * with the SMTP mailer on win32, not with the "mail"
mp-wp_genesis 332 * mailer.
mp-wp_genesis 333 * @param string $address
mp-wp_genesis 334 * @param string $name
mp-wp_genesis 335 * @return void
mp-wp_genesis 336 */
mp-wp_genesis 337 function AddCC($address, $name = '') {
mp-wp_genesis 338 $cur = count($this->cc);
mp-wp_genesis 339 $this->cc[$cur][0] = trim($address);
mp-wp_genesis 340 $this->cc[$cur][1] = $name;
mp-wp_genesis 341 }
mp-wp_genesis 342
mp-wp_genesis 343 /**
mp-wp_genesis 344 * Adds a "Bcc" address. Note: this function works
mp-wp_genesis 345 * with the SMTP mailer on win32, not with the "mail"
mp-wp_genesis 346 * mailer.
mp-wp_genesis 347 * @param string $address
mp-wp_genesis 348 * @param string $name
mp-wp_genesis 349 * @return void
mp-wp_genesis 350 */
mp-wp_genesis 351 function AddBCC($address, $name = '') {
mp-wp_genesis 352 $cur = count($this->bcc);
mp-wp_genesis 353 $this->bcc[$cur][0] = trim($address);
mp-wp_genesis 354 $this->bcc[$cur][1] = $name;
mp-wp_genesis 355 }
mp-wp_genesis 356
mp-wp_genesis 357 /**
mp-wp_genesis 358 * Adds a "Reply-To" address.
mp-wp_genesis 359 * @param string $address
mp-wp_genesis 360 * @param string $name
mp-wp_genesis 361 * @return void
mp-wp_genesis 362 */
mp-wp_genesis 363 function AddReplyTo($address, $name = '') {
mp-wp_genesis 364 $cur = count($this->ReplyTo);
mp-wp_genesis 365 $this->ReplyTo[$cur][0] = trim($address);
mp-wp_genesis 366 $this->ReplyTo[$cur][1] = $name;
mp-wp_genesis 367 }
mp-wp_genesis 368
mp-wp_genesis 369 /////////////////////////////////////////////////
mp-wp_genesis 370 // METHODS, MAIL SENDING
mp-wp_genesis 371 /////////////////////////////////////////////////
mp-wp_genesis 372
mp-wp_genesis 373 /**
mp-wp_genesis 374 * Creates message and assigns Mailer. If the message is
mp-wp_genesis 375 * not sent successfully then it returns false. Use the ErrorInfo
mp-wp_genesis 376 * variable to view description of the error.
mp-wp_genesis 377 * @return bool
mp-wp_genesis 378 */
mp-wp_genesis 379 function Send() {
mp-wp_genesis 380 $header = '';
mp-wp_genesis 381 $body = '';
mp-wp_genesis 382 $result = true;
mp-wp_genesis 383
mp-wp_genesis 384 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
mp-wp_genesis 385 $this->SetError($this->Lang('provide_address'));
mp-wp_genesis 386 return false;
mp-wp_genesis 387 }
mp-wp_genesis 388
mp-wp_genesis 389 /* Set whether the message is multipart/alternative */
mp-wp_genesis 390 if(!empty($this->AltBody)) {
mp-wp_genesis 391 $this->ContentType = 'multipart/alternative';
mp-wp_genesis 392 }
mp-wp_genesis 393
mp-wp_genesis 394 $this->error_count = 0; // reset errors
mp-wp_genesis 395 $this->SetMessageType();
mp-wp_genesis 396 $header .= $this->CreateHeader();
mp-wp_genesis 397 $body = $this->CreateBody();
mp-wp_genesis 398
mp-wp_genesis 399 if($body == '') {
mp-wp_genesis 400 return false;
mp-wp_genesis 401 }
mp-wp_genesis 402
mp-wp_genesis 403 /* Choose the mailer */
mp-wp_genesis 404 switch($this->Mailer) {
mp-wp_genesis 405 case 'sendmail':
mp-wp_genesis 406 $result = $this->SendmailSend($header, $body);
mp-wp_genesis 407 break;
mp-wp_genesis 408 case 'smtp':
mp-wp_genesis 409 $result = $this->SmtpSend($header, $body);
mp-wp_genesis 410 break;
mp-wp_genesis 411 case 'mail':
mp-wp_genesis 412 $result = $this->MailSend($header, $body);
mp-wp_genesis 413 break;
mp-wp_genesis 414 default:
mp-wp_genesis 415 $result = $this->MailSend($header, $body);
mp-wp_genesis 416 break;
mp-wp_genesis 417 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
mp-wp_genesis 418 //$result = false;
mp-wp_genesis 419 //break;
mp-wp_genesis 420 }
mp-wp_genesis 421
mp-wp_genesis 422 return $result;
mp-wp_genesis 423 }
mp-wp_genesis 424
mp-wp_genesis 425 /**
mp-wp_genesis 426 * Sends mail using the $Sendmail program.
mp-wp_genesis 427 * @access private
mp-wp_genesis 428 * @return bool
mp-wp_genesis 429 */
mp-wp_genesis 430 function SendmailSend($header, $body) {
mp-wp_genesis 431 if ($this->Sender != '') {
mp-wp_genesis 432 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
mp-wp_genesis 433 } else {
mp-wp_genesis 434 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
mp-wp_genesis 435 }
mp-wp_genesis 436
mp-wp_genesis 437 if(!@$mail = popen($sendmail, 'w')) {
mp-wp_genesis 438 $this->SetError($this->Lang('execute') . $this->Sendmail);
mp-wp_genesis 439 return false;
mp-wp_genesis 440 }
mp-wp_genesis 441
mp-wp_genesis 442 fputs($mail, $header);
mp-wp_genesis 443 fputs($mail, $body);
mp-wp_genesis 444
mp-wp_genesis 445 $result = pclose($mail);
mp-wp_genesis 446 if (version_compare(phpversion(), '4.2.3') == -1) {
mp-wp_genesis 447 $result = $result >> 8 & 0xFF;
mp-wp_genesis 448 }
mp-wp_genesis 449 if($result != 0) {
mp-wp_genesis 450 $this->SetError($this->Lang('execute') . $this->Sendmail);
mp-wp_genesis 451 return false;
mp-wp_genesis 452 }
mp-wp_genesis 453 return true;
mp-wp_genesis 454 }
mp-wp_genesis 455
mp-wp_genesis 456 /**
mp-wp_genesis 457 * Sends mail using the PHP mail() function.
mp-wp_genesis 458 * @access private
mp-wp_genesis 459 * @return bool
mp-wp_genesis 460 */
mp-wp_genesis 461 function MailSend($header, $body) {
mp-wp_genesis 462
mp-wp_genesis 463 $to = '';
mp-wp_genesis 464 for($i = 0; $i < count($this->to); $i++) {
mp-wp_genesis 465 if($i != 0) { $to .= ', '; }
mp-wp_genesis 466 $to .= $this->AddrFormat($this->to[$i]);
mp-wp_genesis 467 }
mp-wp_genesis 468
mp-wp_genesis 469 $toArr = split(',', $to);
mp-wp_genesis 470
mp-wp_genesis 471 $params = sprintf("-oi -f %s", $this->Sender);
mp-wp_genesis 472 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
mp-wp_genesis 473 $old_from = ini_get('sendmail_from');
mp-wp_genesis 474 ini_set('sendmail_from', $this->Sender);
mp-wp_genesis 475 if ($this->SingleTo === true && count($toArr) > 1) {
mp-wp_genesis 476 foreach ($toArr as $key => $val) {
mp-wp_genesis 477 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
mp-wp_genesis 478 }
mp-wp_genesis 479 } else {
mp-wp_genesis 480 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
mp-wp_genesis 481 }
mp-wp_genesis 482 } else {
mp-wp_genesis 483 if ($this->SingleTo === true && count($toArr) > 1) {
mp-wp_genesis 484 foreach ($toArr as $key => $val) {
mp-wp_genesis 485 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
mp-wp_genesis 486 }
mp-wp_genesis 487 } else {
mp-wp_genesis 488 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
mp-wp_genesis 489 }
mp-wp_genesis 490 }
mp-wp_genesis 491
mp-wp_genesis 492 if (isset($old_from)) {
mp-wp_genesis 493 ini_set('sendmail_from', $old_from);
mp-wp_genesis 494 }
mp-wp_genesis 495
mp-wp_genesis 496 if(!$rt) {
mp-wp_genesis 497 $this->SetError($this->Lang('instantiate'));
mp-wp_genesis 498 return false;
mp-wp_genesis 499 }
mp-wp_genesis 500
mp-wp_genesis 501 return true;
mp-wp_genesis 502 }
mp-wp_genesis 503
mp-wp_genesis 504 /**
mp-wp_genesis 505 * Sends mail via SMTP using PhpSMTP (Author:
mp-wp_genesis 506 * Chris Ryan). Returns bool. Returns false if there is a
mp-wp_genesis 507 * bad MAIL FROM, RCPT, or DATA input.
mp-wp_genesis 508 * @access private
mp-wp_genesis 509 * @return bool
mp-wp_genesis 510 */
mp-wp_genesis 511 function SmtpSend($header, $body) {
mp-wp_genesis 512 include_once($this->PluginDir . 'class-smtp.php');
mp-wp_genesis 513 $error = '';
mp-wp_genesis 514 $bad_rcpt = array();
mp-wp_genesis 515
mp-wp_genesis 516 if(!$this->SmtpConnect()) {
mp-wp_genesis 517 return false;
mp-wp_genesis 518 }
mp-wp_genesis 519
mp-wp_genesis 520 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
mp-wp_genesis 521 if(!$this->smtp->Mail($smtp_from)) {
mp-wp_genesis 522 $error = $this->Lang('from_failed') . $smtp_from;
mp-wp_genesis 523 $this->SetError($error);
mp-wp_genesis 524 $this->smtp->Reset();
mp-wp_genesis 525 return false;
mp-wp_genesis 526 }
mp-wp_genesis 527
mp-wp_genesis 528 /* Attempt to send attach all recipients */
mp-wp_genesis 529 for($i = 0; $i < count($this->to); $i++) {
mp-wp_genesis 530 if(!$this->smtp->Recipient($this->to[$i][0])) {
mp-wp_genesis 531 $bad_rcpt[] = $this->to[$i][0];
mp-wp_genesis 532 }
mp-wp_genesis 533 }
mp-wp_genesis 534 for($i = 0; $i < count($this->cc); $i++) {
mp-wp_genesis 535 if(!$this->smtp->Recipient($this->cc[$i][0])) {
mp-wp_genesis 536 $bad_rcpt[] = $this->cc[$i][0];
mp-wp_genesis 537 }
mp-wp_genesis 538 }
mp-wp_genesis 539 for($i = 0; $i < count($this->bcc); $i++) {
mp-wp_genesis 540 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
mp-wp_genesis 541 $bad_rcpt[] = $this->bcc[$i][0];
mp-wp_genesis 542 }
mp-wp_genesis 543 }
mp-wp_genesis 544
mp-wp_genesis 545 if(count($bad_rcpt) > 0) { // Create error message
mp-wp_genesis 546 for($i = 0; $i < count($bad_rcpt); $i++) {
mp-wp_genesis 547 if($i != 0) {
mp-wp_genesis 548 $error .= ', ';
mp-wp_genesis 549 }
mp-wp_genesis 550 $error .= $bad_rcpt[$i];
mp-wp_genesis 551 }
mp-wp_genesis 552 $error = $this->Lang('recipients_failed') . $error;
mp-wp_genesis 553 $this->SetError($error);
mp-wp_genesis 554 $this->smtp->Reset();
mp-wp_genesis 555 return false;
mp-wp_genesis 556 }
mp-wp_genesis 557
mp-wp_genesis 558 if(!$this->smtp->Data($header . $body)) {
mp-wp_genesis 559 $this->SetError($this->Lang('data_not_accepted'));
mp-wp_genesis 560 $this->smtp->Reset();
mp-wp_genesis 561 return false;
mp-wp_genesis 562 }
mp-wp_genesis 563 if($this->SMTPKeepAlive == true) {
mp-wp_genesis 564 $this->smtp->Reset();
mp-wp_genesis 565 } else {
mp-wp_genesis 566 $this->SmtpClose();
mp-wp_genesis 567 }
mp-wp_genesis 568
mp-wp_genesis 569 return true;
mp-wp_genesis 570 }
mp-wp_genesis 571
mp-wp_genesis 572 /**
mp-wp_genesis 573 * Initiates a connection to an SMTP server. Returns false if the
mp-wp_genesis 574 * operation failed.
mp-wp_genesis 575 * @access private
mp-wp_genesis 576 * @return bool
mp-wp_genesis 577 */
mp-wp_genesis 578 function SmtpConnect() {
mp-wp_genesis 579 if($this->smtp == NULL) {
mp-wp_genesis 580 $this->smtp = new SMTP();
mp-wp_genesis 581 }
mp-wp_genesis 582
mp-wp_genesis 583 $this->smtp->do_debug = $this->SMTPDebug;
mp-wp_genesis 584 $hosts = explode(';', $this->Host);
mp-wp_genesis 585 $index = 0;
mp-wp_genesis 586 $connection = ($this->smtp->Connected());
mp-wp_genesis 587
mp-wp_genesis 588 /* Retry while there is no connection */
mp-wp_genesis 589 while($index < count($hosts) && $connection == false) {
mp-wp_genesis 590 $hostinfo = array();
mp-wp_genesis 591 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
mp-wp_genesis 592 $host = $hostinfo[1];
mp-wp_genesis 593 $port = $hostinfo[2];
mp-wp_genesis 594 } else {
mp-wp_genesis 595 $host = $hosts[$index];
mp-wp_genesis 596 $port = $this->Port;
mp-wp_genesis 597 }
mp-wp_genesis 598
mp-wp_genesis 599 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
mp-wp_genesis 600 if ($this->Helo != '') {
mp-wp_genesis 601 $this->smtp->Hello($this->Helo);
mp-wp_genesis 602 } else {
mp-wp_genesis 603 $this->smtp->Hello($this->ServerHostname());
mp-wp_genesis 604 }
mp-wp_genesis 605
mp-wp_genesis 606 $connection = true;
mp-wp_genesis 607 if($this->SMTPAuth) {
mp-wp_genesis 608 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
mp-wp_genesis 609 $this->SetError($this->Lang('authenticate'));
mp-wp_genesis 610 $this->smtp->Reset();
mp-wp_genesis 611 $connection = false;
mp-wp_genesis 612 }
mp-wp_genesis 613 }
mp-wp_genesis 614 }
mp-wp_genesis 615 $index++;
mp-wp_genesis 616 }
mp-wp_genesis 617 if(!$connection) {
mp-wp_genesis 618 $this->SetError($this->Lang('connect_host'));
mp-wp_genesis 619 }
mp-wp_genesis 620
mp-wp_genesis 621 return $connection;
mp-wp_genesis 622 }
mp-wp_genesis 623
mp-wp_genesis 624 /**
mp-wp_genesis 625 * Closes the active SMTP session if one exists.
mp-wp_genesis 626 * @return void
mp-wp_genesis 627 */
mp-wp_genesis 628 function SmtpClose() {
mp-wp_genesis 629 if($this->smtp != NULL) {
mp-wp_genesis 630 if($this->smtp->Connected()) {
mp-wp_genesis 631 $this->smtp->Quit();
mp-wp_genesis 632 $this->smtp->Close();
mp-wp_genesis 633 }
mp-wp_genesis 634 }
mp-wp_genesis 635 }
mp-wp_genesis 636
mp-wp_genesis 637 /**
mp-wp_genesis 638 * Sets the language for all class error messages. Returns false
mp-wp_genesis 639 * if it cannot load the language file. The default language type
mp-wp_genesis 640 * is English.
mp-wp_genesis 641 * @param string $lang_type Type of language (e.g. Portuguese: "br")
mp-wp_genesis 642 * @param string $lang_path Path to the language file directory
mp-wp_genesis 643 * @access public
mp-wp_genesis 644 * @return bool
mp-wp_genesis 645 */
mp-wp_genesis 646 function SetLanguage($lang_type, $lang_path = 'language/') {
mp-wp_genesis 647 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
mp-wp_genesis 648 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
mp-wp_genesis 649 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
mp-wp_genesis 650 include($lang_path.'phpmailer.lang-en.php');
mp-wp_genesis 651 } else {
mp-wp_genesis 652 $this->SetError('Could not load language file');
mp-wp_genesis 653 return false;
mp-wp_genesis 654 }
mp-wp_genesis 655 $this->language = $PHPMAILER_LANG;
mp-wp_genesis 656
mp-wp_genesis 657 return true;
mp-wp_genesis 658 }
mp-wp_genesis 659
mp-wp_genesis 660 /////////////////////////////////////////////////
mp-wp_genesis 661 // METHODS, MESSAGE CREATION
mp-wp_genesis 662 /////////////////////////////////////////////////
mp-wp_genesis 663
mp-wp_genesis 664 /**
mp-wp_genesis 665 * Creates recipient headers.
mp-wp_genesis 666 * @access private
mp-wp_genesis 667 * @return string
mp-wp_genesis 668 */
mp-wp_genesis 669 function AddrAppend($type, $addr) {
mp-wp_genesis 670 $addr_str = $type . ': ';
mp-wp_genesis 671 $addr_str .= $this->AddrFormat($addr[0]);
mp-wp_genesis 672 if(count($addr) > 1) {
mp-wp_genesis 673 for($i = 1; $i < count($addr); $i++) {
mp-wp_genesis 674 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
mp-wp_genesis 675 }
mp-wp_genesis 676 }
mp-wp_genesis 677 $addr_str .= $this->LE;
mp-wp_genesis 678
mp-wp_genesis 679 return $addr_str;
mp-wp_genesis 680 }
mp-wp_genesis 681
mp-wp_genesis 682 /**
mp-wp_genesis 683 * Formats an address correctly.
mp-wp_genesis 684 * @access private
mp-wp_genesis 685 * @return string
mp-wp_genesis 686 */
mp-wp_genesis 687 function AddrFormat($addr) {
mp-wp_genesis 688 if(empty($addr[1])) {
mp-wp_genesis 689 $formatted = $this->SecureHeader($addr[0]);
mp-wp_genesis 690 } else {
mp-wp_genesis 691 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
mp-wp_genesis 692 }
mp-wp_genesis 693
mp-wp_genesis 694 return $formatted;
mp-wp_genesis 695 }
mp-wp_genesis 696
mp-wp_genesis 697 /**
mp-wp_genesis 698 * Wraps message for use with mailers that do not
mp-wp_genesis 699 * automatically perform wrapping and for quoted-printable.
mp-wp_genesis 700 * Original written by philippe.
mp-wp_genesis 701 * @access private
mp-wp_genesis 702 * @return string
mp-wp_genesis 703 */
mp-wp_genesis 704 function WrapText($message, $length, $qp_mode = false) {
mp-wp_genesis 705 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
mp-wp_genesis 706 // If utf-8 encoding is used, we will need to make sure we don't
mp-wp_genesis 707 // split multibyte characters when we wrap
mp-wp_genesis 708 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
mp-wp_genesis 709
mp-wp_genesis 710 $message = $this->FixEOL($message);
mp-wp_genesis 711 if (substr($message, -1) == $this->LE) {
mp-wp_genesis 712 $message = substr($message, 0, -1);
mp-wp_genesis 713 }
mp-wp_genesis 714
mp-wp_genesis 715 $line = explode($this->LE, $message);
mp-wp_genesis 716 $message = '';
mp-wp_genesis 717 for ($i=0 ;$i < count($line); $i++) {
mp-wp_genesis 718 $line_part = explode(' ', $line[$i]);
mp-wp_genesis 719 $buf = '';
mp-wp_genesis 720 for ($e = 0; $e<count($line_part); $e++) {
mp-wp_genesis 721 $word = $line_part[$e];
mp-wp_genesis 722 if ($qp_mode and (strlen($word) > $length)) {
mp-wp_genesis 723 $space_left = $length - strlen($buf) - 1;
mp-wp_genesis 724 if ($e != 0) {
mp-wp_genesis 725 if ($space_left > 20) {
mp-wp_genesis 726 $len = $space_left;
mp-wp_genesis 727 if ($is_utf8) {
mp-wp_genesis 728 $len = $this->UTF8CharBoundary($word, $len);
mp-wp_genesis 729 } elseif (substr($word, $len - 1, 1) == "=") {
mp-wp_genesis 730 $len--;
mp-wp_genesis 731 } elseif (substr($word, $len - 2, 1) == "=") {
mp-wp_genesis 732 $len -= 2;
mp-wp_genesis 733 }
mp-wp_genesis 734 $part = substr($word, 0, $len);
mp-wp_genesis 735 $word = substr($word, $len);
mp-wp_genesis 736 $buf .= ' ' . $part;
mp-wp_genesis 737 $message .= $buf . sprintf("=%s", $this->LE);
mp-wp_genesis 738 } else {
mp-wp_genesis 739 $message .= $buf . $soft_break;
mp-wp_genesis 740 }
mp-wp_genesis 741 $buf = '';
mp-wp_genesis 742 }
mp-wp_genesis 743 while (strlen($word) > 0) {
mp-wp_genesis 744 $len = $length;
mp-wp_genesis 745 if ($is_utf8) {
mp-wp_genesis 746 $len = $this->UTF8CharBoundary($word, $len);
mp-wp_genesis 747 } elseif (substr($word, $len - 1, 1) == "=") {
mp-wp_genesis 748 $len--;
mp-wp_genesis 749 } elseif (substr($word, $len - 2, 1) == "=") {
mp-wp_genesis 750 $len -= 2;
mp-wp_genesis 751 }
mp-wp_genesis 752 $part = substr($word, 0, $len);
mp-wp_genesis 753 $word = substr($word, $len);
mp-wp_genesis 754
mp-wp_genesis 755 if (strlen($word) > 0) {
mp-wp_genesis 756 $message .= $part . sprintf("=%s", $this->LE);
mp-wp_genesis 757 } else {
mp-wp_genesis 758 $buf = $part;
mp-wp_genesis 759 }
mp-wp_genesis 760 }
mp-wp_genesis 761 } else {
mp-wp_genesis 762 $buf_o = $buf;
mp-wp_genesis 763 $buf .= ($e == 0) ? $word : (' ' . $word);
mp-wp_genesis 764
mp-wp_genesis 765 if (strlen($buf) > $length and $buf_o != '') {
mp-wp_genesis 766 $message .= $buf_o . $soft_break;
mp-wp_genesis 767 $buf = $word;
mp-wp_genesis 768 }
mp-wp_genesis 769 }
mp-wp_genesis 770 }
mp-wp_genesis 771 $message .= $buf . $this->LE;
mp-wp_genesis 772 }
mp-wp_genesis 773
mp-wp_genesis 774 return $message;
mp-wp_genesis 775 }
mp-wp_genesis 776
mp-wp_genesis 777 /**
mp-wp_genesis 778 * Finds last character boundary prior to maxLength in a utf-8
mp-wp_genesis 779 * quoted (printable) encoded string.
mp-wp_genesis 780 * Original written by Colin Brown.
mp-wp_genesis 781 * @access private
mp-wp_genesis 782 * @param string $encodedText utf-8 QP text
mp-wp_genesis 783 * @param int $maxLength find last character boundary prior to this length
mp-wp_genesis 784 * @return int
mp-wp_genesis 785 */
mp-wp_genesis 786 function UTF8CharBoundary($encodedText, $maxLength) {
mp-wp_genesis 787 $foundSplitPos = false;
mp-wp_genesis 788 $lookBack = 3;
mp-wp_genesis 789 while (!$foundSplitPos) {
mp-wp_genesis 790 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
mp-wp_genesis 791 $encodedCharPos = strpos($lastChunk, "=");
mp-wp_genesis 792 if ($encodedCharPos !== false) {
mp-wp_genesis 793 // Found start of encoded character byte within $lookBack block.
mp-wp_genesis 794 // Check the encoded byte value (the 2 chars after the '=')
mp-wp_genesis 795 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
mp-wp_genesis 796 $dec = hexdec($hex);
mp-wp_genesis 797 if ($dec < 128) { // Single byte character.
mp-wp_genesis 798 // If the encoded char was found at pos 0, it will fit
mp-wp_genesis 799 // otherwise reduce maxLength to start of the encoded char
mp-wp_genesis 800 $maxLength = ($encodedCharPos == 0) ? $maxLength :
mp-wp_genesis 801 $maxLength - ($lookBack - $encodedCharPos);
mp-wp_genesis 802 $foundSplitPos = true;
mp-wp_genesis 803 } elseif ($dec >= 192) { // First byte of a multi byte character
mp-wp_genesis 804 // Reduce maxLength to split at start of character
mp-wp_genesis 805 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
mp-wp_genesis 806 $foundSplitPos = true;
mp-wp_genesis 807 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
mp-wp_genesis 808 $lookBack += 3;
mp-wp_genesis 809 }
mp-wp_genesis 810 } else {
mp-wp_genesis 811 // No encoded character found
mp-wp_genesis 812 $foundSplitPos = true;
mp-wp_genesis 813 }
mp-wp_genesis 814 }
mp-wp_genesis 815 return $maxLength;
mp-wp_genesis 816 }
mp-wp_genesis 817
mp-wp_genesis 818 /**
mp-wp_genesis 819 * Set the body wrapping.
mp-wp_genesis 820 * @access private
mp-wp_genesis 821 * @return void
mp-wp_genesis 822 */
mp-wp_genesis 823 function SetWordWrap() {
mp-wp_genesis 824 if($this->WordWrap < 1) {
mp-wp_genesis 825 return;
mp-wp_genesis 826 }
mp-wp_genesis 827
mp-wp_genesis 828 switch($this->message_type) {
mp-wp_genesis 829 case 'alt':
mp-wp_genesis 830 /* fall through */
mp-wp_genesis 831 case 'alt_attachments':
mp-wp_genesis 832 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
mp-wp_genesis 833 break;
mp-wp_genesis 834 default:
mp-wp_genesis 835 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
mp-wp_genesis 836 break;
mp-wp_genesis 837 }
mp-wp_genesis 838 }
mp-wp_genesis 839
mp-wp_genesis 840 /**
mp-wp_genesis 841 * Assembles message header.
mp-wp_genesis 842 * @access private
mp-wp_genesis 843 * @return string
mp-wp_genesis 844 */
mp-wp_genesis 845 function CreateHeader() {
mp-wp_genesis 846 $result = '';
mp-wp_genesis 847
mp-wp_genesis 848 /* Set the boundaries */
mp-wp_genesis 849 $uniq_id = md5(uniqid(time()));
mp-wp_genesis 850 $this->boundary[1] = 'b1_' . $uniq_id;
mp-wp_genesis 851 $this->boundary[2] = 'b2_' . $uniq_id;
mp-wp_genesis 852
mp-wp_genesis 853 $result .= $this->HeaderLine('Date', $this->RFCDate());
mp-wp_genesis 854 if($this->Sender == '') {
mp-wp_genesis 855 $result .= $this->HeaderLine('Return-Path', trim($this->From));
mp-wp_genesis 856 } else {
mp-wp_genesis 857 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
mp-wp_genesis 858 }
mp-wp_genesis 859
mp-wp_genesis 860 /* To be created automatically by mail() */
mp-wp_genesis 861 if($this->Mailer != 'mail') {
mp-wp_genesis 862 if(count($this->to) > 0) {
mp-wp_genesis 863 $result .= $this->AddrAppend('To', $this->to);
mp-wp_genesis 864 } elseif (count($this->cc) == 0) {
mp-wp_genesis 865 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
mp-wp_genesis 866 }
mp-wp_genesis 867 if(count($this->cc) > 0) {
mp-wp_genesis 868 $result .= $this->AddrAppend('Cc', $this->cc);
mp-wp_genesis 869 }
mp-wp_genesis 870 }
mp-wp_genesis 871
mp-wp_genesis 872 $from = array();
mp-wp_genesis 873 $from[0][0] = trim($this->From);
mp-wp_genesis 874 $from[0][1] = $this->FromName;
mp-wp_genesis 875 $result .= $this->AddrAppend('From', $from);
mp-wp_genesis 876
mp-wp_genesis 877 /* sendmail and mail() extract Cc from the header before sending */
mp-wp_genesis 878 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
mp-wp_genesis 879 $result .= $this->AddrAppend('Cc', $this->cc);
mp-wp_genesis 880 }
mp-wp_genesis 881
mp-wp_genesis 882 /* sendmail and mail() extract Bcc from the header before sending */
mp-wp_genesis 883 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
mp-wp_genesis 884 $result .= $this->AddrAppend('Bcc', $this->bcc);
mp-wp_genesis 885 }
mp-wp_genesis 886
mp-wp_genesis 887 if(count($this->ReplyTo) > 0) {
mp-wp_genesis 888 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
mp-wp_genesis 889 }
mp-wp_genesis 890
mp-wp_genesis 891 /* mail() sets the subject itself */
mp-wp_genesis 892 if($this->Mailer != 'mail') {
mp-wp_genesis 893 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
mp-wp_genesis 894 }
mp-wp_genesis 895
mp-wp_genesis 896 if($this->MessageID != '') {
mp-wp_genesis 897 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
mp-wp_genesis 898 } else {
mp-wp_genesis 899 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
mp-wp_genesis 900 }
mp-wp_genesis 901 $result .= $this->HeaderLine('X-Priority', $this->Priority);
mp-wp_genesis 902 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
mp-wp_genesis 903
mp-wp_genesis 904 if($this->ConfirmReadingTo != '') {
mp-wp_genesis 905 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
mp-wp_genesis 906 }
mp-wp_genesis 907
mp-wp_genesis 908 // Add custom headers
mp-wp_genesis 909 for($index = 0; $index < count($this->CustomHeader); $index++) {
mp-wp_genesis 910 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
mp-wp_genesis 911 }
mp-wp_genesis 912 if (!$this->sign_key_file) {
mp-wp_genesis 913 $result .= $this->HeaderLine('MIME-Version', '1.0');
mp-wp_genesis 914 $result .= $this->GetMailMIME();
mp-wp_genesis 915 }
mp-wp_genesis 916
mp-wp_genesis 917 return $result;
mp-wp_genesis 918 }
mp-wp_genesis 919
mp-wp_genesis 920 /**
mp-wp_genesis 921 * Returns the message MIME.
mp-wp_genesis 922 * @access private
mp-wp_genesis 923 * @return string
mp-wp_genesis 924 */
mp-wp_genesis 925 function GetMailMIME() {
mp-wp_genesis 926 $result = '';
mp-wp_genesis 927 switch($this->message_type) {
mp-wp_genesis 928 case 'plain':
mp-wp_genesis 929 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
mp-wp_genesis 930 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
mp-wp_genesis 931 break;
mp-wp_genesis 932 case 'attachments':
mp-wp_genesis 933 /* fall through */
mp-wp_genesis 934 case 'alt_attachments':
mp-wp_genesis 935 if($this->InlineImageExists()){
mp-wp_genesis 936 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
mp-wp_genesis 937 } else {
mp-wp_genesis 938 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
mp-wp_genesis 939 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
mp-wp_genesis 940 }
mp-wp_genesis 941 break;
mp-wp_genesis 942 case 'alt':
mp-wp_genesis 943 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
mp-wp_genesis 944 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
mp-wp_genesis 945 break;
mp-wp_genesis 946 }
mp-wp_genesis 947
mp-wp_genesis 948 if($this->Mailer != 'mail') {
mp-wp_genesis 949 $result .= $this->LE.$this->LE;
mp-wp_genesis 950 }
mp-wp_genesis 951
mp-wp_genesis 952 return $result;
mp-wp_genesis 953 }
mp-wp_genesis 954
mp-wp_genesis 955 /**
mp-wp_genesis 956 * Assembles the message body. Returns an empty string on failure.
mp-wp_genesis 957 * @access private
mp-wp_genesis 958 * @return string
mp-wp_genesis 959 */
mp-wp_genesis 960 function CreateBody() {
mp-wp_genesis 961 $result = '';
mp-wp_genesis 962 if ($this->sign_key_file) {
mp-wp_genesis 963 $result .= $this->GetMailMIME();
mp-wp_genesis 964 }
mp-wp_genesis 965
mp-wp_genesis 966 $this->SetWordWrap();
mp-wp_genesis 967
mp-wp_genesis 968 switch($this->message_type) {
mp-wp_genesis 969 case 'alt':
mp-wp_genesis 970 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
mp-wp_genesis 971 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
mp-wp_genesis 972 $result .= $this->LE.$this->LE;
mp-wp_genesis 973 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
mp-wp_genesis 974 $result .= $this->EncodeString($this->Body, $this->Encoding);
mp-wp_genesis 975 $result .= $this->LE.$this->LE;
mp-wp_genesis 976 $result .= $this->EndBoundary($this->boundary[1]);
mp-wp_genesis 977 break;
mp-wp_genesis 978 case 'plain':
mp-wp_genesis 979 $result .= $this->EncodeString($this->Body, $this->Encoding);
mp-wp_genesis 980 break;
mp-wp_genesis 981 case 'attachments':
mp-wp_genesis 982 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
mp-wp_genesis 983 $result .= $this->EncodeString($this->Body, $this->Encoding);
mp-wp_genesis 984 $result .= $this->LE;
mp-wp_genesis 985 $result .= $this->AttachAll();
mp-wp_genesis 986 break;
mp-wp_genesis 987 case 'alt_attachments':
mp-wp_genesis 988 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
mp-wp_genesis 989 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
mp-wp_genesis 990 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
mp-wp_genesis 991 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
mp-wp_genesis 992 $result .= $this->LE.$this->LE;
mp-wp_genesis 993 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
mp-wp_genesis 994 $result .= $this->EncodeString($this->Body, $this->Encoding);
mp-wp_genesis 995 $result .= $this->LE.$this->LE;
mp-wp_genesis 996 $result .= $this->EndBoundary($this->boundary[2]);
mp-wp_genesis 997 $result .= $this->AttachAll();
mp-wp_genesis 998 break;
mp-wp_genesis 999 }
mp-wp_genesis 1000
mp-wp_genesis 1001 if($this->IsError()) {
mp-wp_genesis 1002 $result = '';
mp-wp_genesis 1003 } else if ($this->sign_key_file) {
mp-wp_genesis 1004 $file = tempnam("", "mail");
mp-wp_genesis 1005 $fp = fopen($file, "w");
mp-wp_genesis 1006 fwrite($fp, $result);
mp-wp_genesis 1007 fclose($fp);
mp-wp_genesis 1008 $signed = tempnam("", "signed");
mp-wp_genesis 1009
mp-wp_genesis 1010 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
mp-wp_genesis 1011 $fp = fopen($signed, "r");
mp-wp_genesis 1012 $result = fread($fp, filesize($this->sign_key_file));
mp-wp_genesis 1013 fclose($fp);
mp-wp_genesis 1014 } else {
mp-wp_genesis 1015 $this->SetError($this->Lang("signing").openssl_error_string());
mp-wp_genesis 1016 $result = '';
mp-wp_genesis 1017 }
mp-wp_genesis 1018
mp-wp_genesis 1019 unlink($file);
mp-wp_genesis 1020 unlink($signed);
mp-wp_genesis 1021 }
mp-wp_genesis 1022
mp-wp_genesis 1023 return $result;
mp-wp_genesis 1024 }
mp-wp_genesis 1025
mp-wp_genesis 1026 /**
mp-wp_genesis 1027 * Returns the start of a message boundary.
mp-wp_genesis 1028 * @access private
mp-wp_genesis 1029 */
mp-wp_genesis 1030 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
mp-wp_genesis 1031 $result = '';
mp-wp_genesis 1032 if($charSet == '') {
mp-wp_genesis 1033 $charSet = $this->CharSet;
mp-wp_genesis 1034 }
mp-wp_genesis 1035 if($contentType == '') {
mp-wp_genesis 1036 $contentType = $this->ContentType;
mp-wp_genesis 1037 }
mp-wp_genesis 1038 if($encoding == '') {
mp-wp_genesis 1039 $encoding = $this->Encoding;
mp-wp_genesis 1040 }
mp-wp_genesis 1041 $result .= $this->TextLine('--' . $boundary);
mp-wp_genesis 1042 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
mp-wp_genesis 1043 $result .= $this->LE;
mp-wp_genesis 1044 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
mp-wp_genesis 1045 $result .= $this->LE;
mp-wp_genesis 1046
mp-wp_genesis 1047 return $result;
mp-wp_genesis 1048 }
mp-wp_genesis 1049
mp-wp_genesis 1050 /**
mp-wp_genesis 1051 * Returns the end of a message boundary.
mp-wp_genesis 1052 * @access private
mp-wp_genesis 1053 */
mp-wp_genesis 1054 function EndBoundary($boundary) {
mp-wp_genesis 1055 return $this->LE . '--' . $boundary . '--' . $this->LE;
mp-wp_genesis 1056 }
mp-wp_genesis 1057
mp-wp_genesis 1058 /**
mp-wp_genesis 1059 * Sets the message type.
mp-wp_genesis 1060 * @access private
mp-wp_genesis 1061 * @return void
mp-wp_genesis 1062 */
mp-wp_genesis 1063 function SetMessageType() {
mp-wp_genesis 1064 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
mp-wp_genesis 1065 $this->message_type = 'plain';
mp-wp_genesis 1066 } else {
mp-wp_genesis 1067 if(count($this->attachment) > 0) {
mp-wp_genesis 1068 $this->message_type = 'attachments';
mp-wp_genesis 1069 }
mp-wp_genesis 1070 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
mp-wp_genesis 1071 $this->message_type = 'alt';
mp-wp_genesis 1072 }
mp-wp_genesis 1073 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
mp-wp_genesis 1074 $this->message_type = 'alt_attachments';
mp-wp_genesis 1075 }
mp-wp_genesis 1076 }
mp-wp_genesis 1077 }
mp-wp_genesis 1078
mp-wp_genesis 1079 /* Returns a formatted header line.
mp-wp_genesis 1080 * @access private
mp-wp_genesis 1081 * @return string
mp-wp_genesis 1082 */
mp-wp_genesis 1083 function HeaderLine($name, $value) {
mp-wp_genesis 1084 return $name . ': ' . $value . $this->LE;
mp-wp_genesis 1085 }
mp-wp_genesis 1086
mp-wp_genesis 1087 /**
mp-wp_genesis 1088 * Returns a formatted mail line.
mp-wp_genesis 1089 * @access private
mp-wp_genesis 1090 * @return string
mp-wp_genesis 1091 */
mp-wp_genesis 1092 function TextLine($value) {
mp-wp_genesis 1093 return $value . $this->LE;
mp-wp_genesis 1094 }
mp-wp_genesis 1095
mp-wp_genesis 1096 /////////////////////////////////////////////////
mp-wp_genesis 1097 // CLASS METHODS, ATTACHMENTS
mp-wp_genesis 1098 /////////////////////////////////////////////////
mp-wp_genesis 1099
mp-wp_genesis 1100 /**
mp-wp_genesis 1101 * Adds an attachment from a path on the filesystem.
mp-wp_genesis 1102 * Returns false if the file could not be found
mp-wp_genesis 1103 * or accessed.
mp-wp_genesis 1104 * @param string $path Path to the attachment.
mp-wp_genesis 1105 * @param string $name Overrides the attachment name.
mp-wp_genesis 1106 * @param string $encoding File encoding (see $Encoding).
mp-wp_genesis 1107 * @param string $type File extension (MIME) type.
mp-wp_genesis 1108 * @return bool
mp-wp_genesis 1109 */
mp-wp_genesis 1110 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
mp-wp_genesis 1111 if(!@is_file($path)) {
mp-wp_genesis 1112 $this->SetError($this->Lang('file_access') . $path);
mp-wp_genesis 1113 return false;
mp-wp_genesis 1114 }
mp-wp_genesis 1115
mp-wp_genesis 1116 $filename = basename($path);
mp-wp_genesis 1117 if($name == '') {
mp-wp_genesis 1118 $name = $filename;
mp-wp_genesis 1119 }
mp-wp_genesis 1120
mp-wp_genesis 1121 $cur = count($this->attachment);
mp-wp_genesis 1122 $this->attachment[$cur][0] = $path;
mp-wp_genesis 1123 $this->attachment[$cur][1] = $filename;
mp-wp_genesis 1124 $this->attachment[$cur][2] = $name;
mp-wp_genesis 1125 $this->attachment[$cur][3] = $encoding;
mp-wp_genesis 1126 $this->attachment[$cur][4] = $type;
mp-wp_genesis 1127 $this->attachment[$cur][5] = false; // isStringAttachment
mp-wp_genesis 1128 $this->attachment[$cur][6] = 'attachment';
mp-wp_genesis 1129 $this->attachment[$cur][7] = 0;
mp-wp_genesis 1130
mp-wp_genesis 1131 return true;
mp-wp_genesis 1132 }
mp-wp_genesis 1133
mp-wp_genesis 1134 /**
mp-wp_genesis 1135 * Attaches all fs, string, and binary attachments to the message.
mp-wp_genesis 1136 * Returns an empty string on failure.
mp-wp_genesis 1137 * @access private
mp-wp_genesis 1138 * @return string
mp-wp_genesis 1139 */
mp-wp_genesis 1140 function AttachAll() {
mp-wp_genesis 1141 /* Return text of body */
mp-wp_genesis 1142 $mime = array();
mp-wp_genesis 1143
mp-wp_genesis 1144 /* Add all attachments */
mp-wp_genesis 1145 for($i = 0; $i < count($this->attachment); $i++) {
mp-wp_genesis 1146 /* Check for string attachment */
mp-wp_genesis 1147 $bString = $this->attachment[$i][5];
mp-wp_genesis 1148 if ($bString) {
mp-wp_genesis 1149 $string = $this->attachment[$i][0];
mp-wp_genesis 1150 } else {
mp-wp_genesis 1151 $path = $this->attachment[$i][0];
mp-wp_genesis 1152 }
mp-wp_genesis 1153
mp-wp_genesis 1154 $filename = $this->attachment[$i][1];
mp-wp_genesis 1155 $name = $this->attachment[$i][2];
mp-wp_genesis 1156 $encoding = $this->attachment[$i][3];
mp-wp_genesis 1157 $type = $this->attachment[$i][4];
mp-wp_genesis 1158 $disposition = $this->attachment[$i][6];
mp-wp_genesis 1159 $cid = $this->attachment[$i][7];
mp-wp_genesis 1160
mp-wp_genesis 1161 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
mp-wp_genesis 1162 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
mp-wp_genesis 1163 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
mp-wp_genesis 1164
mp-wp_genesis 1165 if($disposition == 'inline') {
mp-wp_genesis 1166 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
mp-wp_genesis 1167 }
mp-wp_genesis 1168
mp-wp_genesis 1169 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
mp-wp_genesis 1170
mp-wp_genesis 1171 /* Encode as string attachment */
mp-wp_genesis 1172 if($bString) {
mp-wp_genesis 1173 $mime[] = $this->EncodeString($string, $encoding);
mp-wp_genesis 1174 if($this->IsError()) {
mp-wp_genesis 1175 return '';
mp-wp_genesis 1176 }
mp-wp_genesis 1177 $mime[] = $this->LE.$this->LE;
mp-wp_genesis 1178 } else {
mp-wp_genesis 1179 $mime[] = $this->EncodeFile($path, $encoding);
mp-wp_genesis 1180 if($this->IsError()) {
mp-wp_genesis 1181 return '';
mp-wp_genesis 1182 }
mp-wp_genesis 1183 $mime[] = $this->LE.$this->LE;
mp-wp_genesis 1184 }
mp-wp_genesis 1185 }
mp-wp_genesis 1186
mp-wp_genesis 1187 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
mp-wp_genesis 1188
mp-wp_genesis 1189 return join('', $mime);
mp-wp_genesis 1190 }
mp-wp_genesis 1191
mp-wp_genesis 1192 /**
mp-wp_genesis 1193 * Encodes attachment in requested format. Returns an
mp-wp_genesis 1194 * empty string on failure.
mp-wp_genesis 1195 * @access private
mp-wp_genesis 1196 * @return string
mp-wp_genesis 1197 */
mp-wp_genesis 1198 function EncodeFile ($path, $encoding = 'base64') {
mp-wp_genesis 1199 if(!@$fd = fopen($path, 'rb')) {
mp-wp_genesis 1200 $this->SetError($this->Lang('file_open') . $path);
mp-wp_genesis 1201 return '';
mp-wp_genesis 1202 }
mp-wp_genesis 1203 $magic_quotes = get_magic_quotes_runtime();
mp-wp_genesis 1204 set_magic_quotes_runtime(0);
mp-wp_genesis 1205 $file_buffer = fread($fd, filesize($path));
mp-wp_genesis 1206 $file_buffer = $this->EncodeString($file_buffer, $encoding);
mp-wp_genesis 1207 fclose($fd);
mp-wp_genesis 1208 set_magic_quotes_runtime($magic_quotes);
mp-wp_genesis 1209
mp-wp_genesis 1210 return $file_buffer;
mp-wp_genesis 1211 }
mp-wp_genesis 1212
mp-wp_genesis 1213 /**
mp-wp_genesis 1214 * Encodes string to requested format. Returns an
mp-wp_genesis 1215 * empty string on failure.
mp-wp_genesis 1216 * @access private
mp-wp_genesis 1217 * @return string
mp-wp_genesis 1218 */
mp-wp_genesis 1219 function EncodeString ($str, $encoding = 'base64') {
mp-wp_genesis 1220 $encoded = '';
mp-wp_genesis 1221 switch(strtolower($encoding)) {
mp-wp_genesis 1222 case 'base64':
mp-wp_genesis 1223 /* chunk_split is found in PHP >= 3.0.6 */
mp-wp_genesis 1224 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
mp-wp_genesis 1225 break;
mp-wp_genesis 1226 case '7bit':
mp-wp_genesis 1227 case '8bit':
mp-wp_genesis 1228 $encoded = $this->FixEOL($str);
mp-wp_genesis 1229 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
mp-wp_genesis 1230 $encoded .= $this->LE;
mp-wp_genesis 1231 break;
mp-wp_genesis 1232 case 'binary':
mp-wp_genesis 1233 $encoded = $str;
mp-wp_genesis 1234 break;
mp-wp_genesis 1235 case 'quoted-printable':
mp-wp_genesis 1236 $encoded = $this->EncodeQP($str);
mp-wp_genesis 1237 break;
mp-wp_genesis 1238 default:
mp-wp_genesis 1239 $this->SetError($this->Lang('encoding') . $encoding);
mp-wp_genesis 1240 break;
mp-wp_genesis 1241 }
mp-wp_genesis 1242 return $encoded;
mp-wp_genesis 1243 }
mp-wp_genesis 1244
mp-wp_genesis 1245 /**
mp-wp_genesis 1246 * Encode a header string to best of Q, B, quoted or none.
mp-wp_genesis 1247 * @access private
mp-wp_genesis 1248 * @return string
mp-wp_genesis 1249 */
mp-wp_genesis 1250 function EncodeHeader ($str, $position = 'text') {
mp-wp_genesis 1251 $x = 0;
mp-wp_genesis 1252
mp-wp_genesis 1253 switch (strtolower($position)) {
mp-wp_genesis 1254 case 'phrase':
mp-wp_genesis 1255 if (!preg_match('/[\200-\377]/', $str)) {
mp-wp_genesis 1256 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
mp-wp_genesis 1257 $encoded = addcslashes($str, "\0..\37\177\\\"");
mp-wp_genesis 1258 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
mp-wp_genesis 1259 return ($encoded);
mp-wp_genesis 1260 } else {
mp-wp_genesis 1261 return ("\"$encoded\"");
mp-wp_genesis 1262 }
mp-wp_genesis 1263 }
mp-wp_genesis 1264 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
mp-wp_genesis 1265 break;
mp-wp_genesis 1266 case 'comment':
mp-wp_genesis 1267 $x = preg_match_all('/[()"]/', $str, $matches);
mp-wp_genesis 1268 /* Fall-through */
mp-wp_genesis 1269 case 'text':
mp-wp_genesis 1270 default:
mp-wp_genesis 1271 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
mp-wp_genesis 1272 break;
mp-wp_genesis 1273 }
mp-wp_genesis 1274
mp-wp_genesis 1275 if ($x == 0) {
mp-wp_genesis 1276 return ($str);
mp-wp_genesis 1277 }
mp-wp_genesis 1278
mp-wp_genesis 1279 $maxlen = 75 - 7 - strlen($this->CharSet);
mp-wp_genesis 1280 /* Try to select the encoding which should produce the shortest output */
mp-wp_genesis 1281 if (strlen($str)/3 < $x) {
mp-wp_genesis 1282 $encoding = 'B';
mp-wp_genesis 1283 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
mp-wp_genesis 1284 // Use a custom function which correctly encodes and wraps long
mp-wp_genesis 1285 // multibyte strings without breaking lines within a character
mp-wp_genesis 1286 $encoded = $this->Base64EncodeWrapMB($str);
mp-wp_genesis 1287 } else {
mp-wp_genesis 1288 $encoded = base64_encode($str);
mp-wp_genesis 1289 $maxlen -= $maxlen % 4;
mp-wp_genesis 1290 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
mp-wp_genesis 1291 }
mp-wp_genesis 1292 } else {
mp-wp_genesis 1293 $encoding = 'Q';
mp-wp_genesis 1294 $encoded = $this->EncodeQ($str, $position);
mp-wp_genesis 1295 $encoded = $this->WrapText($encoded, $maxlen, true);
mp-wp_genesis 1296 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
mp-wp_genesis 1297 }
mp-wp_genesis 1298
mp-wp_genesis 1299 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
mp-wp_genesis 1300 $encoded = trim(str_replace("\n", $this->LE, $encoded));
mp-wp_genesis 1301
mp-wp_genesis 1302 return $encoded;
mp-wp_genesis 1303 }
mp-wp_genesis 1304
mp-wp_genesis 1305 /**
mp-wp_genesis 1306 * Checks if a string contains multibyte characters.
mp-wp_genesis 1307 * @access private
mp-wp_genesis 1308 * @param string $str multi-byte text to wrap encode
mp-wp_genesis 1309 * @return bool
mp-wp_genesis 1310 */
mp-wp_genesis 1311 function HasMultiBytes($str) {
mp-wp_genesis 1312 if (function_exists('mb_strlen')) {
mp-wp_genesis 1313 return (strlen($str) > mb_strlen($str, $this->CharSet));
mp-wp_genesis 1314 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
mp-wp_genesis 1315 return False;
mp-wp_genesis 1316 }
mp-wp_genesis 1317 }
mp-wp_genesis 1318
mp-wp_genesis 1319 /**
mp-wp_genesis 1320 * Correctly encodes and wraps long multibyte strings for mail headers
mp-wp_genesis 1321 * without breaking lines within a character.
mp-wp_genesis 1322 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
mp-wp_genesis 1323 * @access private
mp-wp_genesis 1324 * @param string $str multi-byte text to wrap encode
mp-wp_genesis 1325 * @return string
mp-wp_genesis 1326 */
mp-wp_genesis 1327 function Base64EncodeWrapMB($str) {
mp-wp_genesis 1328 $start = "=?".$this->CharSet."?B?";
mp-wp_genesis 1329 $end = "?=";
mp-wp_genesis 1330 $encoded = "";
mp-wp_genesis 1331
mp-wp_genesis 1332 $mb_length = mb_strlen($str, $this->CharSet);
mp-wp_genesis 1333 // Each line must have length <= 75, including $start and $end
mp-wp_genesis 1334 $length = 75 - strlen($start) - strlen($end);
mp-wp_genesis 1335 // Average multi-byte ratio
mp-wp_genesis 1336 $ratio = $mb_length / strlen($str);
mp-wp_genesis 1337 // Base64 has a 4:3 ratio
mp-wp_genesis 1338 $offset = $avgLength = floor($length * $ratio * .75);
mp-wp_genesis 1339
mp-wp_genesis 1340 for ($i = 0; $i < $mb_length; $i += $offset) {
mp-wp_genesis 1341 $lookBack = 0;
mp-wp_genesis 1342
mp-wp_genesis 1343 do {
mp-wp_genesis 1344 $offset = $avgLength - $lookBack;
mp-wp_genesis 1345 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
mp-wp_genesis 1346 $chunk = base64_encode($chunk);
mp-wp_genesis 1347 $lookBack++;
mp-wp_genesis 1348 }
mp-wp_genesis 1349 while (strlen($chunk) > $length);
mp-wp_genesis 1350
mp-wp_genesis 1351 $encoded .= $chunk . $this->LE;
mp-wp_genesis 1352 }
mp-wp_genesis 1353
mp-wp_genesis 1354 // Chomp the last linefeed
mp-wp_genesis 1355 $encoded = substr($encoded, 0, -strlen($this->LE));
mp-wp_genesis 1356 return $encoded;
mp-wp_genesis 1357 }
mp-wp_genesis 1358
mp-wp_genesis 1359 /**
mp-wp_genesis 1360 * Encode string to quoted-printable.
mp-wp_genesis 1361 * @access private
mp-wp_genesis 1362 * @return string
mp-wp_genesis 1363 */
mp-wp_genesis 1364 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
mp-wp_genesis 1365 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
mp-wp_genesis 1366 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
mp-wp_genesis 1367 $eol = "\r\n";
mp-wp_genesis 1368 $escape = '=';
mp-wp_genesis 1369 $output = '';
mp-wp_genesis 1370 while( list(, $line) = each($lines) ) {
mp-wp_genesis 1371 $linlen = strlen($line);
mp-wp_genesis 1372 $newline = '';
mp-wp_genesis 1373 for($i = 0; $i < $linlen; $i++) {
mp-wp_genesis 1374 $c = substr( $line, $i, 1 );
mp-wp_genesis 1375 $dec = ord( $c );
mp-wp_genesis 1376 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
mp-wp_genesis 1377 $c = '=2E';
mp-wp_genesis 1378 }
mp-wp_genesis 1379 if ( $dec == 32 ) {
mp-wp_genesis 1380 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
mp-wp_genesis 1381 $c = '=20';
mp-wp_genesis 1382 } else if ( $space_conv ) {
mp-wp_genesis 1383 $c = '=20';
mp-wp_genesis 1384 }
mp-wp_genesis 1385 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
mp-wp_genesis 1386 $h2 = floor($dec/16);
mp-wp_genesis 1387 $h1 = floor($dec%16);
mp-wp_genesis 1388 $c = $escape.$hex[$h2].$hex[$h1];
mp-wp_genesis 1389 }
mp-wp_genesis 1390 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
mp-wp_genesis 1391 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
mp-wp_genesis 1392 $newline = '';
mp-wp_genesis 1393 // check if newline first character will be point or not
mp-wp_genesis 1394 if ( $dec == 46 ) {
mp-wp_genesis 1395 $c = '=2E';
mp-wp_genesis 1396 }
mp-wp_genesis 1397 }
mp-wp_genesis 1398 $newline .= $c;
mp-wp_genesis 1399 } // end of for
mp-wp_genesis 1400 $output .= $newline.$eol;
mp-wp_genesis 1401 } // end of while
mp-wp_genesis 1402 return trim($output);
mp-wp_genesis 1403 }
mp-wp_genesis 1404
mp-wp_genesis 1405 /**
mp-wp_genesis 1406 * Encode string to q encoding.
mp-wp_genesis 1407 * @access private
mp-wp_genesis 1408 * @return string
mp-wp_genesis 1409 */
mp-wp_genesis 1410 function EncodeQ ($str, $position = 'text') {
mp-wp_genesis 1411 /* There should not be any EOL in the string */
mp-wp_genesis 1412 $encoded = preg_replace("[\r\n]", '', $str);
mp-wp_genesis 1413
mp-wp_genesis 1414 switch (strtolower($position)) {
mp-wp_genesis 1415 case 'phrase':
mp-wp_genesis 1416 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
mp-wp_genesis 1417 break;
mp-wp_genesis 1418 case 'comment':
mp-wp_genesis 1419 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
mp-wp_genesis 1420 case 'text':
mp-wp_genesis 1421 default:
mp-wp_genesis 1422 /* Replace every high ascii, control =, ? and _ characters */
mp-wp_genesis 1423 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
mp-wp_genesis 1424 "'='.sprintf('%02X', ord('\\1'))", $encoded);
mp-wp_genesis 1425 break;
mp-wp_genesis 1426 }
mp-wp_genesis 1427
mp-wp_genesis 1428 /* Replace every spaces to _ (more readable than =20) */
mp-wp_genesis 1429 $encoded = str_replace(' ', '_', $encoded);
mp-wp_genesis 1430
mp-wp_genesis 1431 return $encoded;
mp-wp_genesis 1432 }
mp-wp_genesis 1433
mp-wp_genesis 1434 /**
mp-wp_genesis 1435 * Adds a string or binary attachment (non-filesystem) to the list.
mp-wp_genesis 1436 * This method can be used to attach ascii or binary data,
mp-wp_genesis 1437 * such as a BLOB record from a database.
mp-wp_genesis 1438 * @param string $string String attachment data.
mp-wp_genesis 1439 * @param string $filename Name of the attachment.
mp-wp_genesis 1440 * @param string $encoding File encoding (see $Encoding).
mp-wp_genesis 1441 * @param string $type File extension (MIME) type.
mp-wp_genesis 1442 * @return void
mp-wp_genesis 1443 */
mp-wp_genesis 1444 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
mp-wp_genesis 1445 /* Append to $attachment array */
mp-wp_genesis 1446 $cur = count($this->attachment);
mp-wp_genesis 1447 $this->attachment[$cur][0] = $string;
mp-wp_genesis 1448 $this->attachment[$cur][1] = $filename;
mp-wp_genesis 1449 $this->attachment[$cur][2] = $filename;
mp-wp_genesis 1450 $this->attachment[$cur][3] = $encoding;
mp-wp_genesis 1451 $this->attachment[$cur][4] = $type;
mp-wp_genesis 1452 $this->attachment[$cur][5] = true; // isString
mp-wp_genesis 1453 $this->attachment[$cur][6] = 'attachment';
mp-wp_genesis 1454 $this->attachment[$cur][7] = 0;
mp-wp_genesis 1455 }
mp-wp_genesis 1456
mp-wp_genesis 1457 /**
mp-wp_genesis 1458 * Adds an embedded attachment. This can include images, sounds, and
mp-wp_genesis 1459 * just about any other document. Make sure to set the $type to an
mp-wp_genesis 1460 * image type. For JPEG images use "image/jpeg" and for GIF images
mp-wp_genesis 1461 * use "image/gif".
mp-wp_genesis 1462 * @param string $path Path to the attachment.
mp-wp_genesis 1463 * @param string $cid Content ID of the attachment. Use this to identify
mp-wp_genesis 1464 * the Id for accessing the image in an HTML form.
mp-wp_genesis 1465 * @param string $name Overrides the attachment name.
mp-wp_genesis 1466 * @param string $encoding File encoding (see $Encoding).
mp-wp_genesis 1467 * @param string $type File extension (MIME) type.
mp-wp_genesis 1468 * @return bool
mp-wp_genesis 1469 */
mp-wp_genesis 1470 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
mp-wp_genesis 1471
mp-wp_genesis 1472 if(!@is_file($path)) {
mp-wp_genesis 1473 $this->SetError($this->Lang('file_access') . $path);
mp-wp_genesis 1474 return false;
mp-wp_genesis 1475 }
mp-wp_genesis 1476
mp-wp_genesis 1477 $filename = basename($path);
mp-wp_genesis 1478 if($name == '') {
mp-wp_genesis 1479 $name = $filename;
mp-wp_genesis 1480 }
mp-wp_genesis 1481
mp-wp_genesis 1482 /* Append to $attachment array */
mp-wp_genesis 1483 $cur = count($this->attachment);
mp-wp_genesis 1484 $this->attachment[$cur][0] = $path;
mp-wp_genesis 1485 $this->attachment[$cur][1] = $filename;
mp-wp_genesis 1486 $this->attachment[$cur][2] = $name;
mp-wp_genesis 1487 $this->attachment[$cur][3] = $encoding;
mp-wp_genesis 1488 $this->attachment[$cur][4] = $type;
mp-wp_genesis 1489 $this->attachment[$cur][5] = false;
mp-wp_genesis 1490 $this->attachment[$cur][6] = 'inline';
mp-wp_genesis 1491 $this->attachment[$cur][7] = $cid;
mp-wp_genesis 1492
mp-wp_genesis 1493 return true;
mp-wp_genesis 1494 }
mp-wp_genesis 1495
mp-wp_genesis 1496 /**
mp-wp_genesis 1497 * Returns true if an inline attachment is present.
mp-wp_genesis 1498 * @access private
mp-wp_genesis 1499 * @return bool
mp-wp_genesis 1500 */
mp-wp_genesis 1501 function InlineImageExists() {
mp-wp_genesis 1502 $result = false;
mp-wp_genesis 1503 for($i = 0; $i < count($this->attachment); $i++) {
mp-wp_genesis 1504 if($this->attachment[$i][6] == 'inline') {
mp-wp_genesis 1505 $result = true;
mp-wp_genesis 1506 break;
mp-wp_genesis 1507 }
mp-wp_genesis 1508 }
mp-wp_genesis 1509
mp-wp_genesis 1510 return $result;
mp-wp_genesis 1511 }
mp-wp_genesis 1512
mp-wp_genesis 1513 /////////////////////////////////////////////////
mp-wp_genesis 1514 // CLASS METHODS, MESSAGE RESET
mp-wp_genesis 1515 /////////////////////////////////////////////////
mp-wp_genesis 1516
mp-wp_genesis 1517 /**
mp-wp_genesis 1518 * Clears all recipients assigned in the TO array. Returns void.
mp-wp_genesis 1519 * @return void
mp-wp_genesis 1520 */
mp-wp_genesis 1521 function ClearAddresses() {
mp-wp_genesis 1522 $this->to = array();
mp-wp_genesis 1523 }
mp-wp_genesis 1524
mp-wp_genesis 1525 /**
mp-wp_genesis 1526 * Clears all recipients assigned in the CC array. Returns void.
mp-wp_genesis 1527 * @return void
mp-wp_genesis 1528 */
mp-wp_genesis 1529 function ClearCCs() {
mp-wp_genesis 1530 $this->cc = array();
mp-wp_genesis 1531 }
mp-wp_genesis 1532
mp-wp_genesis 1533 /**
mp-wp_genesis 1534 * Clears all recipients assigned in the BCC array. Returns void.
mp-wp_genesis 1535 * @return void
mp-wp_genesis 1536 */
mp-wp_genesis 1537 function ClearBCCs() {
mp-wp_genesis 1538 $this->bcc = array();
mp-wp_genesis 1539 }
mp-wp_genesis 1540
mp-wp_genesis 1541 /**
mp-wp_genesis 1542 * Clears all recipients assigned in the ReplyTo array. Returns void.
mp-wp_genesis 1543 * @return void
mp-wp_genesis 1544 */
mp-wp_genesis 1545 function ClearReplyTos() {
mp-wp_genesis 1546 $this->ReplyTo = array();
mp-wp_genesis 1547 }
mp-wp_genesis 1548
mp-wp_genesis 1549 /**
mp-wp_genesis 1550 * Clears all recipients assigned in the TO, CC and BCC
mp-wp_genesis 1551 * array. Returns void.
mp-wp_genesis 1552 * @return void
mp-wp_genesis 1553 */
mp-wp_genesis 1554 function ClearAllRecipients() {
mp-wp_genesis 1555 $this->to = array();
mp-wp_genesis 1556 $this->cc = array();
mp-wp_genesis 1557 $this->bcc = array();
mp-wp_genesis 1558 }
mp-wp_genesis 1559
mp-wp_genesis 1560 /**
mp-wp_genesis 1561 * Clears all previously set filesystem, string, and binary
mp-wp_genesis 1562 * attachments. Returns void.
mp-wp_genesis 1563 * @return void
mp-wp_genesis 1564 */
mp-wp_genesis 1565 function ClearAttachments() {
mp-wp_genesis 1566 $this->attachment = array();
mp-wp_genesis 1567 }
mp-wp_genesis 1568
mp-wp_genesis 1569 /**
mp-wp_genesis 1570 * Clears all custom headers. Returns void.
mp-wp_genesis 1571 * @return void
mp-wp_genesis 1572 */
mp-wp_genesis 1573 function ClearCustomHeaders() {
mp-wp_genesis 1574 $this->CustomHeader = array();
mp-wp_genesis 1575 }
mp-wp_genesis 1576
mp-wp_genesis 1577 /////////////////////////////////////////////////
mp-wp_genesis 1578 // CLASS METHODS, MISCELLANEOUS
mp-wp_genesis 1579 /////////////////////////////////////////////////
mp-wp_genesis 1580
mp-wp_genesis 1581 /**
mp-wp_genesis 1582 * Adds the error message to the error container.
mp-wp_genesis 1583 * Returns void.
mp-wp_genesis 1584 * @access private
mp-wp_genesis 1585 * @return void
mp-wp_genesis 1586 */
mp-wp_genesis 1587 function SetError($msg) {
mp-wp_genesis 1588 $this->error_count++;
mp-wp_genesis 1589 $this->ErrorInfo = $msg;
mp-wp_genesis 1590 }
mp-wp_genesis 1591
mp-wp_genesis 1592 /**
mp-wp_genesis 1593 * Returns the proper RFC 822 formatted date.
mp-wp_genesis 1594 * @access private
mp-wp_genesis 1595 * @return string
mp-wp_genesis 1596 */
mp-wp_genesis 1597 function RFCDate() {
mp-wp_genesis 1598 $tz = date('Z');
mp-wp_genesis 1599 $tzs = ($tz < 0) ? '-' : '+';
mp-wp_genesis 1600 $tz = abs($tz);
mp-wp_genesis 1601 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
mp-wp_genesis 1602 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
mp-wp_genesis 1603
mp-wp_genesis 1604 return $result;
mp-wp_genesis 1605 }
mp-wp_genesis 1606
mp-wp_genesis 1607 /**
mp-wp_genesis 1608 * Returns the appropriate server variable. Should work with both
mp-wp_genesis 1609 * PHP 4.1.0+ as well as older versions. Returns an empty string
mp-wp_genesis 1610 * if nothing is found.
mp-wp_genesis 1611 * @access private
mp-wp_genesis 1612 * @return mixed
mp-wp_genesis 1613 */
mp-wp_genesis 1614 function ServerVar($varName) {
mp-wp_genesis 1615 global $HTTP_SERVER_VARS;
mp-wp_genesis 1616 global $HTTP_ENV_VARS;
mp-wp_genesis 1617
mp-wp_genesis 1618 if(!isset($_SERVER)) {
mp-wp_genesis 1619 $_SERVER = $HTTP_SERVER_VARS;
mp-wp_genesis 1620 if(!isset($_SERVER['REMOTE_ADDR'])) {
mp-wp_genesis 1621 $_SERVER = $HTTP_ENV_VARS; // must be Apache
mp-wp_genesis 1622 }
mp-wp_genesis 1623 }
mp-wp_genesis 1624
mp-wp_genesis 1625 if(isset($_SERVER[$varName])) {
mp-wp_genesis 1626 return $_SERVER[$varName];
mp-wp_genesis 1627 } else {
mp-wp_genesis 1628 return '';
mp-wp_genesis 1629 }
mp-wp_genesis 1630 }
mp-wp_genesis 1631
mp-wp_genesis 1632 /**
mp-wp_genesis 1633 * Returns the server hostname or 'localhost.localdomain' if unknown.
mp-wp_genesis 1634 * @access private
mp-wp_genesis 1635 * @return string
mp-wp_genesis 1636 */
mp-wp_genesis 1637 function ServerHostname() {
mp-wp_genesis 1638 if ($this->Hostname != '') {
mp-wp_genesis 1639 $result = $this->Hostname;
mp-wp_genesis 1640 } elseif ($this->ServerVar('SERVER_NAME') != '') {
mp-wp_genesis 1641 $result = $this->ServerVar('SERVER_NAME');
mp-wp_genesis 1642 } else {
mp-wp_genesis 1643 $result = 'localhost.localdomain';
mp-wp_genesis 1644 }
mp-wp_genesis 1645
mp-wp_genesis 1646 return $result;
mp-wp_genesis 1647 }
mp-wp_genesis 1648
mp-wp_genesis 1649 /**
mp-wp_genesis 1650 * Returns a message in the appropriate language.
mp-wp_genesis 1651 * @access private
mp-wp_genesis 1652 * @return string
mp-wp_genesis 1653 */
mp-wp_genesis 1654 function Lang($key) {
mp-wp_genesis 1655 if(count($this->language) < 1) {
mp-wp_genesis 1656 $this->SetLanguage('en'); // set the default language
mp-wp_genesis 1657 }
mp-wp_genesis 1658
mp-wp_genesis 1659 if(isset($this->language[$key])) {
mp-wp_genesis 1660 return $this->language[$key];
mp-wp_genesis 1661 } else {
mp-wp_genesis 1662 return 'Language string failed to load: ' . $key;
mp-wp_genesis 1663 }
mp-wp_genesis 1664 }
mp-wp_genesis 1665
mp-wp_genesis 1666 /**
mp-wp_genesis 1667 * Returns true if an error occurred.
mp-wp_genesis 1668 * @return bool
mp-wp_genesis 1669 */
mp-wp_genesis 1670 function IsError() {
mp-wp_genesis 1671 return ($this->error_count > 0);
mp-wp_genesis 1672 }
mp-wp_genesis 1673
mp-wp_genesis 1674 /**
mp-wp_genesis 1675 * Changes every end of line from CR or LF to CRLF.
mp-wp_genesis 1676 * @access private
mp-wp_genesis 1677 * @return string
mp-wp_genesis 1678 */
mp-wp_genesis 1679 function FixEOL($str) {
mp-wp_genesis 1680 $str = str_replace("\r\n", "\n", $str);
mp-wp_genesis 1681 $str = str_replace("\r", "\n", $str);
mp-wp_genesis 1682 $str = str_replace("\n", $this->LE, $str);
mp-wp_genesis 1683 return $str;
mp-wp_genesis 1684 }
mp-wp_genesis 1685
mp-wp_genesis 1686 /**
mp-wp_genesis 1687 * Adds a custom header.
mp-wp_genesis 1688 * @return void
mp-wp_genesis 1689 */
mp-wp_genesis 1690 function AddCustomHeader($custom_header) {
mp-wp_genesis 1691 $this->CustomHeader[] = explode(':', $custom_header, 2);
mp-wp_genesis 1692 }
mp-wp_genesis 1693
mp-wp_genesis 1694 /**
mp-wp_genesis 1695 * Evaluates the message and returns modifications for inline images and backgrounds
mp-wp_genesis 1696 * @access public
mp-wp_genesis 1697 * @return $message
mp-wp_genesis 1698 */
mp-wp_genesis 1699 function MsgHTML($message,$basedir='') {
mp-wp_genesis 1700 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
mp-wp_genesis 1701 if(isset($images[2])) {
mp-wp_genesis 1702 foreach($images[2] as $i => $url) {
mp-wp_genesis 1703 // do not change urls for absolute images (thanks to corvuscorax)
mp-wp_genesis 1704 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
mp-wp_genesis 1705 $filename = basename($url);
mp-wp_genesis 1706 $directory = dirname($url);
mp-wp_genesis 1707 ($directory == '.')?$directory='':'';
mp-wp_genesis 1708 $cid = 'cid:' . md5($filename);
mp-wp_genesis 1709 $fileParts = split("\.", $filename);
mp-wp_genesis 1710 $ext = $fileParts[1];
mp-wp_genesis 1711 $mimeType = $this->_mime_types($ext);
mp-wp_genesis 1712 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
mp-wp_genesis 1713 if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
mp-wp_genesis 1714 $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
mp-wp_genesis 1715 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
mp-wp_genesis 1716 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
mp-wp_genesis 1717 }
mp-wp_genesis 1718 }
mp-wp_genesis 1719 }
mp-wp_genesis 1720 }
mp-wp_genesis 1721 $this->IsHTML(true);
mp-wp_genesis 1722 $this->Body = $message;
mp-wp_genesis 1723 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
mp-wp_genesis 1724 if ( !empty($textMsg) && empty($this->AltBody) ) {
mp-wp_genesis 1725 $this->AltBody = $textMsg;
mp-wp_genesis 1726 }
mp-wp_genesis 1727 if ( empty($this->AltBody) ) {
mp-wp_genesis 1728 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
mp-wp_genesis 1729 }
mp-wp_genesis 1730 }
mp-wp_genesis 1731
mp-wp_genesis 1732 /**
mp-wp_genesis 1733 * Gets the mime type of the embedded or inline image
mp-wp_genesis 1734 * @access private
mp-wp_genesis 1735 * @return mime type of ext
mp-wp_genesis 1736 */
mp-wp_genesis 1737 function _mime_types($ext = '') {
mp-wp_genesis 1738 $mimes = array(
mp-wp_genesis 1739 'hqx' => 'application/mac-binhex40',
mp-wp_genesis 1740 'cpt' => 'application/mac-compactpro',
mp-wp_genesis 1741 'doc' => 'application/msword',
mp-wp_genesis 1742 'bin' => 'application/macbinary',
mp-wp_genesis 1743 'dms' => 'application/octet-stream',
mp-wp_genesis 1744 'lha' => 'application/octet-stream',
mp-wp_genesis 1745 'lzh' => 'application/octet-stream',
mp-wp_genesis 1746 'exe' => 'application/octet-stream',
mp-wp_genesis 1747 'class' => 'application/octet-stream',
mp-wp_genesis 1748 'psd' => 'application/octet-stream',
mp-wp_genesis 1749 'so' => 'application/octet-stream',
mp-wp_genesis 1750 'sea' => 'application/octet-stream',
mp-wp_genesis 1751 'dll' => 'application/octet-stream',
mp-wp_genesis 1752 'oda' => 'application/oda',
mp-wp_genesis 1753 'pdf' => 'application/pdf',
mp-wp_genesis 1754 'ai' => 'application/postscript',
mp-wp_genesis 1755 'eps' => 'application/postscript',
mp-wp_genesis 1756 'ps' => 'application/postscript',
mp-wp_genesis 1757 'smi' => 'application/smil',
mp-wp_genesis 1758 'smil' => 'application/smil',
mp-wp_genesis 1759 'mif' => 'application/vnd.mif',
mp-wp_genesis 1760 'xls' => 'application/vnd.ms-excel',
mp-wp_genesis 1761 'ppt' => 'application/vnd.ms-powerpoint',
mp-wp_genesis 1762 'wbxml' => 'application/vnd.wap.wbxml',
mp-wp_genesis 1763 'wmlc' => 'application/vnd.wap.wmlc',
mp-wp_genesis 1764 'dcr' => 'application/x-director',
mp-wp_genesis 1765 'dir' => 'application/x-director',
mp-wp_genesis 1766 'dxr' => 'application/x-director',
mp-wp_genesis 1767 'dvi' => 'application/x-dvi',
mp-wp_genesis 1768 'gtar' => 'application/x-gtar',
mp-wp_genesis 1769 'php' => 'application/x-httpd-php',
mp-wp_genesis 1770 'php4' => 'application/x-httpd-php',
mp-wp_genesis 1771 'php3' => 'application/x-httpd-php',
mp-wp_genesis 1772 'phtml' => 'application/x-httpd-php',
mp-wp_genesis 1773 'phps' => 'application/x-httpd-php-source',
mp-wp_genesis 1774 'js' => 'application/x-javascript',
mp-wp_genesis 1775 'swf' => 'application/x-shockwave-flash',
mp-wp_genesis 1776 'sit' => 'application/x-stuffit',
mp-wp_genesis 1777 'tar' => 'application/x-tar',
mp-wp_genesis 1778 'tgz' => 'application/x-tar',
mp-wp_genesis 1779 'xhtml' => 'application/xhtml+xml',
mp-wp_genesis 1780 'xht' => 'application/xhtml+xml',
mp-wp_genesis 1781 'zip' => 'application/zip',
mp-wp_genesis 1782 'mid' => 'audio/midi',
mp-wp_genesis 1783 'midi' => 'audio/midi',
mp-wp_genesis 1784 'mpga' => 'audio/mpeg',
mp-wp_genesis 1785 'mp2' => 'audio/mpeg',
mp-wp_genesis 1786 'mp3' => 'audio/mpeg',
mp-wp_genesis 1787 'aif' => 'audio/x-aiff',
mp-wp_genesis 1788 'aiff' => 'audio/x-aiff',
mp-wp_genesis 1789 'aifc' => 'audio/x-aiff',
mp-wp_genesis 1790 'ram' => 'audio/x-pn-realaudio',
mp-wp_genesis 1791 'rm' => 'audio/x-pn-realaudio',
mp-wp_genesis 1792 'rpm' => 'audio/x-pn-realaudio-plugin',
mp-wp_genesis 1793 'ra' => 'audio/x-realaudio',
mp-wp_genesis 1794 'rv' => 'video/vnd.rn-realvideo',
mp-wp_genesis 1795 'wav' => 'audio/x-wav',
mp-wp_genesis 1796 'bmp' => 'image/bmp',
mp-wp_genesis 1797 'gif' => 'image/gif',
mp-wp_genesis 1798 'jpeg' => 'image/jpeg',
mp-wp_genesis 1799 'jpg' => 'image/jpeg',
mp-wp_genesis 1800 'jpe' => 'image/jpeg',
mp-wp_genesis 1801 'png' => 'image/png',
mp-wp_genesis 1802 'tiff' => 'image/tiff',
mp-wp_genesis 1803 'tif' => 'image/tiff',
mp-wp_genesis 1804 'css' => 'text/css',
mp-wp_genesis 1805 'html' => 'text/html',
mp-wp_genesis 1806 'htm' => 'text/html',
mp-wp_genesis 1807 'shtml' => 'text/html',
mp-wp_genesis 1808 'txt' => 'text/plain',
mp-wp_genesis 1809 'text' => 'text/plain',
mp-wp_genesis 1810 'log' => 'text/plain',
mp-wp_genesis 1811 'rtx' => 'text/richtext',
mp-wp_genesis 1812 'rtf' => 'text/rtf',
mp-wp_genesis 1813 'xml' => 'text/xml',
mp-wp_genesis 1814 'xsl' => 'text/xml',
mp-wp_genesis 1815 'mpeg' => 'video/mpeg',
mp-wp_genesis 1816 'mpg' => 'video/mpeg',
mp-wp_genesis 1817 'mpe' => 'video/mpeg',
mp-wp_genesis 1818 'qt' => 'video/quicktime',
mp-wp_genesis 1819 'mov' => 'video/quicktime',
mp-wp_genesis 1820 'avi' => 'video/x-msvideo',
mp-wp_genesis 1821 'movie' => 'video/x-sgi-movie',
mp-wp_genesis 1822 'doc' => 'application/msword',
mp-wp_genesis 1823 'word' => 'application/msword',
mp-wp_genesis 1824 'xl' => 'application/excel',
mp-wp_genesis 1825 'eml' => 'message/rfc822'
mp-wp_genesis 1826 );
mp-wp_genesis 1827 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
mp-wp_genesis 1828 }
mp-wp_genesis 1829
mp-wp_genesis 1830 /**
mp-wp_genesis 1831 * Set (or reset) Class Objects (variables)
mp-wp_genesis 1832 *
mp-wp_genesis 1833 * Usage Example:
mp-wp_genesis 1834 * $page->set('X-Priority', '3');
mp-wp_genesis 1835 *
mp-wp_genesis 1836 * @access public
mp-wp_genesis 1837 * @param string $name Parameter Name
mp-wp_genesis 1838 * @param mixed $value Parameter Value
mp-wp_genesis 1839 * NOTE: will not work with arrays, there are no arrays to set/reset
mp-wp_genesis 1840 */
mp-wp_genesis 1841 function set ( $name, $value = '' ) {
mp-wp_genesis 1842 if ( isset($this->$name) ) {
mp-wp_genesis 1843 $this->$name = $value;
mp-wp_genesis 1844 } else {
mp-wp_genesis 1845 $this->SetError('Cannot set or reset variable ' . $name);
mp-wp_genesis 1846 return false;
mp-wp_genesis 1847 }
mp-wp_genesis 1848 }
mp-wp_genesis 1849
mp-wp_genesis 1850 /**
mp-wp_genesis 1851 * Read a file from a supplied filename and return it.
mp-wp_genesis 1852 *
mp-wp_genesis 1853 * @access public
mp-wp_genesis 1854 * @param string $filename Parameter File Name
mp-wp_genesis 1855 */
mp-wp_genesis 1856 function getFile($filename) {
mp-wp_genesis 1857 $return = '';
mp-wp_genesis 1858 if ($fp = fopen($filename, 'rb')) {
mp-wp_genesis 1859 while (!feof($fp)) {
mp-wp_genesis 1860 $return .= fread($fp, 1024);
mp-wp_genesis 1861 }
mp-wp_genesis 1862 fclose($fp);
mp-wp_genesis 1863 return $return;
mp-wp_genesis 1864 } else {
mp-wp_genesis 1865 return false;
mp-wp_genesis 1866 }
mp-wp_genesis 1867 }
mp-wp_genesis 1868
mp-wp_genesis 1869 /**
mp-wp_genesis 1870 * Strips newlines to prevent header injection.
mp-wp_genesis 1871 * @access private
mp-wp_genesis 1872 * @param string $str String
mp-wp_genesis 1873 * @return string
mp-wp_genesis 1874 */
mp-wp_genesis 1875 function SecureHeader($str) {
mp-wp_genesis 1876 $str = trim($str);
mp-wp_genesis 1877 $str = str_replace("\r", "", $str);
mp-wp_genesis 1878 $str = str_replace("\n", "", $str);
mp-wp_genesis 1879 return $str;
mp-wp_genesis 1880 }
mp-wp_genesis 1881
mp-wp_genesis 1882 /**
mp-wp_genesis 1883 * Set the private key file and password to sign the message.
mp-wp_genesis 1884 *
mp-wp_genesis 1885 * @access public
mp-wp_genesis 1886 * @param string $key_filename Parameter File Name
mp-wp_genesis 1887 * @param string $key_pass Password for private key
mp-wp_genesis 1888 */
mp-wp_genesis 1889 function Sign($key_filename, $key_pass) {
mp-wp_genesis 1890 $this->sign_key_file = $key_filename;
mp-wp_genesis 1891 $this->sign_key_pass = $key_pass;
mp-wp_genesis 1892 }
mp-wp_genesis 1893
mp-wp_genesis 1894 }
mp-wp_genesis 1895
mp-wp_genesis 1896 ?>