minor #33641 Make legacy "wrong" RFC2047 encoding apply only to one header (terjebraten-certua)
This PR was merged into the 4.3 branch.
Discussion
----------
Make legacy "wrong" RFC2047 encoding apply only to one header
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| License | MIT
It says in a comment in the code that "We have to go against RFC 2183/2231 in some areas for interoperability". But I would like that to be the exception and not the rule. As the code was, all parameterized headers except from "Content-Disposition" was not encoded according to RFC 2231.
This change is to make it so that the exception (to not follow the RFC) is for the header "Content-Type" only, and all other parameterized headers will follow the rule of RFC 2231.
The code kind of worked before, because in emails we generally only have two parameterized headers; "Content-Disposition" and "Content-Type". But I think it is a good thing that if another parameterized header would happen to be added, by default it should follow the rule of the RFC and not by default be an exception.
Commits
-------
3817a8b036
Make legacy "wrong" RFC2047 encoding apply only to one header
This commit is contained in:
commit
acca7ad939
@ -38,7 +38,7 @@ final class ParameterizedHeader extends UnstructuredHeader
|
||||
$this->setParameter($k, $v);
|
||||
}
|
||||
|
||||
if ('content-disposition' === strtolower($name)) {
|
||||
if ('content-type' !== strtolower($name)) {
|
||||
$this->encoder = new Rfc2231Encoder();
|
||||
}
|
||||
}
|
||||
|
@ -205,16 +205,25 @@ class ParameterizedHeaderTest extends TestCase
|
||||
$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()
|
||||
@ -234,6 +243,18 @@ class ParameterizedHeaderTest extends TestCase
|
||||
tag. For example:
|
||||
|
||||
From: =?US-ASCII*EN?Q?Keith_Moore?= <moore@cs.utk.edu>
|
||||
|
||||
-- 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';
|
||||
@ -241,7 +262,7 @@ class ParameterizedHeaderTest extends TestCase
|
||||
$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()
|
||||
|
Reference in New Issue
Block a user