Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and test for miss matched transfer encoding (header says it's quotedprintable when it's not) #23

Closed

Conversation

chris-garrett
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Feb 10, 2017

Coverage Status

Coverage decreased (-0.1%) to 84.742% when pulling fab5a2b on chris-garrett:cg/miss-matched-encoding into 9f8c4e2 on jhillyerd:master.

Copy link
Owner

@jhillyerd jhillyerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution Chris, but I don't think this code is doing what you think it is; see my code comments for why. I think we are going to have to take a different strategy to solve this problem, probably creating a reader that detects invalid bytes and qp encodes them on the fly. It could then wrap contentReader at https://github.com/jhillyerd/enmime/blob/master/part.go#L89

Also, I would prefer it if PRs were submitted against the develop branch - I'm going to add a tl;dr to the contributing guide because I realize it's not clear for people that aren't familiar with git-flow.

if ioerr != nil {

// quoted-printable was not quoted. try raw
if strings.Contains(ioerr.Error(), "quotedprintable: invalid unescaped byte") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it's best to avoid inspecting to the contents of an error string. In this case I don't see an easy way around it though.

https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully (see Never inspect the output of error.Error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted ty.


// quoted-printable was not quoted. try raw
if strings.Contains(ioerr.Error(), "quotedprintable: invalid unescaped byte") {
reader, err := newCharsetReader("utf-8", p.rawReader)
Copy link
Owner

@jhillyerd jhillyerd Feb 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong, but my understanding is that at this point, p.rawReader has already been partially or completely consumed. The plain text portion of the message is lost. Your unit test below seems to confirm that; I will continue my comment there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right. I totally know better.

t.Fatal("Failed to parse MIME:", err)
}

if e.Text != "Stuff" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Stuff" is not the expected text portion of this message, it should be the ~60 lines of text from the Content-Type: text/plain; charset="utf-8" MIME part.

What's happening here is enmime saw that envelope.Text was empty, and down-converted the HTML section to text. That's not what we want.

@@ -917,3 +917,51 @@ func TestEnvelopeHeaders(t *testing.T) {
}
}
}

func TestMissMatchedTransferEncoding(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/MissMatched/Mismatched/

@jhillyerd
Copy link
Owner

I'm going to take a crack at the reader thing, since I've had to implement a couple io.Readers for enmime already...

@jhillyerd
Copy link
Owner

Ok, I've added a quoted-printable cleaning reader in 7706cdf, and isolated the text portion of your slack test case in 7e461ff. Feel free to open a bug if you find more q-p problems.

@jhillyerd jhillyerd closed this Feb 12, 2017
@chris-garrett
Copy link
Contributor Author

Thank you for entertaining my rushed, poorly thought out PR. I will test your changes and let you know if anything crops up. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants