Changeset 3138 in subversion for trunk/roundcubemail/program/lib/Mail/mimePart.php
- Timestamp:
- Nov 26, 2009 6:11:27 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/lib/Mail/mimePart.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
