-
Notifications
You must be signed in to change notification settings - Fork 100
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
feat: add option skip malformed parts #248
feat: add option skip malformed parts #248
Conversation
I'm in favor of this, will take a bit of time to review, and may hold off merging until after the next release. Edit: or if you think you will have follow-ups, we can merge into a dedicated branch for now |
How about a new ReadEnvelopeWithOptions() function instead of modifying existing ReadEnvelope()? I'd like to add options like:
|
My initial plan for options was like @iredmail describes above, however I think if I designed it today, I'd have a options builder struct with ReadEnvelope/etc as methods on it. This would make it easier for people to mock in tests. The original package funcs could just forward to those methods on a default options object. That being said, I haven't thought about the strategy @dmytrokasianenko-outreach used before, so I will spend some time on it. Probably not this weekend though. Most code would continue to work with that change, but I think I've seen breakage from that type of change in the past. I expect we'd want to go from 0.9 series to 0.10 or 1.0 in that case. |
Probably better solutions could be to use option interfaces, see Uber Go Style Guide for functional options. Mainly:
WDYT? |
90ae0da
to
671b2cb
Compare
Q1: @jhillyerd so that it would be possible to replace some part of the message parsing flow? So that we will have open/close principle in place - open for extension but closed for modifications - closed part would be message parsing orchestration (method ReadParts) which drives boundary reader but the particular steps would be replaceable (use defaults it nothing provided), right? IMO the question is how much of the openings is needed/desired. Q2: would it be possible to introduce custom error for malformed parts so that when processing "problems" it would be possible to get a pointer to the malformed part, type of issue (header, content, etc). Q3: Shouldn't explicitly "skip malformed parts" be part of the default behavior so that after parsing we get some results with references to the failed parts so that we can handle it accordingly, wdyt? |
After giving it some thought, I'm OK with the functional options pattern you are using, and it seems more acceptable in Go than a builder pattern. What I'm not OK with is forcing our users to build their options from scratch for every call to enmime, most users will be using identical options for every parse. Thoughts on making config public (while keeping the fields private)? Edit: I didn't quite grok the interfaces part on the first read, you're right that would be better than public config struct. |
This seems way out of scope for this PR, or even the 1.0 release of enmime.
Probably, but that can come later.
No, this may have security implications for existing users. I expect very few users ever inspect the soft errors enmime returns. |
I have a idea, but it would require API changes: // build parser once, with all configs
p := enmime.NewParser(ops...)
// use multiple times
p.Parse(...)
p.Parse(...) |
A new |
I like that. We could modify the existing ReadEnvelope + ReadParts to use a default set of options (private), so the old API continues to work. |
function will still require to pass options and build config every time you want to parse an email. |
This commit introduces Parser, which allows to configure how MIME will be parsed. Default parser behavior isn't changed - ReadEvelope and ReadParts will work as before. Currently only adding option to skip malformed parts.
671b2cb
to
93f5dfc
Compare
@jhillyerd updated code to use functional options as interfaces and added parser constructor which consumes options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks great, I added one question and a couple changes.
My plan is to merge this into a separate branch, release the final 0.9.x, and then merge this to master in the next week or so. This will kick off 0.10, which I hope will be a rather short series of releases before going 1.0. 🚀
Co-authored-by: James Hillyerd <james@hillyerd.com>
Thanks! This is probably one of the most exciting changes for enmime in years. I'll try to release 0.9.x & merge it to master this week. |
* feat: add option skip malformed parts This commit introduces Parser, which allows to configure how MIME will be parsed. Default parser behavior isn't changed - ReadEnvelope and ReadParts will work as before. Currently only adding option to skip malformed parts. Co-authored-by: Dmytro Kasianenko <dmytro.kasianeneko@outreach.io>
Merged to master |
This PR is proposal for the feature which allows to skip parts that can't be parsed. It won't return error, just add them to "problems"
This can be useful if you need to parse everything what is possible to parse and turned off by default.
For example, we have emails which have body of the email starting at the beginning of the part (without headers). Currently parser returns error, but it can be beneficial to skip this part.