Permalink
Browse files

Merge branch 'master' of github.com:pear/Mail_Mime

  • Loading branch information...
alecpl committed Jul 9, 2012
2 parents 23cb5d5 + 2202d28 commit 81ca7efe771f45f1a878effea63129ce9544e78b
View
@@ -387,7 +387,8 @@ function addHTMLImage($file,
* @param string $description Content-Description header
* @param string $h_charset The character set of the headers e.g. filename
* If not specified, $charset will be used
- * @param array $add_headers Additional part headers
+ * @param array $add_headers Additional part headers. Array keys can be in form
+ * of <header_name>:<parameter_name>
*
* @return mixed True on success or PEAR_Error object
* @access public
View
@@ -156,7 +156,8 @@ class Mail_mimePart
* headers_charset - Charset of the headers e.g. filename, description.
* If not set, 'charset' will be used
* eol - End of line sequence. Default: "\r\n"
- * headers - Hash array with additional part headers
+ * headers - Hash array with additional part headers. Array keys can be
+ * in form of <header_name>:<parameter_name>
* body_file - Location of file with part's body (instead of $body)
*
* @access public
@@ -222,13 +223,17 @@ function Mail_mimePart($body = '', $params = array())
$params['headers_charset'] = $params['charset'];
}
}
+
+ // header values encoding parameters
+ $h_charset = !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII';
+ $h_language = !empty($params['language']) ? $params['language'] : null;
+ $h_encoding = !empty($params['name_encoding']) ? $params['name_encoding'] : null;
+
+
if (!empty($params['filename'])) {
$headers['Content-Type'] .= ';' . $this->_eol;
$headers['Content-Type'] .= $this->_buildHeaderParam(
- 'name', $params['filename'],
- !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
- !empty($params['language']) ? $params['language'] : null,
- !empty($params['name_encoding']) ? $params['name_encoding'] : null
+ 'name', $params['filename'], $h_charset, $h_language, $h_encoding
);
}
@@ -238,23 +243,41 @@ function Mail_mimePart($body = '', $params = array())
if (!empty($params['filename'])) {
$headers['Content-Disposition'] .= ';' . $this->_eol;
$headers['Content-Disposition'] .= $this->_buildHeaderParam(
- 'filename', $params['filename'],
- !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
- !empty($params['language']) ? $params['language'] : null,
+ 'filename', $params['filename'], $h_charset, $h_language,
!empty($params['filename_encoding']) ? $params['filename_encoding'] : null
);
}
+
+ // add attachment size
+ $size = $this->_body_file ? filesize($this->_body_file) : strlen($body);
+ if ($size) {
+ $headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size;
+ }
}
if (!empty($params['description'])) {
$headers['Content-Description'] = $this->encodeHeader(
- 'Content-Description', $params['description'],
- !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII',
- !empty($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable',
+ 'Content-Description', $params['description'], $h_charset, $h_encoding,
$this->_eol
);
}
+ // Search and add existing headers' parameters
+ foreach ($headers as $key => $value) {
+ $items = explode(':', $key);
+ if (count($items) == 2) {
+ $header = $items[0];
+ $param = $items[1];
+ if (isset($headers[$header])) {
+ $headers[$header] .= ';' . $this->_eol;
+ }
+ $headers[$header] .= $this->_buildHeaderParam(
+ $param, $value, $h_charset, $h_language, $h_encoding
+ );
+ unset($headers[$key]);
+ }
+ }
+
// Default encoding
if (!isset($this->_encoding)) {
$this->_encoding = '7bit';
View
@@ -29,19 +29,19 @@ using RFC2047 and/or RFC2231.</description>
<email>alec@php.net</email>
<active>yes</active>
</lead>
- <date>2012-05-17</date>
+ <date>2012-06-09</date>
<version>
- <release>1.8.4</release>
- <api>1.4.2</api>
+ <release>1.8.5</release>
+ <api>1.4.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
<notes>
- * Request #19406: Allow to set individual attachment part headers [alec]
- * Fixed Bug #18982: Non-static method Mail_mimePart::encodeHeader() should not be called statically [alec]
+ * Added possibility to set additional parameters of message part header, e.g. attachment size [alec]
+ * Added automatic setting of attachment size via Content-Disposition header size parameter [alec]
</notes>
<contents>
<dir name="/">
@@ -636,5 +636,21 @@ Bugs Fixed:
* Fixed Bug #19328: Wrong encoding of filenames with comma [alec]
</notes>
</release>
+ <release>
+ <date>2012-05-17</date>
+ <version>
+ <release>1.8.4</release>
+ <api>1.4.2</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
+ <notes>
+ * Request #19406: Allow to set individual attachment part headers [alec]
+ * Fixed Bug #18982: Non-static method Mail_mimePart::encodeHeader() should not be called statically [alec]
+ </notes>
+ </release>
</changelog>
</package>
@@ -24,4 +24,5 @@ echo $enc->_headers['Content-Disposition'];
text/plain; charset=ISO-8859-1;
name="=?ISO-8859-1?Q?=C5=9Bciema?="
attachment;
- filename="=?ISO-8859-1?B?xZtjaWVtYQ==?="
+ filename="=?ISO-8859-1?B?xZtjaWVtYQ==?=";
+ size=8
@@ -15,4 +15,5 @@ print_r($enc->_headers['Content-Disposition']);
?>
--EXPECT--
attachment;
- filename*=ISO-8859-1''%C5%9Bciema
+ filename*=ISO-8859-1''%C5%9Bciema;
+ size=8
@@ -22,4 +22,5 @@ echo $enc->_headers['Content-Disposition'];
text/plain; charset=ISO-8859-1;
name="=?UTF-8?Q?=C5=9Bciema?="
attachment;
- filename="=?UTF-8?B?xZtjaWVtYQ==?="
+ filename="=?UTF-8?B?xZtjaWVtYQ==?=";
+ size=8
@@ -12,4 +12,5 @@ $enc = $Mime->_addAttachmentPart($root, $Mime->_parts[0]);
print($enc->_headers['Content-Disposition']);
--EXPECT--
attachment;
- filename*=ISO-8859-1''F%F3%F3b%E6r.txt
+ filename*=ISO-8859-1''F%F3%F3b%E6r.txt;
+ size=8
@@ -13,4 +13,5 @@ print($enc->_headers['Content-Disposition']);
--EXPECT--
attachment;
filename*0*=UTF-8'de'S%C3%BCper%20gr%C3%B6se%20tolle%20tolle%20gr%C3%BC;
- filename*1*=%C3%9Fe.txt
+ filename*1*=%C3%9Fe.txt;
+ size=8
@@ -15,4 +15,6 @@ print($enc->_headers['Content-Disposition']);
?>
--EXPECT--
attachment;
- filename*=iso-2022-jp''%1B$BF|K%5C8l%1B%28B.txt
+ filename*=iso-2022-jp''%1B$BF|K%5C8l%1B%28B.txt;
+ size=8
+

0 comments on commit 81ca7ef

Please sign in to comment.