Skip to content

Commit

Permalink
Fix Bug #21255: Boundary gets added twice when using setContentType()
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Nov 17, 2017
1 parent 54a6123 commit 827811d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Mail/mime.php
Expand Up @@ -1163,19 +1163,16 @@ public function setContentType($type, $params = array())
{
$header = $type;

$eol = !empty($this->build_params['eol'])
? $this->build_params['eol'] : "\r\n";
$eol = !empty($this->build_params['eol']) ? $this->build_params['eol'] : "\r\n";

// add parameters
$token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D'
. '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#';
$token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#';

if (is_array($params)) {
foreach ($params as $name => $value) {
if ($name == 'boundary') {
$this->build_params['boundary'] = $value;
}
if (!preg_match($token_regexp, $value)) {
} else if (!preg_match($token_regexp, $value)) {
$header .= ";$eol $name=$value";
} else {
$value = addcslashes($value, '\\"');
Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -90,6 +90,7 @@ using RFC2047 and/or RFC2231.</description>
<file baseinstalldir="Mail" name="test_Bug_21098.phpt" role="test" />
<file baseinstalldir="Mail" name="test_Bug_21205.phpt" role="test" />
<file baseinstalldir="Mail" name="test_Bug_21206.phpt" role="test" />
<file baseinstalldir="Mail" name="test_Bug_21255.phpt" role="test" />
</dir> <!-- /tests -->
<dir name="Mail">
<file baseinstalldir="/" name="mime.php" role="php" />
Expand Down
19 changes: 19 additions & 0 deletions tests/test_Bug_21255.phpt
@@ -0,0 +1,19 @@
--TEST--
Bug #21255 Boundary gets added twice
--SKIPIF--
--FILE--
<?php
include "Mail/mime.php";

$mime = new Mail_mime("\r\n");
$mime->setHTMLBody('html');
$mime->setTXTBody('text');
$mime->setContentType('multipart/alternative', array('boundary' => 'something'));

$msg = $mime->getMessage();

echo substr_count($msg, 'boundary=');

?>
--EXPECT--
1

0 comments on commit 827811d

Please sign in to comment.