Changeset ee289dc in github for program/lib/Mail/mimePart.php
- Timestamp:
- Jun 13, 2008 3:42:15 PM (5 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- f0d4b72
- Parents:
- 5d725ed
- File:
-
- 1 edited
-
program/lib/Mail/mimePart.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/lib/Mail/mimePart.php
rf294da0 ree289dc 136 136 } 137 137 138 $contentType = array(); 139 $contentDisp = array(); 138 140 foreach ($params as $key => $value) { 139 141 switch ($key) { 140 142 case 'content_type': 141 $headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : ''); 143 $contentType['type'] = $value; 144 //$headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : ''); 142 145 break; 143 146 … … 152 155 153 156 case 'disposition': 154 $ headers['Content-Disposition'] = $value . (isset($dfilename) ? '; filename="' . $dfilename . '"' : '');157 $contentDisp['disp'] = $value; 155 158 break; 156 159 157 160 case 'dfilename': 158 if (isset($headers['Content-Disposition'])) { 159 $headers['Content-Disposition'] .= '; filename="' . $value . '"'; 160 } else { 161 $dfilename = $value; 162 } 161 $contentDisp['filename'] = $value; 162 $contentType['name'] = $value; 163 163 break; 164 164 … … 168 168 169 169 case 'charset': 170 if (isset($headers['Content-Type'])) { 171 $headers['Content-Type'] .= '; charset="' . $value . '"'; 172 } else { 173 $charset = $value; 174 } 175 break; 170 $contentType['charset'] = $value; 171 $contentDisp['charset'] = $value; 172 break; 173 174 case 'language': 175 $contentType['language'] = $value; 176 $contentDisp['language'] = $value; 177 break; 178 179 case 'location': 180 $headers['Content-Location'] = $value; 181 break; 182 176 183 } 177 184 } 178 185 if (isset($contentType['type'])) { 186 $headers['Content-Type'] = $contentType['type']; 187 if (isset($contentType['name'])) { 188 $headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF; 189 $headers['Content-Type'] .= $this->_buildHeaderParam('name', $contentType['name'], 190 isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII', 191 isset($contentType['language']) ? $contentType['language'] : NULL); 192 } elseif (isset($contentType['charset'])) { 193 $headers['Content-Type'] .= "; charset=\"{$contentType['charset']}\""; 194 } 195 } 196 197 198 if (isset($contentDisp['disp'])) { 199 $headers['Content-Disposition'] = $contentDisp['disp']; 200 if (isset($contentDisp['filename'])) { 201 $headers['Content-Disposition'] .= ';' . MAIL_MIMEPART_CRLF; 202 $headers['Content-Disposition'] .= $this->_buildHeaderParam('filename', $contentDisp['filename'], 203 isset($contentDisp['charset']) ? $contentDisp['charset'] : 'US-ASCII', 204 isset($contentDisp['language']) ? $contentDisp['language'] : NULL); 205 } 206 } 207 208 209 210 179 211 // Default content-type 180 212 if (!isset($headers['Content-Type'])) { … … 208 240 $encoded =& $this->_encoded; 209 241 210 if (!empty($this->_subparts)) { 211 // http://pear.php.net/bugs/bug.php?id=13032 212 // srand((double)microtime()*1000000); 242 if (count($this->_subparts)) { 243 srand((double)microtime()*1000000); 213 244 $boundary = '=_' . md5(rand() . microtime()); 214 245 $this->_headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"'; … … 221 252 $headers[] = $key . ': ' . $value; 222 253 } 223 $subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body'] ;254 $subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body'] . MAIL_MIMEPART_CRLF; 224 255 } 225 256 226 $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF . 227 implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) .228 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF;257 $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF . 258 rtrim(implode('--' . $boundary . MAIL_MIMEPART_CRLF , $subparts), MAIL_MIMEPART_CRLF) . MAIL_MIMEPART_CRLF . 259 '--' . $boundary.'--' . MAIL_MIMEPART_CRLF; 229 260 230 261 } else { 231 $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding) . MAIL_MIMEPART_CRLF;262 $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding); 232 263 } 233 264 … … 308 339 $output = ''; 309 340 310 while (list(, $line) = each($lines)){341 while (list(, $line) = each($lines)) { 311 342 312 343 $line = preg_split('||', $line, -1, PREG_SPLIT_NO_EMPTY); … … 318 349 $dec = ord($char); 319 350 320 if (($dec == 32) AND ($i == ($linlen - 1))) { // convert space at eol only351 if (($dec == 32) AND ($i == ($linlen - 1))) { // convert space at eol only 321 352 $char = '=20'; 322 353 323 } elseif (($dec == 9) AND ($i == ($linlen - 1))) { // convert tab at eol only354 } elseif (($dec == 9) AND ($i == ($linlen - 1))) { // convert tab at eol only 324 355 $char = '=09'; 325 } elseif ($dec == 9) {356 } elseif ($dec == 9) { 326 357 ; // Do nothing if a tab. 327 } elseif (($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) {358 } elseif (($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) { 328 359 $char = $escape . strtoupper(sprintf('%02s', dechex($dec))); 360 } elseif (($dec == 46) AND (($newline == '') || ((strlen($newline) + strlen("=2E")) >= $line_max))) { 361 //Bug #9722: convert full-stop at bol, 362 //some Windows servers need this, won't break anything (cipri) 363 //Bug #11731: full-stop at bol also needs to be encoded 364 //if this line would push us over the line_max limit. 365 $char = '=2E'; 329 366 } 330 367 368 //Note, when changing this line, also change the ($dec == 46) 369 //check line, as it mimics this line due to Bug #11731 331 370 if ((strlen($newline) + strlen($char)) >= $line_max) { // MAIL_MIMEPART_CRLF is not counted 332 371 $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay … … 340 379 return $output; 341 380 } 381 382 /** 383 * _buildHeaderParam() 384 * 385 * Encodes the paramater of a header. 386 * 387 * @param $name The name of the header-parameter 388 * @param $value The value of the paramter 389 * @param $charset The characterset of $value 390 * @param $language The language used in $value 391 * @param $maxLength The maximum length of a line. Defauls to 75 392 * 393 * @access private 394 */ 395 function _buildHeaderParam($name, $value, $charset=NULL, $language=NULL, $maxLength=75) 396 { 397 //If we find chars to encode, or if charset or language 398 //is not any of the defaults, we need to encode the value. 399 $shouldEncode = 0; 400 $secondAsterisk = ''; 401 if (preg_match('#([\x80-\xFF]){1}#', $value)) { 402 $shouldEncode = 1; 403 } elseif ($charset && (strtolower($charset) != 'us-ascii')) { 404 $shouldEncode = 1; 405 } elseif ($language && ($language != 'en' && $language != 'en-us')) { 406 $shouldEncode = 1; 407 } 408 if ($shouldEncode) { 409 $search = array('%', ' ', "\t"); 410 $replace = array('%25', '%20', '%09'); 411 $encValue = str_replace($search, $replace, $value); 412 $encValue = preg_replace('#([\x80-\xFF])#e', '"%" . strtoupper(dechex(ord("\1")))', $encValue); 413 $value = "$charset'$language'$encValue"; 414 $secondAsterisk = '*'; 415 } 416 $header = " {$name}{$secondAsterisk}=\"{$value}\"; "; 417 if (strlen($header) <= $maxLength) { 418 return $header; 419 } 420 421 $preLength = strlen(" {$name}*0{$secondAsterisk}=\""); 422 $sufLength = strlen("\";"); 423 $maxLength = MAX(16, $maxLength - $preLength - $sufLength - 2); 424 $maxLengthReg = "|(.{0,$maxLength}[^\%][^\%])|"; 425 426 $headers = array(); 427 $headCount = 0; 428 while ($value) { 429 $matches = array(); 430 $found = preg_match($maxLengthReg, $value, $matches); 431 if ($found) { 432 $headers[] = " {$name}*{$headCount}{$secondAsterisk}=\"{$matches[0]}\""; 433 $value = substr($value, strlen($matches[0])); 434 } else { 435 $headers[] = " {$name}*{$headCount}{$secondAsterisk}=\"{$value}\""; 436 $value = ""; 437 } 438 $headCount++; 439 } 440 $headers = implode(MAIL_MIMEPART_CRLF, $headers) . ';'; 441 return $headers; 442 } 342 443 } // End of class
Note: See TracChangeset
for help on using the changeset viewer.
