Repository navigation
Keep 8-bit bytes in 7bit and 8bit parts when parsing - #233
Open
dickykuang wants to merge 1 commit into
Open
dickykuang wants to merge 1 commit into
dickykuang wants to merge 1 commit into
Conversation
Mail in the wild often labels UTF-8 text 7bit, or carries a NUL in an 8bit part. Mail.Parsers.RFC2822 raised ArgumentError from the SevenBit/EightBit decoders, so one mislabelled part failed the whole message. RFC 2045 6.2: 7bit and 8bit mean no encoding was applied, so the parser now keeps such a body as it is. The encoders still reject those bytes when called directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this pull request
Mail in the wild sometimes labels 8-bit text as
7bit. A common case is abulk sender whose UTF-8 HTML and text parts say
Content-Transfer-Encoding: 7bitand contain non-breaking spaces or curlyquotes.
Mail.Parsers.RFC2822.parse/2passes such a body toMail.Encoders.SevenBit.decode/1, which raisesArgumentError, "invalid character: 194", so the whole message fails toparse, not just the mislabelled part. The same happens for a NUL in an
8bitpart ("illegal NUL character").RFC 2045 section 6.2 says
7bit,8bitandbinaryall mean that noencoding was applied; the label describes the data, it does not transform
it. This change keeps the encoders as they are (they still reject those
bytes, and their tests still pass) and makes only the parser tolerant: if the
7bitor8bitdecoder rejects a body, the parser keeps the body unchangedand still applies the
charset_handler. Bodies that decoded before decodeexactly as before, including the removal of the encoder's 998-character line
wrapping. Other transfer encodings still raise as before.
If you would rather make
SevenBit.decode/1andEightBit.decode/1lenientthemselves, I'm happy to rework it that way; I left them strict because their
tests expect them to raise.
Tests: two parser tests. One has UTF-8 text in
7bitparts of amultipart/alternative message and checks the charset handler still runs; its
text contains non-breaking spaces and a curly apostrophe, which look like
ordinary characters in the diff. The other has a NUL in an
8bitpart. Bothfail on master with the errors above.
Would a 0.5.3 release with this be possible? We parse inbound mail with this
library and currently lose these messages.