-
Couldn't load subscription status.
- Fork 17
Export letters.ParseHeaders() so that a message can be parsed into letters.Headers only
#85
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
Conversation
…ail headers only. Add test. Update README.md.
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.
Nice simple fix!
I agree that it would be a (small) usability improvent if ParseHeaders() accepted the same parameters as ParseEmail(), thus hiding the ReadMessage() logic from the user.
Curious if there are any pros to delegating the ReadMessage() task to the client. Do we foresee a scenario where the intermediate object msg is required elsewhere?
|
Thank you for the review, @ValleyCrisps 🙇 @rorycl raised good points in the discussion here #64, where they mentioned that
and in one more place that I cannot find now (not sure if it was a PR comment that was deleted or if I lost track of one thread), where @rorycl said that
I think it is a very good point. This might be a minor point, but I still have some objections against a Generally, I think that options of the form My current thinking is that we should refactor The default behaviour stays the same: the simplest use case is to parse an email completely by creating an Email instance from a reader: but if somebody has a more advanced use case, we can enable them to create an empty Email and parse headers and bodies separately: That way,
This is a pretty nitty discussion, but we have the luxury of taking the time to build a nice library, so let's try to get this nice and elegant. Thoughts? |
|
Thank you for the discussion, I wouldn't have thought of this approach on my own, and I'm learning a lot just by reviewing and reading your comments. I like the consistency in the method parameters and the logic encapsulation in the proposed solution.
|
|
Thank you for the review, @ValleyCrisps . Let me merge this first and make a release and we can explore parsing different types of bodies and parsing attachments in a separate PR. |
In #72 @rorycl makes a good point for parsing email headers only: the email bodies might be malformed or the user might be interested in headers only.
I do not think, however, that a string arg
letters.ParseEmail(r, "HeadersOnly")is the best way to implement this feature. I believe that this should be at least a config struct for future maintainability, but for the time being there is a simpler solution: export theParseHeaders()identifier so that users can use it directly.This PR renames
letters.parseHeaders()toletters.ParseHeaders(), adds a test, and updates README.md with an example.One point that might merit discussion, is whether the now public
ParseHeaders()should not accept the same parameters asParseEmailso that the user is not responsible for reading the message usingmail.ReadMessage()and passingmsg.HeadertoParseHeaders().