Problem/Motivation
In Inmail, we are dealing with mail message processing.
In order to decode email header fields, we use \Drupal\Component\Utility\Unicode::mimeHeaderDecode()
helper.
Encoded header value is defined as:
encoded-field = "=?" charset "?" encoding "?" encoded-text "?="
The helper function assumes that encoding value is given as uppercase and fails to decode the given string when it's provided as lowercase.
RFC 2047 allows those values to be provided as either uppercased or lowercased:
Both 'encoding' and 'charset' names are case-independent. Thus the charset name "ISO-8859-1" is equivalent to "iso-8859-1", and the encoding named "Q" may be spelled either "Q" or "q".
Proposed resolution
Let \Drupal\Component\Utility\Unicode::mimeHeaderDecode()
consider lowercased encoding values as well.
Provide test coverage for lowercased cases.
Remaining tasks
Create patch with test- Review
- Commit
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#27 | raw-interdiff-24-27.txt | 659 bytes | jungle |
#27 | 2822334-8.9.x-27.patch | 3.65 KB | jungle |
#24 | 2822334-24.patch | 3.65 KB | jungle |
Comments
Comment #2
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedProviding a fix and test-only patch.
I wanted to use the existing
providerTestMimeHeader()
, but couldn't get the excepted results asUnicode::mimeHeaderEncode()
always returns uppercased charset/encoding values.Also, it seems this affects all Drupal versions, starting from 4.5 as it was introduced in #32465: mime_decode for core.
Comment #10
Kristen PolPatch applies cleanly to 9.1.x.
Comment #11
jungleThe patch is vaild to 9.1.x, RED/GREEN as expected. Per RFC 2047, the changes are good. And the patch is good to go to me.
Comment #12
quietone CreditAttribution: quietone as a volunteer commentedThe IS looks fine and is up to date, yay! I didn't see any questions unanswered in the issue.
Looking at the patch , I found a few items.
Is this necessary? I don't add an @see in the data providers that I have written.
Needs to use [] syntax. (Shows how old this patch is).
Comment #13
jungleThanks, @quietone for reviewing. Addressing, #12 meanwhile, transferred comments into keys.
Comment #15
quietone CreditAttribution: quietone as a volunteer commentedUsing the comments as key seems to be the trend, and it is helpful.
One more thing.
Since some of the line are greater than 80 chars let's format them like this
which is much easier to read.
Comment #16
jungleThanks! @quietone.
alexpott seems prefer #13
I noticed it. The rule
Drupal.Arrays.Array.LongLineDeclaration
has not been applied in core yet. One liners seem compact and easier to read. Well, addressing.Comment #17
jungleAll are multilines now.
Comment #18
Kristen PolCurious why
ASCII
is used twice.The only other thing is wording. IMO, it would be cleaner to use:
Uppercase
instead ofUpper cased
and
Lowercase
instead ofLower cased
Otherwise Looks RTBC unless any of the items mentioned above should be changed.
1) Patch still applies cleanly.
2) Tests pass.
3) Includes new test to test the issue.
4) Patch addresses issue from issue summary.
5) Feedback from previous comments has been addressed.
6) Title and issue summary are clear.
Comment #19
longwaveAgree with @Kristen Pol about Upper/Lower cased => Uppercase/Lowercase.
Also the new test case seems to be inserted between an existing test case and its data provider; would be better to keep them together and insert the new test after providerTestMimeHeader.
Is it also worth refactoring testMimeHeader() to test the encoding side only? There is some duplication now as both methods test the decoding method with the same set of data.
This would fit better with the other test cases if this was "test.txt" I think, I realise this is copied from the other test but maybe worth changing there too?
Comment #20
jungle@Kristen Pol, @longwave, thanks for reviewing.
See \Drupal\Component\Utility\Unicode::mimeHeaderEncode();
For headers consist of ASCII chars, it returns as the original. Or see http://www.rfc-editor.org/rfc/rfc2047.txt for more information.
Addressing #18, #19 and fixing the wrong indentation above.
Comment #22
jungleRandom fail. Requeued.
Comment #23
longwave> Is it also worth refactoring testMimeHeader() to test the encoding side only?
Thinking again this is out of scope, and an extra two unit test passes don't take any time, so let's leave this alone.
All other review points addressed so RTBC assuming tests pass this time!
Comment #24
jungleThanks @longwave for RTBC-ing!
Sorry missed this.
testMimeHeader()
covers both::mimeHeaderDecode
,::mimeHeaderEncode
previously, nowtestMimeHeaderDecode()
added to test::mimeHeaderDecode
only. Renaming and refactoringtestMimeHeader()
to test::mimeHeaderEncode
only makes sense and it's in scope to me.Addressing, but stay RTBC.
Comment #26
catchCommitted 1c7065d and pushed to 9.1.x. Thanks!
This looks backportable to 9.0.x and 8.9.x, but we're in a freeze so just moving there for now.
Comment #27
jungle@catch, thanks for committing!
The patch in #24 is vailid to 9.0.x. Rerolling one for 8,9.x
Comment #28
jungleTo pair with
providerTestMimeHeaderDecode()
, would be better renamingproviderTestMimeHeader()
toproviderTestMimeHeaderEncode()
, do it in a separate issue as it got committed to 9.1.x already or ignore it -- it does not matter keeping it untouched.Tagging "Needs followup" please if necessary.
Comment #31
larowlanBackported the original patch to 8.9.x
Committed 7f3f6de and pushed to 8.9.x.