Changeset 8235 for sandbox/2.5.1-evolucao/library/mime/mimePart.php
- Timestamp:
- 10/10/13 11:39:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.