-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add bodyFilter
and fileFilter
on EmailParser
and allow WithBodyFilter()
and WithFileFilter()
options
#119
Conversation
Hi @mnako I'm very much in favour of adding a parser struct, as you have in this patch, as this is the key point for allowing future flexibility of use of this very useful library. This flexibility could come through the new Options you've suggested, which are great, but also to allow greater flexibility in the structure and testing of the library in general. The At the moment you have this in the patch: type EmailParser struct {
bodyFilter EmailBodyFilter
fileFilter EmailFileFilter
} I would be grateful if you consider extending this struct further, perhaps as follows: type EmailParser struct {
// what are we going to process? header only / no attachments, // etc...
processType typeOfProcessing
// store the email as it is extracted here
email *Email
// have funcs here that can be overridden by the user, with the
// default attached at "NewParser".
addressFunc func(mail.Header, string) (*mail.Address, error)
dateFunc func(string) (*time.Time, error)
fileFunc func([]string) (*email.File, error) // signature tbc
// possibly helpful to store main email encoding and cte
encoding encoding.Encoding
cte email.ContentTransferEncoding
} Futher funcs might be added, as you suggest, but they might not be just restricted to filtering. My suggestions are intended to assist someone trying to contribute to the You'll see there are a few further things in my suggestion. I'll go through them in turn.
In summary I'm enthusiastic about the use of a struct for the parser and hope that you will consider some of these items for expanding the use of the struct, including moving some funcs to methods. The benefits would include:
Thanks for your consideration. |
…ilter() and WithFileFilter() options.
dd24a40
to
d28a884
Compare
Fix a loop variable captured in closure in tests.
Update tests. Update readme.
bodyFilter
and fileFilter
on EmailParser
and allow WithBodyFilter()
and WithFileFilter()
optionsbodyFilter
and fileFilter
on EmailParser
and allow WithBodyFilter()
and WithFileFilter()
options
@ValleyCrisps this should be now in a good enough state for a review. One notable change is that I have added the Content-Disposition header to the file filter function type. This will allow filtering files not only by their filename, but also by whether they are inlined or attached. The changes to the test file are huge, you might need to review them in a local Git client. Please also take a look at the readme and let me know whether it is easy to follow and helpful to future user. |
I apologise if my comments haven't been clear enough to have a conversation. I personally consider the direction being taken unnecessarily limiting. For example, simply exposing the full file struct to users will allow then to provide an attached or inline file processing func. There is no benefit (except perhaps to provide an example file processing func) for the file filter. |
…rs.ParseEmail()` for backward compatibility.
@ValleyCrisps, one last change: since we are already using letters on a production email server, I want to keep unnecessary breaking changes to a minimum. I have renamed I have also updated the readme. I believe this is good enough for the next minor release, please let me know if you are ok with this merge and a release. |
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.
The README looks good to me.
I like how the ParseEmail function is now a wrapper around the default implementation. This will introduce the new functionality as a non-breaking change for current users.
Thanks for your review and comments, @ValleyCrisps. I answered your comments. Unless you have more comments, if you could approve, I can try and cut out a release candidate tomorrow. |
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.
Thanks for addressing my comments, good to go!
@rorycl, thank you for your comments. With #119 now merged and soon to be released as v0.2.4, I hope this covers the use case of skipping parsing attachments. As we discussed, we've chosen the Since we're going in a different direction with Thank you for your work for the Golang community. |
Thanks very much for your thoughtful response and your wonderful work on letters. I hope you find some useful ideas in the code, which I'm actively developing at https://github.com/rorycl/letters. I'll be sure to keep you and your contributors mentioned as set out in the licence, although I'll upgrade that formally to an MIT licence unless you suggest otherwise. A few things that I quite like about the more modularised approach include:
You might also find testRegen.go useful if you need to regenerate your excellent tests after changing the structure of the returned Best wishes, |
Cf. #112 (comment) and further discussion