Changeset 3138 in subversion
- Timestamp:
- Nov 26, 2009 6:11:27 AM (3 years ago)
- Location:
- trunk/roundcubemail/program/lib/Mail
- Files:
-
- 2 edited
-
mime.php (modified) (24 diffs)
-
mimePart.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/lib/Mail/mime.php
r2009 r3138 333 333 $c_type = 'application/octet-stream', 334 334 $name = '', 335 $isfile= true,335 $isfile = true, 336 336 $encoding = 'base64', 337 337 $disposition = 'attachment', 338 338 $charset = '', 339 $language= '',339 $language = '', 340 340 $location = '', 341 $n_encoding = NULL, 342 $f_encoding = NULL) 343 { 344 $filedata = ($isfile === true) ? $this->_file2str($file) 345 : $file; 341 $n_encoding = NULL, 342 $f_encoding = NULL) 343 { 344 $filedata = ($isfile === true) ? $this->_file2str($file) : $file; 345 346 if (PEAR::isError($filedata)) { 347 return $filedata; 348 } 349 346 350 if ($isfile === true) { 347 351 // Force the name the user supplied, otherwise use $file … … 356 360 } 357 361 $filename = $this->_basename($filename); 358 if (PEAR::isError($filedata)) {359 return $filedata;360 }361 362 362 363 $this->_parts[] = array( … … 369 370 'location' => $location, 370 371 'disposition' => $disposition, 371 'name-encoding'=> $n_encoding,372 'filename-encoding'=> $f_encoding372 'name-encoding' => $n_encoding, 373 'filename-encoding' => $f_encoding 373 374 ); 374 375 return true; … … 398 399 return $err; 399 400 } 400 401 401 402 //Temporarily reset magic_quotes_runtime and read file contents 402 403 if ($magic_quote_setting = get_magic_quotes_runtime()) { 403 404 set_magic_quotes_runtime(0); 404 405 } 405 $cont = file_get_contents($file_name); 406 $cont = file_get_contents($file_name); 406 407 if ($magic_quote_setting) { 407 408 set_magic_quotes_runtime($magic_quote_setting); 408 409 } 409 410 410 411 return $cont; 411 412 } … … 472 473 $params = array(); 473 474 $params['content_type'] = 'multipart/mixed'; 474 475 475 476 //Create empty multipart/mixed Mail_mimePart object to return 476 477 $ret = new Mail_mimePart('', $params); … … 539 540 $params['dfilename'] = $value['name']; 540 541 $params['cid'] = $value['cid']; 541 if ($value['name-encoding']) { 542 $params['name-encoding'] = $value['name-encoding']; 543 } 544 if ($value['filename-encoding']) { 545 $params['filename-encoding'] = $value['filename-encoding']; 546 } 547 542 543 if (!empty($value['name-encoding'])) { 544 $params['name-encoding'] = $value['name-encoding']; 545 } 546 if (!empty($value['filename-encoding'])) { 547 $params['filename-encoding'] = $value['filename-encoding']; 548 } 549 548 550 $ret = $obj->addSubpart($value['body'], $params); 549 551 return $ret; 550 552 551 553 } 552 554 … … 574 576 $params['location'] = $value['location']; 575 577 } 576 if ($value['name-encoding']) {577 $params['name-encoding'] = $value['name-encoding'];578 }579 if ($value['filename-encoding']) {580 $params['filename-encoding'] = $value['filename-encoding'];581 }578 if ($value['name-encoding']) { 579 $params['name-encoding'] = $value['name-encoding']; 580 } 581 if ($value['filename-encoding']) { 582 $params['filename-encoding'] = $value['filename-encoding']; 583 } 582 584 $params['content_type'] = $value['c_type']; 583 585 $params['disposition'] = isset($value['disposition']) ? … … 606 608 */ 607 609 function getMessage( 608 $separation = null, 609 $build_params = null, 610 $xtra_headers = null, 610 $separation = null, 611 $build_params = null, 612 $xtra_headers = null, 611 613 $overwrite = false 612 614 ) … … 659 661 } 660 662 } 661 663 662 664 if (isset($this->_headers['From'])){ 663 665 //Bug #11381: Illegal characters in domain ID … … 671 673 } 672 674 } 673 675 674 676 if (count($this->_html_images) AND isset($this->_htmlbody)) { 675 677 foreach ($this->_html_images as $key => $value) { … … 685 687 686 688 $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody); 687 $this->_html_images[$key]['name'] = 689 $this->_html_images[$key]['name'] = 688 690 $this->_basename($this->_html_images[$key]['name']); 689 691 } … … 776 778 if (isset($message)) { 777 779 $output = $message->encode(); 778 780 779 781 $this->_headers = array_merge($this->_headers, 780 782 $output['headers']); … … 832 834 { 833 835 $headers = $this->headers($xtra_headers, $overwrite); 834 836 835 837 $ret = ''; 836 838 foreach ($headers as $key => $val) { … … 944 946 //Note: Atom as specified here is not exactly the same as an RFC822 atom, 945 947 //as $atom's may contain just a single space. 946 947 $useIconv = true; 948 949 $useIconv = true; 948 950 if (isset($build_params['ignore-iconv'])) { 949 951 $useIconv = !$build_params['ignore-iconv']; 950 } 952 } 951 953 foreach ($input as $hdr_name => $hdr_value) { 952 954 /* … … 978 980 $imePrefs['line-length'] = 74; 979 981 $imePrefs['line-break-chars'] = "\r\n"; //Specified in RFC2047 980 982 981 983 $hdr_value = iconv_mime_encode($hdr_name, $hdr_value, $imePrefs); 982 984 $hdr_value = preg_replace("#^{$hdr_name}\:\ #", "", $hdr_value); … … 985 987 //Base64 encode the entire string 986 988 $hdr_value = base64_encode($hdr_value); 987 989 988 990 //Generate the header using the specified params and dynamicly 989 991 //determine the maximum length of such strings. … … 1001 1003 $maxLength = $maxLength - ($maxLength % 4); 1002 1004 $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4); 1003 1005 1004 1006 $cutpoint = $maxLength1stLine; 1005 1007 $hdr_value_out = $hdr_value; … … 1010 1012 $hdr_value_out = substr($hdr_value_out, $cutpoint); 1011 1013 $cutpoint = $maxLength; 1012 //RFC 2047 specifies that any split header should 1014 //RFC 2047 specifies that any split header should 1013 1015 //be seperated by a CRLF SPACE. 1014 1016 if ($output) { 1015 $output .= "\r\n ";1017 $output .= "\r\n "; 1016 1018 } 1017 1019 $output .= $prefix . $part . $suffix; … … 1037 1039 $quoteSuffix = '"'; 1038 1040 } 1039 1041 1040 1042 //Generate the header using the specified params and dynamicly 1041 1043 //determine the maximum length of such strings. … … 1049 1051 $maxLength1stLine = $maxLength - strlen($hdr_name) - 2; 1050 1052 $maxLength = $maxLength - 1; 1051 1053 1052 1054 //Replace all special characters used by the encoder. 1053 1055 $search = array('=', '_', '?', ' '); 1054 1056 $replace = array('=3D', '=5F', '=3F', '_'); 1055 1057 $hdr_value = str_replace($search, $replace, $hdr_value); 1056 1058 1057 1059 //Replace all extended characters (\x80-xFF) with their 1058 1060 //ASCII values. … … 1068 1070 //Concat the double quotes and encoded string together 1069 1071 $hdr_value = $quotePrefix . $hdr_value . $quoteSuffix; 1070 1072 1071 1073 $hdr_value_out = $hdr_value; 1072 1074 $realMax = $maxLength1stLine + strlen($prefix . $suffix); … … 1079 1081 //But make sure not to break any translated chars. 1080 1082 $found = preg_match($reg, $hdr_value_out, $matches); 1081 1083 1082 1084 //After this first line, we need to use a different 1083 1085 //regexp for the first line. 1084 1086 $reg = $reg2nd; 1085 1087 1086 1088 //Save the found part and encapsulate it in the 1087 1089 //prefix & suffix. Then remove the part from the … … 1095 1097 $hdr_value_out = ""; 1096 1098 } 1097 1099 1098 1100 //RFC 2047 specifies that any split header should 1099 1101 //be seperated by a CRLF SPACE 1100 1102 if ($output) { 1101 $output .= "\r\n ";1103 $output .= "\r\n "; 1102 1104 } 1103 1105 $output .= $prefix . $part . $suffix; … … 1141 1143 function _basename($filename) 1142 1144 { 1143 // basename() is not unicode safe and locale dependent1144 if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware'))1145 return preg_replace('/^.*[\\\\\\/]/', '', $filename);1146 else1147 return preg_replace('/^.*[\/]/', '', $filename);1145 // basename() is not unicode safe and locale dependent 1146 if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) 1147 return preg_replace('/^.*[\\\\\\/]/', '', $filename); 1148 else 1149 return preg_replace('/^.*[\/]/', '', $filename); 1148 1150 } 1149 1151 -
trunk/roundcubemail/program/lib/Mail/mimePart.php
r3088 r3138 183 183 } 184 184 } 185 185 186 186 if (isset($contentType['type'])) { 187 187 $headers['Content-Type'] = $contentType['type']; 188 if (isset($contentType['charset'])) {188 if (isset($contentType['charset'])) { 189 189 $headers['Content-Type'] .= "; charset={$contentType['charset']}"; 190 190 } … … 192 192 $headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF; 193 193 $headers['Content-Type'] .= 194 $this->_buildHeaderParam('name', $contentType['name'], 195 isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII', 194 $this->_buildHeaderParam('name', $contentType['name'], 195 isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII', 196 196 isset($contentType['language']) ? $contentType['language'] : NULL, 197 isset($params['name-encoding']) ? $params['name-encoding'] : NULL);197 isset($params['name-encoding']) ? $params['name-encoding'] : NULL); 198 198 } 199 199 } … … 205 205 $headers['Content-Disposition'] .= ';' . MAIL_MIMEPART_CRLF; 206 206 $headers['Content-Disposition'] .= 207 $this->_buildHeaderParam('filename', $contentDisp['filename'], 208 isset($contentDisp['charset']) ? $contentDisp['charset'] : 'US-ASCII', 207 $this->_buildHeaderParam('filename', $contentDisp['filename'], 208 isset($contentDisp['charset']) ? $contentDisp['charset'] : 'US-ASCII', 209 209 isset($contentDisp['language']) ? $contentDisp['language'] : NULL, 210 isset($params['filename-encoding']) ? $params['filename-encoding'] : NULL);210 isset($params['filename-encoding']) ? $params['filename-encoding'] : NULL); 211 211 } 212 212 } … … 258 258 259 259 $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF . 260 implode('--' . $boundary . MAIL_MIMEPART_CRLF , $subparts) .261 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF;260 implode('--' . $boundary . MAIL_MIMEPART_CRLF , $subparts) . 261 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF; 262 262 263 263 } else { … … 399 399 { 400 400 // RFC 2045: 401 // value needs encoding if contains non-ASCII chars or is longer than 78 chars401 // value needs encoding if contains non-ASCII chars or is longer than 78 chars 402 402 if (!preg_match('#[^\x20-\x7E]#', $value)) { // ASCII 403 // token 404 if (!preg_match('#([^\x21,\x23-\x27,\x2A,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#', $value)) { 405 if (strlen($name) + strlen($value) + 3 <= $maxLength) 406 return " {$name}={$value};"; 407 } else { // quoted-string 408 $quoted = addcslashes($value, '\\"'); 409 if (strlen($name) + strlen($quoted) + 5 <= $maxLength) 410 return " {$name}=\"{$quoted}\";"; 411 } 412 } 413 414 // RFC2047: use quoted-printable/base64 encoding 415 if ($paramEnc == 'quoted-printable' || $paramEnc == 'base64') 416 return $this->_buildRFC2047Param($name, $value, $charset, $paramEnc); 417 418 // RFC2231: 419 $encValue = preg_replace('#([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#e', 420 '"%" . strtoupper(dechex(ord("\1")))', $value); 403 // token 404 if (!preg_match('#([^\x21,\x23-\x27,\x2A,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#', $value)) { 405 if (strlen($name) + strlen($value) + 3 <= $maxLength) 406 return " {$name}={$value};"; 407 } else { // quoted-string 408 $quoted = addcslashes($value, '\\"'); 409 if (strlen($name) + strlen($quoted) + 5 <= $maxLength) 410 return " {$name}=\"{$quoted}\";"; 411 } 412 } 413 414 // RFC2047: use quoted-printable/base64 encoding 415 if ($paramEnc == 'quoted-printable' || $paramEnc == 'base64') 416 return $this->_buildRFC2047Param($name, $value, $charset, $paramEnc); 417 418 // RFC2231: 419 $encValue = preg_replace( 420 '#([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#e', 421 '"%" . strtoupper(dechex(ord("\1")))', 422 $value); 421 423 $value = "$charset'$language'$encValue"; 422 424 … … 462 464 function _buildRFC2047Param($name, $value, $charset, $encoding='quoted-printable', $maxLength=75) 463 465 { 464 // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in465 // parameter of a MIME Content-Type or Content-Disposition field"466 // but... it's supported by many clients/servers467 468 if ($encoding == 'base64')469 {470 $value = base64_encode($value);466 // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in 467 // parameter of a MIME Content-Type or Content-Disposition field" 468 // but... it's supported by many clients/servers 469 470 if ($encoding == 'base64') 471 { 472 $value = base64_encode($value); 471 473 $prefix = '=?' . $charset . '?B?'; 472 474 $suffix = '?='; 473 $quoted = '';474 475 $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';'476 $len = $add_len + strlen($value);477 478 while ($len > $maxLength) {479 // We can cut base64-encoded string every 4 characters480 $real_len = floor(($maxLength - $add_len) / 4) * 4;481 $_quote = substr($value, 0, $real_len);482 $value = substr($value, $real_len);483 484 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' ';485 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'486 $len = strlen($value) + $add_len;487 } 475 $quoted = ''; 476 477 $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 478 $len = $add_len + strlen($value); 479 480 while ($len > $maxLength) { 481 // We can cut base64-encoded string every 4 characters 482 $real_len = floor(($maxLength - $add_len) / 4) * 4; 483 $_quote = substr($value, 0, $real_len); 484 $value = substr($value, $real_len); 485 486 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 487 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 488 $len = strlen($value) + $add_len; 489 } 488 490 $quoted .= $prefix . $value . $suffix; 489 491 490 492 } 491 else // quoted-printable492 {493 // Replace all special characters used by the encoder.493 else // quoted-printable 494 { 495 // Replace all special characters used by the encoder. 494 496 $search = array('=', '_', '?', ' '); 495 $replace = array('=3D', '=5F', '=3F', '_');496 $value = str_replace($search, $replace, $value);497 498 // Replace all extended characters (\x80-xFF) with their499 // ASCII values.500 $value = preg_replace('/([\x80-\xFF])/e', 501 '"=" . strtoupper(dechex(ord("\1")))', $value);497 $replace = array('=3D', '=5F', '=3F', '_'); 498 $value = str_replace($search, $replace, $value); 499 500 // Replace all extended characters (\x80-xFF) with their 501 // ASCII values. 502 $value = preg_replace('/([\x80-\xFF])/e', 503 '"=" . strtoupper(dechex(ord("\1")))', $value); 502 504 503 505 $prefix = '=?' . $charset . '?Q?'; 504 506 $suffix = '?='; 505 507 506 $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';'507 $len = $add_len + strlen($value);508 509 while ($len > $maxLength) { 510 $length = $maxLength - $add_len;511 // not break any encoded letters512 if(preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches))513 $_quote = $matches[1];514 515 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' ';516 $value = substr($value, strlen($_quote));517 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'518 $len = strlen($value) + $add_len;519 }520 521 $quoted .= $prefix . $value . $suffix;508 $add_len = strlen($prefix . $suffix) + strlen($name) + 6; // 2 x SPACE, 2 x '"', '=', ';' 509 $len = $add_len + strlen($value); 510 511 while ($len > $maxLength) { 512 $length = $maxLength - $add_len; 513 // not break any encoded letters 514 if(preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) 515 $_quote = $matches[1]; 516 517 $quoted .= $prefix . $_quote . $suffix . MAIL_MIMEPART_CRLF . ' '; 518 $value = substr($value, strlen($_quote)); 519 $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';' 520 $len = strlen($value) + $add_len; 521 } 522 523 $quoted .= $prefix . $value . $suffix; 522 524 } 523 525
Note: See TracChangeset
for help on using the changeset viewer.
