feat: ability to recover partial content from broken encoding #262
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.
--> Problem
What I did:
I wrote a simple email which has two parts (text/plain and text/html) with base64 encoded data, but with one characteristic: both part contents have one extra base64 character (so they are slightly broken). Instead of having 4*n characters, the contents are (4*n)+1 characters long.
What I expected:
ReadParts() returns the root Part, with a FirstChild, and this one with a NextSibling. FirstChild and NextSibling have the partially decoded base64 data (Content != nil, parser recovers partial data from the parts with broken encoding).
What I got:
ReadParts() returns the root Part, with a FirstChild, and this one with a NextSibling. FirstChild and NextSibling have Content == nil (Parser does not recover partial data)
The reason is that for each part a
base64.CorruptInputError
is thrown, which then is catched bybase64CorruptInputCheck()
, leaving the part content empty and returning nil error (skipMalformedParts
flag on true/false would not change the output).--> Solution
With this particular scenario, in which there are text/plain and text/html contents, I would like to ignore that specific error (base64.CorruptInputError) and to keep the buffer read at that moment.
But the thing is that there might be different preferences (for now on, "policies"). For example:
To solve this, I added a callback function
readPartErrorPolicy
to theParser
type, from which it will be possible to decide when to keep the buffer or not when an error is thrown while reading a part content.Release or branch I am using:
master