valid_email2
valid_email2 copied to clipboard
Supplying blacklist / whitelist domains from array vs yml file?
Hey there,
I've used this library quite a few times in the past, and even initially suggested the MX spam lookup trick (https://github.com/micke/valid_email2/issues/95)
It's now a few years later, and I have a new suggestion -- allowing the blacklist
/ whitelist
option to take an array vs a boolean.
E.g. right now we can do:
validates :email, 'valid_email_2/email': { blacklist: true } # This is the default behavior
But it would be really cool if we could do:
validates :email, 'valid_email_2/email': { blacklist: ["cool.com", "fun.com", etc...] }
This could then be used to support things like AR models, e.g.
validates :email, 'valid_email_2/email': { blacklist: proc { EmailPermissions.where(blacklist: true).pluck(:domain) } }
The benefit here is that with large websites, spammers target you quite often, and so if you need to commit and push an updated config/blacklisted_email_domains.yml
every time, it's going to be quite painful. By having the default be the same, but being able to override the default to be more dynamic, you can have perhaps have the best of both worlds.
@micke Just a poke here, let me know what you think on this.
Great idea! What do you think about letting the proc take the models domain as an argument and not only return a enumurable of blocked domains but also return true or false. Then you can let the database do the heavy lifting instead of loading a huge list into the applications memory.
I'll gladly accept a PR!