Changeset 8235 for sandbox/2.5.1-evolucao/library/mime/mime.php
- Timestamp:
- 10/10/13 11:39:53 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/library/mime/mime.php
r7673 r8235 49 49 * @copyright 2003-2006 PEAR <pear-group@php.net> 50 50 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 51 * @version CVS: $Id : mime.php 305690 2010-11-23 12:41:00Z alec$51 * @version CVS: $Id$ 52 52 * @link http://pear.php.net/package/Mail_mime 53 53 * … … 64 64 * This package depends on PEAR to raise errors. 65 65 */ 66 require_once dirname(__FILE__).'/../PEAR/PEAR.php';66 require_once 'PEAR.php'; 67 67 68 68 /** … … 73 73 * consist of. 74 74 */ 75 //require_once 'Mail/mimePart.php';75 require_once 'Mail/mimePart.php'; 76 76 77 77 … … 246 246 } else { 247 247 $cont = $this->_file2str($data); 248 if ( PEAR::isError($cont)) {248 if ($this->_isError($cont)) { 249 249 return $cont; 250 250 } … … 255 255 } 256 256 } 257 257 258 return true; 258 259 } … … 287 288 } else { 288 289 $cont = $this->_file2str($data); 289 if ( PEAR::isError($cont)) {290 if ($this->_isError($cont)) { 290 291 return $cont; 291 292 } … … 337 338 $bodyfile = $file; 338 339 } else { 339 if ( PEAR::isError($filedata = $this->_file2str($file))) {340 if ($this->_isError($filedata = $this->_file2str($file))) { 340 341 return $filedata; 341 342 } … … 348 349 349 350 if (!$content_id) { 350 $content_id = md5(uniqid(time()));351 $content_id = preg_replace('/[^0-9a-zA-Z]/', '', uniqid(time(), true)); 351 352 } 352 353 … … 388 389 * @param string $h_charset The character set of the headers e.g. filename 389 390 * If not specified, $charset will be used 391 * @param array $add_headers Additional part headers. Array keys can be in form 392 * of <header_name>:<parameter_name> 390 393 * 391 394 * @return mixed True on success or PEAR_Error object … … 404 407 $f_encoding = null, 405 408 $description = '', 406 $h_charset = null 409 $h_charset = null, 410 $add_headers = array() 407 411 ) { 408 412 $bodyfile = null; … … 414 418 $bodyfile = $file; 415 419 } else { 416 if ( PEAR::isError($filedata = $this->_file2str($file))) {420 if ($this->_isError($filedata = $this->_file2str($file))) { 417 421 return $filedata; 418 422 } 419 423 } 420 424 // Force the name the user supplied, otherwise use $file 421 $filename = ($name ? $name : $this->_basename($file ));425 $filename = ($name ? $name : $this->_basename($file)); 422 426 } else { 423 427 $filedata = $file; … … 427 431 if (!strlen($filename)) { 428 432 $msg = "The supplied filename for the attachment can't be empty"; 429 $err = PEAR::raiseError($msg); 430 return $err; 431 } 432 433 return $this->_raiseError($msg); 434 } 435 433 436 $this->_parts[] = array( 434 437 'body' => $filedata, … … 442 445 'disposition' => $disposition, 443 446 'description' => $description, 447 'add_headers' => $add_headers, 444 448 'name_encoding' => $n_encoding, 445 449 'filename_encoding' => $f_encoding, … … 458 462 * @access private 459 463 */ 460 function &_file2str($file_name)464 function _file2str($file_name) 461 465 { 462 466 // Check state of file and raise an error properly 463 467 if (!file_exists($file_name)) { 464 $err = PEAR::raiseError('File not found: ' . $file_name); 465 return $err; 468 return $this->_raiseError('File not found: ' . $file_name); 466 469 } 467 470 if (!is_file($file_name)) { 468 $err = PEAR::raiseError('Not a regular file: ' . $file_name); 469 return $err; 471 return $this->_raiseError('Not a regular file: ' . $file_name); 470 472 } 471 473 if (!is_readable($file_name)) { 472 $err = PEAR::raiseError('File is not readable: ' . $file_name); 473 return $err; 474 return $this->_raiseError('File is not readable: ' . $file_name); 474 475 } 475 476 … … 497 498 * @access private 498 499 */ 499 function &_addTextPart(&$obj , $text)500 function &_addTextPart(&$obj = null, $text = '') 500 501 { 501 502 $params['content_type'] = 'text/plain'; … … 506 507 if (is_object($obj)) { 507 508 $ret = $obj->addSubpart($text, $params); 508 return $ret;509 509 } else { 510 510 $ret = new Mail_mimePart($text, $params); 511 return $ret; 512 } 511 } 512 513 return $ret; 513 514 } 514 515 … … 523 524 * @access private 524 525 */ 525 function &_addHtmlPart(&$obj )526 function &_addHtmlPart(&$obj = null) 526 527 { 527 528 $params['content_type'] = 'text/html'; … … 532 533 if (is_object($obj)) { 533 534 $ret = $obj->addSubpart($this->_htmlbody, $params); 534 return $ret;535 535 } else { 536 536 $ret = new Mail_mimePart($this->_htmlbody, $params); 537 return $ret; 538 } 537 } 538 539 return $ret; 539 540 } 540 541 … … 549 550 function &_addMixedPart() 550 551 { 551 $params = array();552 552 $params['content_type'] = 'multipart/mixed'; 553 553 $params['eol'] = $this->_build_params['eol']; … … 569 569 * @access private 570 570 */ 571 function &_addAlternativePart(&$obj )571 function &_addAlternativePart(&$obj = null) 572 572 { 573 573 $params['content_type'] = 'multipart/alternative'; … … 575 575 576 576 if (is_object($obj)) { 577 return$obj->addSubpart('', $params);577 $ret = $obj->addSubpart('', $params); 578 578 } else { 579 579 $ret = new Mail_mimePart('', $params); 580 return $ret; 581 } 580 } 581 582 return $ret; 582 583 } 583 584 … … 593 594 * @access private 594 595 */ 595 function &_addRelatedPart(&$obj )596 function &_addRelatedPart(&$obj = null) 596 597 { 597 598 $params['content_type'] = 'multipart/related'; … … 599 600 600 601 if (is_object($obj)) { 601 return$obj->addSubpart('', $params);602 $ret = $obj->addSubpart('', $params); 602 603 } else { 603 604 $ret = new Mail_mimePart('', $params); 604 return $ret; 605 } 605 } 606 607 return $ret; 606 608 } 607 609 … … 679 681 if (!empty($value['description'])) { 680 682 $params['description'] = $value['description']; 683 } 684 if (is_array($value['add_headers'])) { 685 $params['headers'] = $value['add_headers']; 681 686 } 682 687 … … 694 699 * @param string $separation The separation between these two parts. 695 700 * @param array $params The Build parameters passed to the 696 * &get() function. See &getfor more info.701 * get() function. See get() for more info. 697 702 * @param array $headers The extra headers that should be passed 698 * to the &headers() function.703 * to the headers() method. 699 704 * See that function for more info. 700 705 * @param bool $overwrite Overwrite the existing headers with new. … … 712 717 $body = $this->get($params); 713 718 714 if ( PEAR::isError($body)) {719 if ($this->_isError($body)) { 715 720 return $body; 716 721 } 717 722 718 $head = $this->txtHeaders($headers, $overwrite); 719 $mail = $head . $separation . $body; 720 return $mail; 723 return $this->txtHeaders($headers, $overwrite) . $separation . $body; 721 724 } 722 725 … … 726 729 * 727 730 * @param array $params The Build parameters passed to the 728 * &get() function. See &getfor more info.731 * get() method. See get() for more info. 729 732 * 730 733 * @return mixed The e-mail body or PEAR error object … … 742 745 * @param string $filename Output file location 743 746 * @param array $params The Build parameters passed to the 744 * &get() function. See &getfor more info.747 * get() method. See get() for more info. 745 748 * @param array $headers The extra headers that should be passed 746 * to the &headers() function.749 * to the headers() function. 747 750 * See that function for more info. 748 751 * @param bool $overwrite Overwrite the existing headers with new. … … 756 759 // Check state of file and raise an error properly 757 760 if (file_exists($filename) && !is_writable($filename)) { 758 $err = PEAR::raiseError('File is not writable: ' . $filename); 759 return $err; 761 return $this->_raiseError('File is not writable: ' . $filename); 760 762 } 761 763 … … 766 768 767 769 if (!($fh = fopen($filename, 'ab'))) { 768 $err = PEAR::raiseError('Unable to open file: ' . $filename); 769 return $err; 770 return $this->_raiseError('Unable to open file: ' . $filename); 770 771 } 771 772 … … 773 774 $head = $this->txtHeaders($headers, $overwrite, true); 774 775 if (fwrite($fh, $head) === false) { 775 $err = PEAR::raiseError('Error writing to file: ' . $filename); 776 return $err; 776 return $this->_raiseError('Error writing to file: ' . $filename); 777 777 } 778 778 … … 791 791 /** 792 792 * Writes (appends) the complete e-mail body into file. 793 * 793 * 794 794 * @param string $filename Output file location 795 795 * @param array $params The Build parameters passed to the 796 * &get() function. See &getfor more info.796 * get() method. See get() for more info. 797 797 * 798 798 * @return mixed True or PEAR error object … … 804 804 // Check state of file and raise an error properly 805 805 if (file_exists($filename) && !is_writable($filename)) { 806 $err = PEAR::raiseError('File is not writable: ' . $filename); 807 return $err; 806 return $this->_raiseError('File is not writable: ' . $filename); 808 807 } 809 808 … … 814 813 815 814 if (!($fh = fopen($filename, 'ab'))) { 816 $err = PEAR::raiseError('Unable to open file: ' . $filename); 817 return $err; 815 return $this->_raiseError('Unable to open file: ' . $filename); 818 816 } 819 817 … … 838 836 * @access public 839 837 */ 840 function &get($params = null, $filename = null, $skip_head = false)838 function get($params = null, $filename = null, $skip_head = false) 841 839 { 842 840 if (isset($params)) { … … 872 870 $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3'; 873 871 $rep[] = 'url(\1cid:' . $value['cid'] . '\1)'; 874 872 875 873 $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody); 876 874 $this->_html_images[$key]['name'] 877 875 = $this->_basename($this->_html_images[$key]['name']); 878 879 876 } 880 877 } … … 895 892 case !$text && !$html && $attachments: 896 893 $message =& $this->_addMixedPart(); 897 $parts_count = count($this->_parts); 898 for ($i = 0; $i < $parts_count; ++$i) { 894 for ($i = 0; $i < count($this->_parts); $i++) { 899 895 $this->_addAttachmentPart($message, $this->_parts[$i]); 900 896 } … … 904 900 $message =& $this->_addMixedPart(); 905 901 $this->_addTextPart($message, $this->_txtbody); 906 $parts_count = count($this->_parts); 907 for ($i = 0; $i < $parts_count; ++$i) { 902 for ($i = 0; $i < count($this->_parts); $i++) { 908 903 $this->_addAttachmentPart($message, $this->_parts[$i]); 909 904 } … … 932 927 $ht =& $this->_addRelatedPart($message); 933 928 $this->_addHtmlPart($ht); 934 $html_images_count = count($this->_html_images); 935 for ($i = 0; $i < $html_images_count; ++$i) { 929 for ($i = 0; $i < count($this->_html_images); $i++) { 936 930 $this->_addHtmlImagePart($ht, $this->_html_images[$i]); 937 931 } … … 942 936 $message =& $this->_addRelatedPart($null); 943 937 $this->_addHtmlPart($message); 944 $html_images_count = count($this->_html_images); 945 for ($i = 0; $i < $html_images_count; ++$i) { 938 for ($i = 0; $i < count($this->_html_images); $i++) { 946 939 $this->_addHtmlImagePart($message, $this->_html_images[$i]); 947 940 } … … 962 955 $this->_addHtmlPart($message); 963 956 } 964 $html_images_count = count($this->_html_images); 965 for ($i = 0; $i < $html_images_count; ++$i) { 957 for ($i = 0; $i < count($this->_html_images); $i++) { 966 958 $this->_addHtmlImagePart($message, $this->_html_images[$i]); 967 959 } … … 978 970 $this->_addHtmlPart($message); 979 971 } 980 $parts_count = count($this->_parts); 981 for ($i = 0; $i < $parts_count; ++$i) { 972 for ($i = 0; $i < count($this->_parts); $i++) { 982 973 $this->_addAttachmentPart($message, $this->_parts[$i]); 983 974 } 984 975 break; 985 /* 986 * Original: 987 * case $html && $attachments && $html_images: 976 977 case $html && $attachments && $html_images: 988 978 $message =& $this->_addMixedPart(); 989 979 if (isset($this->_txtbody)) { … … 995 985 } 996 986 $this->_addHtmlPart($rel); 997 $html_images_count = count($this->_html_images); 998 for ($i = 0; $i < $html_images_count; ++$i) { 987 for ($i = 0; $i < count($this->_html_images); $i++) { 999 988 $this->_addHtmlImagePart($rel, $this->_html_images[$i]); 1000 989 } 1001 $parts_count = count($this->_parts); 1002 for ($i = 0; $i < $parts_count; ++$i) { 990 for ($i = 0; $i < count($this->_parts); $i++) { 1003 991 $this->_addAttachmentPart($message, $this->_parts[$i]); 1004 992 } 1005 * break;1006 * Alteração feita para que as imagens senjam inseridas junto com os anexos e não em uma alternate part.1007 * Para compatibilização com a fomra do expresso anexar imagens no copo do e-mail1008 *1009 */1010 case $html && $attachments && $html_images:1011 $message =& $this->_addMixedPart();1012 if (isset($this->_txtbody)) {1013 $alt =& $this->_addAlternativePart($message);1014 $this->_addTextPart($alt, $this->_txtbody);1015 } else {1016 $this->_addHtmlPart($message);1017 }1018 1019 $html_images_count = count($this->_html_images);1020 for ($i = 0; $i < $html_images_count; ++$i) {1021 $this->_addHtmlImagePart($message, $this->_html_images[$i]);1022 }1023 $parts_count = count($this->_parts);1024 for ($i = 0; $i < $parts_count; ++$i) {1025 $this->_addAttachmentPart($message, $this->_parts[$i]);1026 }1027 993 break; 1028 /*1029 * Fim da alteração1030 */1031 994 1032 995 } 1033 996 1034 997 if (!isset($message)) { 1035 $ret = null; 1036 return $ret; 998 return null; 1037 999 } 1038 1000 … … 1048 1010 // Append mimePart message headers and body into file 1049 1011 $headers = $message->encodeToFile($filename, $boundary, $skip_head); 1050 if ( PEAR::isError($headers)) {1012 if ($this->_isError($headers)) { 1051 1013 return $headers; 1052 1014 } 1053 1015 $this->_headers = array_merge($this->_headers, $headers); 1054 $ret = null; 1055 return $ret; 1016 return null; 1056 1017 } else { 1057 1018 $output = $message->encode($boundary, $skip_head); 1058 if ( PEAR::isError($output)) {1019 if ($this->_isError($output)) { 1059 1020 return $output; 1060 1021 } 1061 1022 $this->_headers = array_merge($this->_headers, $output['headers']); 1062 $body = $output['body']; 1063 return $body; 1023 return $output['body']; 1064 1024 } 1065 1025 } … … 1079 1039 * @access public 1080 1040 */ 1081 function &headers($xtra_headers = null, $overwrite = false, $skip_content = false)1041 function headers($xtra_headers = null, $overwrite = false, $skip_content = false) 1082 1042 { 1083 1043 // Add mime version header … … 1177 1137 1178 1138 // add parameters 1179 $token_regexp = '#([^\x21 ,\x23-\x27,\x2A,\x2B,\x2D'1180 . ' ,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';1139 $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D' 1140 . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#'; 1181 1141 if (is_array($params)) { 1182 1142 foreach ($params as $name => $value) { … … 1354 1314 function encodeHeader($name, $value, $charset, $encoding) 1355 1315 { 1356 return Mail_mimePart::encodeHeader( 1316 $mime_part = new Mail_mimePart; 1317 return $mime_part->encodeHeader( 1357 1318 $name, $value, $charset, $encoding, $this->_build_params['eol'] 1358 1319 ); … … 1500 1461 } 1501 1462 1463 /** 1464 * PEAR::isError implementation 1465 * 1466 * @param mixed $data Object 1467 * 1468 * @return bool True if object is an instance of PEAR_Error 1469 * @access private 1470 */ 1471 function _isError($data) 1472 { 1473 // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473) 1474 if (is_object($data) && is_a($data, 'PEAR_Error')) { 1475 return true; 1476 } 1477 1478 return false; 1479 } 1480 1481 /** 1482 * PEAR::raiseError implementation 1483 * 1484 * @param $message A text error message 1485 * 1486 * @return PEAR_Error Instance of PEAR_Error 1487 * @access private 1488 */ 1489 function _raiseError($message) 1490 { 1491 // PEAR::raiseError() is not PHP 5.4 compatible 1492 return new PEAR_Error($message); 1493 } 1494 1502 1495 } // End of class
Note: See TracChangeset
for help on using the changeset viewer.