Emailist
emailist
is a wrapper around Ruby Array, and is meant to assist in managing a list of email addresses.
emailist
automatically attempts to clean invalid emails as they're added, and maintains uniqueness of your list. This is good for parsing emails, where you may end up with some invalid characters, or extra, unwanted bit of text on the beginnings/ends of the emails). While there are some caveats using emailist
, as long as you don't need and/or expect 100% accuracy, then you should be fine. emailist
tries its hardest to adhere to the RFC specs for emails, and checks validity of TLDs against ICANN.
This is just a small project I built for myself. I was building a simple parser to grab emails from a bunch of files. I decided I'd pull it out into its own gem, as I can see it being useful in other cases. Anyway, the code could certainly be a lot better, I only spent a couple of hours on this this morning. I'd love to improve this further, so pull requests are very welcome.
Installation
Add this line to your application's Gemfile:
gem 'emailist'
And then execute:
$ bundle
Or install it yourself as:
$ gem install emailist
Usage
Make sure you require...
require 'emailist'
Adding and removing emails is very easy:
emails = Emailist.new
emails.add('[email protected]')
=> ['[email protected]']
emails.remove('[email protected]')
=> []
Uniqueness is automatically maintained:
emails = Emailist.new
emails.add('[email protected]')
=> ['[email protected]']
emails.add('[email protected]')
=> ['[email protected]']
Invalid emails are attempted to be cleaned:
emails = Emailist.new
emails.add('[email protected]')
=> ['[email protected]']
emails.add('[email protected].')
=> ['[email protected]']
Invalid TLDs (after cleaning) raise Emailist::InvalidTLD
:
emails = Emailist.new
emails.add('[email protected]')
=> # raises Emailist::InvalidTLD
Finally, if you want to verify hosts (example.com in [email protected]), do:
emails = Emailist.new(verify_hosts: true)
emails.add('[email protected]')
=> # raises Emailist::HostDead
Ideas For Improvement
- Some kind of "best-guess" algorithm that can take invalid TLDs and find the most likely intended TLD (e.g. I'm getting some emails from my parser that have an 'E', like '[email protected]' -- this clearly is supposed to be '.com'). Perhaps Levenshtein distance could be useful for this.
- Fix
possible_email
gem -- Rapportive still has an API but they've modified it, so the code for the gem doesn't work. This will require reverse-engineering the API, as they don't offer access publicly. Not sure if it's even possible, but worth a try.
Contributing
- Fork it ( https://github.com/[my-github-username]/emailist/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request