Skip to content

Commit

Permalink
Make legacy "wrong" RFC2047 encoding apply only to one header
Browse files Browse the repository at this point in the history
  • Loading branch information
terjebraten-certua committed Sep 19, 2019
1 parent ed8d050 commit 32f7157
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Header/ParameterizedHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(string $name, string $value, array $parameters = [])
$this->setParameter($k, $v);
}

if ('content-disposition' === strtolower($name)) {
if ('content-type' !== strtolower($name)) {
$this->encoder = new Rfc2231Encoder();
}
}
Expand Down
29 changes: 25 additions & 4 deletions Tests/Header/ParameterizedHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,25 @@ public function testValueAndParamCanBeEncodedIfNonAscii()
$header = new ParameterizedHeader('X-Foo', $value);
$header->setCharset('iso-8859-1');
$header->setParameters(['says' => $value]);
$this->assertEquals('X-Foo: =?'.$header->getCharset().'?Q?fo=8Fbar?=; says="=?'.$header->getCharset().'?Q?fo=8Fbar?="', $header->toString());
$this->assertEquals('X-Foo: =?'.$header->getCharset().'?Q?fo=8Fbar?=; says*='.$header->getCharset()."''fo%8Fbar", $header->toString());
}

public function testParamsAreEncodedWithEncodedWordsIfNoParamEncoderSet()
public function testParamsAreEncodedIfNonAscii()
{
$value = 'fo'.pack('C', 0x8F).'bar';
$header = new ParameterizedHeader('X-Foo', 'bar');
$header->setCharset('iso-8859-1');
$header->setParameters(['says' => $value]);
$this->assertEquals('X-Foo: bar; says="=?'.$header->getCharset().'?Q?fo=8Fbar?="', $header->toString());
$this->assertEquals('X-Foo: bar; says*='.$header->getCharset()."''fo%8Fbar", $header->toString());
}

public function testParamsAreEncodedWithLegacyEncodingEnabled()
{
$value = 'fo'.pack('C', 0x8F).'bar';
$header = new ParameterizedHeader('Content-Type', 'bar');
$header->setCharset('iso-8859-1');
$header->setParameters(['says' => $value]);
$this->assertEquals('Content-Type: bar; says="=?'.$header->getCharset().'?Q?fo=8Fbar?="', $header->toString());
}

public function testLanguageInformationAppearsInEncodedWords()
Expand All @@ -234,14 +243,26 @@ public function testLanguageInformationAppearsInEncodedWords()
tag. For example:
From: =?US-ASCII*EN?Q?Keith_Moore?= <[email protected]>
-- RFC 2047, 5. Use of encoded-words in message headers
...
+ An 'encoded-word' MUST NOT be used in parameter of a MIME
Content-Type or Content-Disposition field, or in any structured
field body except within a 'comment' or 'phrase'.
-- RFC 2047, Appendix - changes since RFC 1522
...
+ clarify that encoded-words are allowed in '*text' fields in both
RFC822 headers and MIME body part headers, but NOT as parameter
values.
*/

$value = 'fo'.pack('C', 0x8F).'bar';
$header = new ParameterizedHeader('X-Foo', $value);
$header->setCharset('iso-8859-1');
$header->setLanguage('en');
$header->setParameters(['says' => $value]);
$this->assertEquals('X-Foo: =?'.$header->getCharset().'*en?Q?fo=8Fbar?=; says="=?'.$header->getCharset().'*en?Q?fo=8Fbar?="', $header->toString());
$this->assertEquals('X-Foo: =?'.$header->getCharset().'*en?Q?fo=8Fbar?=; says*='.$header->getCharset()."'en'fo%8Fbar", $header->toString());
}

public function testSetBody()
Expand Down

0 comments on commit 32f7157

Please sign in to comment.