Changeset 45
- Timestamp:
- 05/15/2007 02:13:05 PM (19 months ago)
- Files:
-
- 1 modified
-
branches/1.0/system/libraries/Email.php (modified) (112 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/system/libraries/Email.php
r24 r45 71 71 var $_base_charsets = array('iso-8859-1', 'us-ascii'); 72 72 var $_bit_depths = array('7bit', '8bit'); 73 var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); 73 var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); 74 74 75 75 … … 78 78 * 79 79 * The constructor can be passed an array of config values 80 */ 80 */ 81 81 function CI_Email($config = array()) 82 { 82 { 83 83 if (count($config) > 0) 84 84 { 85 85 $this->initialize($config); 86 } 86 } 87 87 88 88 log_message('debug', "Email Class Initialized"); … … 97 97 * @param array 98 98 * @return void 99 */ 99 */ 100 100 function initialize($config = array()) 101 101 { … … 106 106 { 107 107 $method = 'set_'.$key; 108 108 109 109 if (method_exists($this, $method)) 110 110 { … … 114 114 { 115 115 $this->$key = $val; 116 } 116 } 117 117 } 118 118 } 119 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; 119 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; 120 120 $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; 121 121 } 122 122 123 123 // -------------------------------------------------------------------- 124 124 … … 128 128 * @access public 129 129 * @return void 130 */ 130 */ 131 131 function clear($clear_attachments = FALSE) 132 132 { … … 139 139 $this->_headers = array(); 140 140 $this->_debug_msg = array(); 141 142 $this->_set_header('User-Agent', $this->useragent); 141 142 $this->_set_header('User-Agent', $this->useragent); 143 143 $this->_set_header('Date', $this->_set_date()); 144 144 145 145 if ($clear_attachments !== FALSE) 146 146 { … … 148 148 $this->_attach_type = array(); 149 149 $this->_attach_disp = array(); 150 } 151 } 152 150 } 151 } 152 153 153 // -------------------------------------------------------------------- 154 154 … … 160 160 * @param string 161 161 * @return void 162 */ 162 */ 163 163 function from($from, $name = '') 164 164 { … … 168 168 if ($this->validate) 169 169 $this->validate_email($this->_str_to_array($from)); 170 170 171 171 if ($name != '' && substr($name, 0, 1) != '"') 172 172 { 173 173 $name = '"'.$name.'"'; 174 174 } 175 175 176 176 $this->_set_header('From', $name.' <'.$from.'>'); 177 177 $this->_set_header('Return-Path', '<'.$from.'>'); 178 178 } 179 179 180 180 // -------------------------------------------------------------------- 181 181 … … 187 187 * @param string 188 188 * @return void 189 */ 189 */ 190 190 function reply_to($replyto, $name = '') 191 191 { … … 194 194 195 195 if ($this->validate) 196 $this->validate_email($this->_str_to_array($replyto)); 196 $this->validate_email($this->_str_to_array($replyto)); 197 197 198 198 if ($name == '') … … 209 209 $this->_replyto_flag = TRUE; 210 210 } 211 211 212 212 // -------------------------------------------------------------------- 213 213 … … 218 218 * @param string 219 219 * @return void 220 */ 220 */ 221 221 function to($to) 222 222 { 223 223 $to = $this->_str_to_array($to); 224 224 $to = $this->clean_email($to); 225 225 226 226 if ($this->validate) 227 227 $this->validate_email($to); 228 228 229 229 if ($this->_get_protocol() != 'mail') 230 230 $this->_set_header('To', implode(", ", $to)); … … 238 238 case 'mail' : $this->_recipients = implode(", ", $to); 239 239 break; 240 } 241 } 242 240 } 241 } 242 243 243 // -------------------------------------------------------------------- 244 244 … … 249 249 * @param string 250 250 * @return void 251 */ 251 */ 252 252 function cc($cc) 253 { 253 { 254 254 $cc = $this->_str_to_array($cc); 255 255 $cc = $this->clean_email($cc); … … 259 259 260 260 $this->_set_header('Cc', implode(", ", $cc)); 261 261 262 262 if ($this->_get_protocol() == "smtp") 263 263 $this->_cc_array = $cc; 264 264 } 265 265 266 266 // -------------------------------------------------------------------- 267 267 … … 273 273 * @param string 274 274 * @return void 275 */ 275 */ 276 276 function bcc($bcc, $limit = '') 277 277 { … … 284 284 $bcc = $this->_str_to_array($bcc); 285 285 $bcc = $this->clean_email($bcc); 286 286 287 287 if ($this->validate) 288 288 $this->validate_email($bcc); … … 293 293 $this->_set_header('Bcc', implode(", ", $bcc)); 294 294 } 295 295 296 296 // -------------------------------------------------------------------- 297 297 … … 302 302 * @param string 303 303 * @return void 304 */ 304 */ 305 305 function subject($subject) 306 306 { 307 307 $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); 308 308 $subject = preg_replace("/(\t)/", " ", $subject); 309 310 $this->_set_header('Subject', trim($subject)); 311 } 312 309 310 $this->_set_header('Subject', trim($subject)); 311 } 312 313 313 // -------------------------------------------------------------------- 314 314 … … 319 319 * @param string 320 320 * @return void 321 */ 321 */ 322 322 function message($body) 323 323 { 324 $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); 325 } 326 324 $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); 325 } 326 327 327 // -------------------------------------------------------------------- 328 328 … … 333 333 * @param string 334 334 * @return string 335 */ 335 */ 336 336 function attach($filename, $disposition = 'attachment') 337 { 337 { 338 338 $this->_attach_name[] = $filename; 339 339 $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); … … 350 350 * @param string 351 351 * @return void 352 */ 352 */ 353 353 function _set_header($header, $value) 354 354 { 355 355 $this->_headers[$header] = $value; 356 356 } 357 357 358 358 // -------------------------------------------------------------------- 359 359 … … 364 364 * @param string 365 365 * @return array 366 */ 366 */ 367 367 function _str_to_array($email) 368 368 { 369 369 if ( ! is_array($email)) 370 { 370 { 371 371 if (ereg(',$', $email)) 372 372 $email = substr($email, 0, -1); 373 373 374 374 if (ereg('^,', $email)) 375 $email = substr($email, 1); 376 375 $email = substr($email, 1); 376 377 377 if (ereg(',', $email)) 378 { 378 { 379 379 $x = explode(',', $email); 380 380 $email = array(); 381 381 382 382 for ($i = 0; $i < count($x); $i ++) 383 383 $email[] = trim($x[$i]); 384 384 } 385 385 else 386 { 386 { 387 387 $email = trim($email); 388 388 settype($email, "array"); … … 391 391 return $email; 392 392 } 393 393 394 394 // -------------------------------------------------------------------- 395 395 … … 400 400 * @param string 401 401 * @return void 402 */ 402 */ 403 403 function set_alt_message($str = '') 404 404 { 405 405 $this->alt_message = ($str == '') ? '' : $str; 406 406 } 407 407 408 408 // -------------------------------------------------------------------- 409 409 … … 414 414 * @param string 415 415 * @return void 416 */ 416 */ 417 417 function set_mailtype($type = 'text') 418 418 { 419 419 $this->mailtype = ($type == 'html') ? 'html' : 'text'; 420 420 } 421 421 422 422 // -------------------------------------------------------------------- 423 423 … … 428 428 * @param string 429 429 * @return void 430 */ 430 */ 431 431 function set_wordwrap($wordwrap = TRUE) 432 432 { 433 433 $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; 434 434 } 435 435 436 436 // -------------------------------------------------------------------- 437 437 … … 442 442 * @param string 443 443 * @return void 444 */ 444 */ 445 445 function set_protocol($protocol = 'mail') 446 446 { 447 447 $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); 448 448 } 449 449 450 450 // -------------------------------------------------------------------- 451 451 … … 456 456 * @param integer 457 457 * @return void 458 */ 458 */ 459 459 function set_priority($n = 3) 460 460 { … … 464 464 return; 465 465 } 466 466 467 467 if ($n < 1 OR $n > 5) 468 468 { … … 470 470 return; 471 471 } 472 472 473 473 $this->priority = $n; 474 474 } 475 475 476 476 // -------------------------------------------------------------------- 477 477 … … 482 482 * @param string 483 483 * @return void 484 */ 484 */ 485 485 function set_newline($newline = "\n") 486 486 { 487 if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") 488 { 489 $this->newline = "\n"; 490 return; 491 } 492 493 $this->newline = $newline; 494 } 495 487 $this->newline = 488 ($newline == "\n" OR $newline == "\r\n" OR $newline == "\r") ? 489 $newline: 490 "\n"; 491 } 492 496 493 // -------------------------------------------------------------------- 497 494 … … 501 498 * @access private 502 499 * @return void 503 */ 500 */ 504 501 function _set_boundaries() 505 502 { … … 507 504 $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary 508 505 } 509 506 510 507 // -------------------------------------------------------------------- 511 508 … … 515 512 * @access private 516 513 * @return string 517 */ 514 */ 518 515 function _get_message_id() 519 516 { … … 521 518 $from = str_replace(">", "", $from); 522 519 $from = str_replace("<", "", $from); 523 524 return "<".uniqid('').strstr($from, '@').">"; 525 } 526 520 521 return "<".uniqid('').strstr($from, '@').">"; 522 } 523 527 524 // -------------------------------------------------------------------- 528 525 … … 533 530 * @param bool 534 531 * @return string 535 */ 532 */ 536 533 function _get_protocol($return = true) 537 534 { 538 535 $this->protocol = strtolower($this->protocol); 539 536 $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; 540 537 541 538 if ($return == true) 542 539 return $this->protocol; 543 540 } 544 541 545 542 // -------------------------------------------------------------------- 546 543 … … 551 548 * @param bool 552 549 * @return string 553 */ 550 */ 554 551 function _get_encoding($return = true) 555 { 552 { 556 553 $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; 557 554 558 555 if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) 559 556 $this->_encoding = "8bit"; 560 557 561 558 if ($return == true) 562 559 return $this->_encoding; … … 570 567 * @access private 571 568 * @return string 572 */ 569 */ 573 570 function _get_content_type() 574 { 571 { 575 572 if ($this->mailtype == 'html' && count($this->_attach_name) == 0) 576 573 return 'html'; 577 574 578 575 elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) 579 return 'html-attach'; 580 576 return 'html-attach'; 577 581 578 elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) 582 579 return 'plain-attach'; 583 580 584 581 else return 'plain'; 585 582 } 586 583 587 584 // -------------------------------------------------------------------- 588 585 … … 592 589 * @access public 593 590 * @return string 594 */ 591 */ 595 592 function _set_date() 596 593 { … … 599 596 $timezone = abs($timezone); 600 597 $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; 601 598 602 599 return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); 603 600 } 604 601 605 602 // -------------------------------------------------------------------- 606 603 … … 610 607 * @access private 611 608 * @return string 612 */ 609 */ 613 610 function _get_mime_message() 614 611 { 615 612 return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; 616 613 } 617 614 618 615 // -------------------------------------------------------------------- 619 616 … … 624 621 * @param string 625 622 * @return bool 626 */ 623 */ 627 624 function validate_email($email) 628 { 625 { 629 626 if ( ! is_array($email)) 630 627 { 631 $this->_set_error_message('email_must_be_array'); 628 $this->_set_error_message('email_must_be_array'); 632 629 return FALSE; 633 630 } … … 637 634 if ( ! $this->valid_email($val)) 638 635 { 639 $this->_set_error_message('email_invalid_address', $val); 636
