Changeset 8235 for sandbox/2.5.1-evolucao/library/mime
- Timestamp:
- 10/10/13 11:39:53 (11 years ago)
- Location:
- sandbox/2.5.1-evolucao/library/mime
- Files:
-
- 3 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 -
sandbox/2.5.1-evolucao/library/mime/mimeDecode.php
r7673 r8235 63 63 * This package depends on PEAR to raise errors. 64 64 */ 65 //require_once 'PEAR.php';65 require_once 'PEAR.php'; 66 66 67 67 … … 89 89 * @link http://pear.php.net/package/Mail_mime 90 90 */ 91 class Mail_mimeDecode 91 class Mail_mimeDecode extends PEAR 92 92 { 93 93 /** … … 194 194 * @return object Decoded results 195 195 * @access public 196 */ 196 */ 197 197 function decode($params = null) 198 198 { … … 326 326 327 327 $parts = $this->_boundarySplit($body, $content_type['other']['boundary']); 328 $parts_count = count($parts); 329 for ($i = 0; $i < $parts_count; ++$i) { 328 for ($i = 0; $i < count($parts); $i++) { 330 329 list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]); 331 330 $part = $this->_decode($part_header, $part_body, $default_ctype); … … 337 336 338 337 case 'message/rfc822': 339 340 341 342 338 if ($this->_rfc822_bodies) { 339 $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit'; 340 $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body); 341 } 343 342 $obj = new Mail_mimeDecode($body); 344 343 $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies, … … 348 347 break; 349 348 350 case 'message/delivery-status':351 if(!isset($content_transfer_encoding['value']))352 $content_transfer_encoding['value'] = '7bit';353 $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;354 break;355 356 349 default: 357 350 if(!isset($content_transfer_encoding['value'])) … … 387 380 $return[$prepend . $mime_number] = &$structure; 388 381 } 389 $structure_parts_count = count($structure->parts);390 for ($i = 0; $i < $structure_parts_count; ++$i) { 382 for ($i = 0; $i < count($structure->parts); $i++) { 383 391 384 392 385 if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') { … … 522 515 $escaped = false; 523 516 if ($c == '\\') { 524 ++$i;517 $i++; 525 518 if ($i == $l-1) { // end of string. 526 519 break; … … 536 529 $val = ''; 537 530 $key = trim($key); 538 ++$i;531 $i++; 539 532 continue; 540 533 } … … 548 541 } 549 542 $key .= $c; 550 ++$i;543 $i++; 551 544 continue; 552 545 } … … 557 550 // not in quote yet. 558 551 if ((!strlen($val) || $lq !== false) && $c == ' ' || $c == "\t") { 559 ++$i;552 $i++; 560 553 continue; // skip leading spaces after '=' or after '"' 561 554 } … … 566 559 // but we will handle it as a merged part of the string.. 567 560 $val = !strlen(trim($val)) ? '' : trim($val); 568 ++$i;561 $i++; 569 562 continue; 570 563 } … … 594 587 $key = ''; 595 588 $lq = false; 596 ++$i;589 $i++; 597 590 continue; 598 591 } 599 592 600 593 $val .= $c; 601 ++$i;594 $i++; 602 595 continue; 603 596 } … … 609 602 $lq = $q; 610 603 $q = false; 611 ++$i;604 $i++; 612 605 continue; 613 606 } … … 615 608 // normal char inside of quoted string.. 616 609 $val.= $c; 617 ++$i;610 $i++; 618 611 } 619 612 … … 669 662 670 663 $len = count($tmp) -1; 671 for ($i = 1; $i < $len; ++$i) {664 for ($i = 1; $i < $len; $i++) { 672 665 if (strlen(trim($tmp[$i]))) { 673 666 $parts[] = $tmp[$i]; … … 789 782 function &uudecode($input) 790 783 { 791 792 784 // Find all uuencoded sections 793 785 preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches); 794 786 795 $matches_count = count($matches[3]); 796 for ($j = 0; $j < $matches_count; ++$j) { 787 for ($j = 0; $j < count($matches[3]); $j++) { 797 788 798 789 $str = $matches[3][$j]; … … 801 792 802 793 $file = ''; 803 $str = preg_split( '/\r?\n/', trim($str));794 $str = preg_split("/\r?\n/", trim($str)); 804 795 $strlen = count($str); 805 796 806 for ($i = 0; $i < $strlen; ++$i) {797 for ($i = 0; $i < $strlen; $i++) { 807 798 $pos = 1; 808 799 $d = 0; … … 945 936 // Multiple headers with this name 946 937 if (is_array($headers[$hdr_name])) { 947 $hdr_value_count = count($hdr_value); 948 for ($i = 0; $i < $hdr_value_count; ++$i) { 938 for ($i = 0; $i < count($hdr_value); $i++) { 949 939 $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent); 950 940 } … … 957 947 958 948 if (!empty($input->parts)) { 959 $parts_count = count($input->parts); 960 for ($i = 0; $i < $parts_count; ++$i) { 949 for ($i = 0; $i < count($input->parts); $i++) { 961 950 $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf . 962 951 Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) . -
sandbox/2.5.1-evolucao/library/mime/mimePart.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 : mimePart.php 314695 2011-08-10 07:18:07Z alec$51 * @version CVS: $Id$ 52 52 * @link http://pear.php.net/package/Mail_mime 53 53 */ … … 131 131 */ 132 132 var $_eol = "\r\n"; 133 133 134 134 135 /** … … 156 157 * If not set, 'charset' will be used 157 158 * eol - End of line sequence. Default: "\r\n" 159 * headers - Hash array with additional part headers. Array keys can be 160 * in form of <header_name>:<parameter_name> 158 161 * body_file - Location of file with part's body (instead of $body) 159 162 * … … 166 169 } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat. 167 170 $this->_eol = MAIL_MIMEPART_CRLF; 171 } 172 173 // Additional part headers 174 if (!empty($params['headers']) && is_array($params['headers'])) { 175 $headers = $params['headers']; 168 176 } 169 177 … … 216 224 } 217 225 } 226 227 // header values encoding parameters 228 $h_charset = !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII'; 229 $h_language = !empty($params['language']) ? $params['language'] : null; 230 $h_encoding = !empty($params['name_encoding']) ? $params['name_encoding'] : null; 231 232 218 233 if (!empty($params['filename'])) { 219 234 $headers['Content-Type'] .= ';' . $this->_eol; 220 235 $headers['Content-Type'] .= $this->_buildHeaderParam( 221 'name', $params['filename'], 222 !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 223 !empty($params['language']) ? $params['language'] : null, 224 !empty($params['name_encoding']) ? $params['name_encoding'] : null 236 'name', $params['filename'], $h_charset, $h_language, $h_encoding 225 237 ); 226 238 } … … 232 244 $headers['Content-Disposition'] .= ';' . $this->_eol; 233 245 $headers['Content-Disposition'] .= $this->_buildHeaderParam( 234 'filename', $params['filename'], 235 !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 236 !empty($params['language']) ? $params['language'] : null, 246 'filename', $params['filename'], $h_charset, $h_language, 237 247 !empty($params['filename_encoding']) ? $params['filename_encoding'] : null 238 248 ); 239 249 } 250 251 // add attachment size 252 $size = $this->_body_file ? filesize($this->_body_file) : strlen($body); 253 if ($size) { 254 $headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size; 255 } 240 256 } 241 257 242 258 if (!empty($params['description'])) { 243 259 $headers['Content-Description'] = $this->encodeHeader( 244 'Content-Description', $params['description'], 245 !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII', 246 !empty($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable', 260 'Content-Description', $params['description'], $h_charset, $h_encoding, 247 261 $this->_eol 248 262 ); 263 } 264 265 // Search and add existing headers' parameters 266 foreach ($headers as $key => $value) { 267 $items = explode(':', $key); 268 if (count($items) == 2) { 269 $header = $items[0]; 270 $param = $items[1]; 271 if (isset($headers[$header])) { 272 $headers[$header] .= ';' . $this->_eol; 273 } 274 $headers[$header] .= $this->_buildHeaderParam( 275 $param, $value, $h_charset, $h_language, $h_encoding 276 ); 277 unset($headers[$key]); 278 } 249 279 } 250 280 … … 283 313 $encoded['body'] = ''; 284 314 285 $subparts_count = count($this->_subparts); 286 for ($i = 0; $i < $subparts_count; ++$i) { 315 for ($i = 0; $i < count($this->_subparts); $i++) { 287 316 $encoded['body'] .= '--' . $boundary . $eol; 288 317 $tmp = $this->_subparts[$i]->encode(); 289 if ( PEAR::isError($tmp)) {318 if ($this->_isError($tmp)) { 290 319 return $tmp; 291 320 } … … 310 339 } 311 340 312 if ( PEAR::isError($body)) {341 if ($this->_isError($body)) { 313 342 return $body; 314 343 } … … 340 369 { 341 370 if (file_exists($filename) && !is_writable($filename)) { 342 $err = PEAR::raiseError('File is not writeable: ' . $filename);371 $err = $this->_raiseError('File is not writeable: ' . $filename); 343 372 return $err; 344 373 } 345 374 346 375 if (!($fh = fopen($filename, 'ab'))) { 347 $err = PEAR::raiseError('Unable to open file: ' . $filename);376 $err = $this->_raiseError('Unable to open file: ' . $filename); 348 377 return $err; 349 378 } … … 362 391 } 363 392 364 return PEAR::isError($res) ? $res : $this->_headers;393 return $this->_isError($res) ? $res : $this->_headers; 365 394 } 366 395 … … 394 423 395 424 if (count($this->_subparts)) { 396 $subparts_count = count($this->_subparts); 397 for ($i = 0; $i < $subparts_count; ++$i) { 425 for ($i = 0; $i < count($this->_subparts); $i++) { 398 426 fwrite($fh, $f_eol . '--' . $boundary . $eol); 399 427 $res = $this->_subparts[$i]->_encodePartToFile($fh); 400 if ( PEAR::isError($res)) {428 if ($this->_isError($res)) { 401 429 return $res; 402 430 } … … 413 441 $this->_body_file, $this->_encoding, $fh 414 442 ); 415 if ( PEAR::isError($res)) {443 if ($this->_isError($res)) { 416 444 return $res; 417 445 } … … 429 457 * as the $params argument for constructor. 430 458 * 431 * @return Mail_mimePart A reference to the part you just added. I t is459 * @return Mail_mimePart A reference to the part you just added. In PHP4, it is 432 460 * crucial if using multipart/* in your subparts that 433 461 * you use =& in your script when calling this function, … … 437 465 function &addSubpart($body, $params) 438 466 { 439 $this->_subparts[] = new Mail_mimePart($body, $params);440 return $ this->_subparts[count($this->_subparts) - 1];467 $this->_subparts[] = $part = new Mail_mimePart($body, $params); 468 return $part; 441 469 } 442 470 … … 484 512 { 485 513 if (!is_readable($filename)) { 486 $err = PEAR::raiseError('Unable to read file: ' . $filename);514 $err = $this->_raiseError('Unable to read file: ' . $filename); 487 515 return $err; 488 516 } 489 517 490 518 if (!($fd = fopen($filename, 'rb'))) { 491 $err = PEAR::raiseError('Could not open file: ' . $filename);519 $err = $this->_raiseError('Could not open file: ' . $filename); 492 520 return $err; 493 521 } … … 572 600 } 573 601 */ 574 $lines = preg_split( '/\r?\n/', $input);602 $lines = preg_split("/\r?\n/", $input); 575 603 $escape = '='; 576 604 $output = ''; … … 583 611 $char = $line[$i]; 584 612 $dec = ord($char); 585 ++$i;613 $i++; 586 614 587 615 if (($dec == 32) && (!isset($line[$i]))) { … … 621 649 622 650 /** 623 * Encodes the param ater of a header.651 * Encodes the parameter of a header. 624 652 * 625 653 * @param string $name The name of the header-parameter … … 641 669 // value needs encoding if contains non-ASCII chars or is longer than 78 chars 642 670 if (!preg_match('#[^\x20-\x7E]#', $value)) { 643 $token_regexp = '#([^\x21 ,\x23-\x27,\x2A,\x2B,\x2D'644 . ' ,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';671 $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D' 672 . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#'; 645 673 if (!preg_match($token_regexp, $value)) { 646 674 // token … … 664 692 // RFC2231: 665 693 $encValue = preg_replace_callback( 666 '/([^\x21 ,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])/',694 '/([^\x21\x23\x24\x26\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])/', 667 695 array($this, '_encodeReplaceCallback'), $value 668 696 ); … … 690 718 $value = ''; 691 719 } 692 ++$headCount;720 $headCount++; 693 721 } 694 722 … … 788 816 'resent-from', 'resent-to', 'resent-cc', 'resent-bcc', 789 817 'resent-sender', 'resent-reply-to', 818 'mail-reply-to', 'mail-followup-to', 790 819 'return-receipt-to', 'disposition-notification-to', 791 820 ); … … 809 838 if (!empty($separator)) { 810 839 // Simple e-mail address regexp 811 $email_regexp = '( \S+|("[^\r\n"]+"))@\S+';840 $email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+'; 812 841 813 842 $parts = Mail_mimePart::_explodeQuotedString($separator, $value); … … 923 952 $strlen = strlen($string); 924 953 925 for ($q=$p=$i=0; $i < $strlen; ++$i) {954 for ($q=$p=$i=0; $i < $strlen; $i++) { 926 955 if ($string[$i] == "\"" 927 956 && (empty($string[$i-1]) || $string[$i-1] != "\\") … … 985 1014 $cutpoint = $maxLength; 986 1015 // RFC 2047 specifies that any split header should 987 // be sep erated by a CRLF SPACE.1016 // be separated by a CRLF SPACE. 988 1017 if ($output) { 989 1018 $output .= $eol . ' '; … … 1027 1056 1028 1057 // RFC 2047 specifies that any split header should 1029 // be sep erated by a CRLF SPACE1058 // be separated by a CRLF SPACE 1030 1059 if ($output) { 1031 1060 $output .= $eol . ' '; … … 1105 1134 $prev = ''; 1106 1135 1107 for ($i=1; $i<=$length; ++$i) {1136 for ($i=1; $i<=$length; $i++) { 1108 1137 // See #17311 1109 1138 $chunk = mb_substr($str, $start, $i-$start, $charset); … … 1136 1165 $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/'; 1137 1166 1138 for ($i=0; $i<=$length; ++$i) {1167 for ($i=0; $i<=$length; $i++) { 1139 1168 $char = mb_substr($str, $i, 1, $charset); 1140 1169 // RFC recommends underline (instead of =20) in place of the space … … 1198 1227 } 1199 1228 1229 /** 1230 * PEAR::isError implementation 1231 * 1232 * @param mixed $data Object 1233 * 1234 * @return bool True if object is an instance of PEAR_Error 1235 * @access private 1236 */ 1237 function _isError($data) 1238 { 1239 // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473) 1240 if (is_object($data) && is_a($data, 'PEAR_Error')) { 1241 return true; 1242 } 1243 1244 return false; 1245 } 1246 1247 /** 1248 * PEAR::raiseError implementation 1249 * 1250 * @param $message A text error message 1251 * 1252 * @return PEAR_Error Instance of PEAR_Error 1253 * @access private 1254 */ 1255 function _raiseError($message) 1256 { 1257 // PEAR::raiseError() is not PHP 5.4 compatible 1258 return new PEAR_Error($message); 1259 } 1260 1200 1261 } // End of class
Note: See TracChangeset
for help on using the changeset viewer.