Giter Club home page Giter Club logo

rfc822's Introduction

Introduction

This is a simple gem for Ruby that simplifies validating email addresses. It conforms with RFC2822.

Here comes a quick code sample. Currently no docs.

require 'rfc822'

# To test if whole string is an email... ugly way
#  (returns 0 on success, nil on failure):

"[email protected]".dup.force_encoding("BINARY") =~ RFC822::EMAIL_REGEXP_WHOLE

# or nice one (returns true/false):

"[email protected]".is_email?

# To test if string contains an email... ugly way
#   (returns 0 on success, nil on failure):

"demo [email protected]".dup.force_encoding("BINARY") =~ RFC822::EMAIL_REGEXP_PART

# or nice one (returns true/false):

"demo [email protected]".contains_email?

# To scan for emails within a string... ugly way
#   (returns an array):

"something [email protected] xyz".dup.force_encoding("BINARY").scan(RFC822::EMAIL_REGEXP_PART)

# or nice one (also returns an array):

"something [email protected] xyz".scan_for_emails

If you omit ‘.dup.force_encoding(“BINARY”)` part, you can run into exceptions if someone passes non-ASCII email (see github.com/mspanc/rfc822/issues/3).

Installation

Ruby Versions

Code was tested with ruby-1.8.7-p334 [ i386 ] and ruby-1.9.2-p180 [ i386 ] under RVM.

Gems

The gems are hosted at Rubygems.org. Make sure you’re using the latest version of rubygems:

$ gem update --system

Then you can install the gem as follows:

$ gem install rfc822

Bundler

Add to your Gemfile:

gem "rfc822"

and then type:

bundle install

From the GitHub source

The source code is available at github.com/saepia/rfc822. You can either clone the git repository or download a tarball or zip file. Once you have the source, you can unpack it and use from wherever you downloaded.

ChangeLog

0.1.5

  • Fixed bug that caused to change encoding of string passed to the methods (thanks to Artur Trzop)

0.1.4

  • Fixed regression introduced in 0.1.3 that caused EMAIL_REGEXP_WHOLE to stop working properly.

0.1.3 (yanked)

  • security

    Updated regular expressions to use A and z instead of ^ and $ operators.

0.1.2

  • Updated license

0.1.1

  • Fixed description in the gem description

0.1.0

  • Added compatibility with Ruby 1.9

  • Added String#is_email?, String#contains_email? and String#scan_for_emails methods

0.0.2

  • Initial release

License

MIT

rfc822's People

Contributors

mspanc avatar arturt avatar

Stargazers

 avatar James Gifford avatar Chris Caselas avatar Ryan Gendron avatar Kazuma Furuhashi avatar Shuhei KONDO avatar Maciej avatar Lee Azzarello avatar  avatar Ezequiel Erbaro avatar  avatar Farid Aliev avatar

Watchers

Chris Caselas avatar James Cloos avatar  avatar

rfc822's Issues

Doesn't work with non-ascii emails

I realize that RFC2822 does not support extended charsets and that that is pending RFC5335. However the current situation leads to a huge gotcha where the documentation suggests matching against RFC822::EMAIL_REGEXP_WHOLE. However if this is done against a UTF-8 string with higher order chars then it pukes out a Encoding::CompatibilityError. eg.

"tó[email protected]" =~ RFC822::EMAIL_REGEXP_WHOLE

I realize you guard against this in the String methods, but the docs themselves list the direct match method.

Incompatible with Ruby 3.3.3

Issue Description

The rfc822 gem is currently not compatible with the latest Ruby Regexp.new API. The specific issue arises from the use of the third argument ('n') in the Regexp.new method, which is no longer supported in the latest Ruby versions.

Steps to Reproduce

  1. Use Ruby version 3.3.3 or later.
  2. Include the rfc822 gem in your project.
  3. Attempt to start your server or run your application.

Error Message

/path/to/gem/rfc822-0.1.5/lib/rfc822.rb:16
`initialize': wrong number of arguments (given 3, expected 1..2) (ArgumentError)
EMAIL_REGEXP_WHOLE = Regexp.new("\A#{ADDR_SPEC}\z", nil, 'n')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Suggested Fix

To maintain compatibility with the latest Ruby versions, the Regexp.new calls should be updated as follows:

EMAIL_REGEXP_WHOLE = Regexp.new("\\A#{ADDR_SPEC}\\z", Regexp::NOENCODING)
EMAIL_REGEXP_PART = Regexp.new("#{ADDR_SPEC}", Regexp::NOENCODING)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.