Skip to content

Commit

Permalink
- #17573: Place charset parameter in first line of Content-Type heade…
Browse files Browse the repository at this point in the history
…r (if possible)

git-svn-id: http://svn.php.net/repository/pear/packages/Mail_Mime/trunk@301061 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Aleksander Machniak committed Jul 7, 2010
1 parent 80ff4a1 commit ac08cc4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
40 changes: 23 additions & 17 deletions mimePart.php
Expand Up @@ -215,32 +215,43 @@ function Mail_mimePart($body = '', $params = array())
}
}

// Default content-type
if (empty($c_type['type'])) {
$c_type['type'] = 'text/plain';
}

// Content-Type
if (isset($c_type['type'])) {
if (!empty($c_type['type'])) {
$headers['Content-Type'] = $c_type['type'];
if (isset($c_type['name'])) {
if (!empty($c_type['charset'])) {
$charset = "charset={$c_type['charset']}";
// place charset parameter in the same line, if possible
if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) {
$headers['Content-Type'] .= '; ';
} else {
$headers['Content-Type'] .= ';' . $this->_eol . ' ';
}
$headers['Content-Type'] .= $charset;
}
if (!empty($c_type['name'])) {
$headers['Content-Type'] .= ';' . $this->_eol;
$headers['Content-Type'] .= $this->_buildHeaderParam(
'name', $c_type['name'],
isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII',
'name', $c_type['name'],
isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII',
isset($c_type['language']) ? $c_type['language'] : null,
isset($params['name_encoding']) ? $params['name_encoding'] : null
);
}
if (isset($c_type['charset'])) {
$headers['Content-Type']
.= ';' . $this->_eol . " charset={$c_type['charset']}";
}
}

// Content-Disposition
if (isset($c_disp['disp'])) {
if (!empty($c_disp['disp'])) {
$headers['Content-Disposition'] = $c_disp['disp'];
if (isset($c_disp['filename'])) {
if (!empty($c_disp['filename'])) {
$headers['Content-Disposition'] .= ';' . $this->_eol;
$headers['Content-Disposition'] .= $this->_buildHeaderParam(
'filename', $c_disp['filename'],
isset($c_disp['charset']) ? $c_disp['charset'] : 'US-ASCII',
'filename', $c_disp['filename'],
isset($c_disp['charset']) ? $c_disp['charset'] : 'US-ASCII',
isset($c_disp['language']) ? $c_disp['language'] : null,
isset($params['filename_encoding']) ? $params['filename_encoding'] : null
);
Expand All @@ -256,11 +267,6 @@ function Mail_mimePart($body = '', $params = array())
);
}

// Default content-type
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = 'text/plain';
}

// Default encoding
if (!isset($this->_encoding)) {
$this->_encoding = '7bit';
Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -44,6 +44,7 @@ using RFC2047 and/or RFC2231.</description>
Bugs Fixed:
* Fix double-addition of e-mail domain to content ID in HTML images [alec]
* #17311: Fix multi-octet characters are split across adjacent 'encoded-word's [alec]
* #17573: Place charset parameter in first line of Content-Type header (if possible) [alec]
Implemented Features:
* #17518: Added addTo() method [alec]
</notes>
Expand Down
5 changes: 2 additions & 3 deletions tests/test_Bug_12411.phpt
Expand Up @@ -22,8 +22,7 @@ echo "\n";
echo $enc->_headers['Content-Disposition'];
?>
--EXPECT--
text/plain;
name="=?ISO-8859-1?Q?=C5=9Bciema?=";
charset=ISO-8859-1
text/plain; charset=ISO-8859-1;
name="=?ISO-8859-1?Q?=C5=9Bciema?="
attachment;
filename="=?ISO-8859-1?B?xZtjaWVtYQ==?="
2 changes: 1 addition & 1 deletion tests/test_Bug_13444.phpt
Expand Up @@ -16,7 +16,7 @@ $headCT = $head['Content-Type'];
$headCT = explode(";", $headCT);
$headCT = $headCT[0];

$ct = preg_match_all('|Content-Type: (.*);|', $body, $matches);
$ct = preg_match_all('|Content-Type: ([^;\r\n]+)|', $body, $matches);
print($headCT);
print("\n");
foreach ($matches[1] as $match){
Expand Down
6 changes: 3 additions & 3 deletions tests/test_Bug_15320.phpt
Expand Up @@ -12,6 +12,6 @@ $enc = $m->_addAttachmentPart($root, $m->_parts[0]);
print_r($enc->_headers['Content-Type']);
?>
--EXPECT--
text/plain;
name=file.txt;
charset=ISO-8859-1
text/plain; charset=ISO-8859-1;
name=file.txt

0 comments on commit ac08cc4

Please sign in to comment.