Git Product home page Git Product logo

emailaddress's Introduction

#emailaddress

Join the chat at https://gitter.im/hmrc/emailaddress Build Status Download

Scala micro-library for typing, validating and obfuscating email addresses

Address Typing & Validation

The EmailAddress class will only accept valid addresses:

scala> import uk.gov.hmrc.emailaddress._
import uk.gov.hmrc.emailaddress._

scala> EmailAddress("[email protected]")
res0: uk.gov.hmrc.emailaddress.EmailAddress = example@test.com

scala> EmailAddress("not_a_meaningful_address")
java.lang.IllegalArgumentException: requirement failed: 'not_a_meaningful_address' is not a valid email address

You can also use EmailAddress.isValid(...):

scala> EmailAddress.isValid("[email protected]")
res2: Boolean = true

scala> EmailAddress.isValid("not_a_meaningful_address")
res3: Boolean = false

Accessing the domain and mailbox

You can access the mailbox and domain of a given address:

scala> EmailAddress("[email protected]").domain
res0: uk.gov.hmrc.emailaddress.EmailAddress.Domain = test.com

scala> EmailAddress("[email protected]").mailbox
res1: uk.gov.hmrc.emailaddress.EmailAddress.Mailbox = example

These compare equal as you might expect:

scala> EmailAddress("[email protected]").domain == EmailAddress("[email protected]").domain
res2: Boolean = true

scala> EmailAddress("[email protected]").domain == EmailAddress("[email protected]").domain
res3: Boolean = false

Obfuscation

Addresses are obfuscated by starring out all of their mailbox part, apart from the first and last letters:

scala> ObfuscatedEmailAddress("[email protected]")
res4: uk.gov.hmrc.emailaddress.ObfuscatedEmailAddress = e*****e@test.com

Unless there are only two letters:

scala> ObfuscatedEmailAddress("[email protected]")
res7: uk.gov.hmrc.emailaddress.ObfuscatedEmailAddress = **@test.com```

You can also create them directly from an EmailAddress:

scala> EmailAddress("[email protected]").obfuscated
res6: uk.gov.hmrc.emailaddress.ObfuscatedEmailAddress = e*****e@test.com

Converting back to String

All classes toString and implicitly convert to Strings nicely:

scala> val someString: String = EmailAddress("[email protected]")
someString: String = example@test.com

scala> val someString = EmailAddress("[email protected]").toString
someString: String = example@test.com

scala> val someString: String = ObfuscatedEmailAddress("[email protected]")
someString: String = e*****e@test.com

scala> val someString = ObfuscatedEmailAddress("[email protected]").toString
someString: String = e*****e@test.com

scala> EmailAddress("[email protected]").domain.toString
res4: String = test.com

scala> val s: String = EmailAddress("[email protected]").domain
s: String = test.com

scala> EmailAddress("[email protected]").mailbox.toString
res5: String = example

scala> val s: String = EmailAddress("[email protected]").mailbox
s: String = example

Installing

Include the following dependency in your SBT build before v4.0.0

resolvers += Resolver.bintrayRepo("hmrc", "releases")

libraryDependencies += "uk.gov.hmrc" %% "emailaddress" % "<INSERT VERSION>"

Include one the following dependencies in your SBT build for v4.0.0 or after depending on whether you are using Play 2.8, Play 2.9 or Play 3.0

libraryDependencies += "uk.gov.hmrc" %% "emailaddress-play-28" % "<INSERT VERSION>"

OR

libraryDependencies += "uk.gov.hmrc" %% "emailaddress-play-29" % "<INSERT VERSION>"

OR

libraryDependencies += "uk.gov.hmrc" %% "emailaddress-play-30" % "<INSERT VERSION>"

Run the tests and sbt fmt before raising a PR

Format:

sbt fmt

Then run the tests and coverage report:

sbt clean coverage test coverageReport

If your build fails due to poor test coverage, DO NOT lower the test coverage threshold, instead inspect the generated report located here on your local repo: /target/scala-2.12/scoverage-report/index.html

Then run the integration tests:

sbt it:test

License

This code is open source software licensed under the Apache 2.0 License.

emailaddress's People

Contributors

andy1138 avatar andyhwchung avatar barnesjake avatar duncancrawford avatar enriquefaci avatar gitter-badger avatar grahampaulcook avatar howyp avatar jakobgrunig avatar lxol avatar mgladdish avatar mikemey avatar muralishub avatar pangiole-hmrc avatar platops-teams-and-repositories-labs avatar stjasink avatar timothygordon32 avatar tomasz-rosiek avatar vasanthavijaya avatar vaughansharman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emailaddress's Issues

Artifacts are not propagating to Maven Central

Just looked at pulling this lib in, but it seems to be stuck on a very old version (0.2.0) on Maven Central, whild Bintray has it a 1.1.0. Many organisations don't allow JCenter directly, so it would be very beneficial if it was published to Maven Central too.

Remove dependency on play-json

I'm using this library outside play, and I would really like not to have to include the play-json library. Firstly because I don't need a json representation of an email address, secondly because of the large set of dependencies play-json pulls in:

  • com.typesafe.play : play-iteratees_2.10
  • com.typesafe.play : play-functional_2.10
  • com.typesafe.play : play-datacommons_2.10
  • joda-time : joda-time
  • org.joda : joda-convert
  • com.fasterxml.jackson.core : jackson-annotations
  • com.fasterxml.jackson.core : jackson-core
  • com.fasterxml.jackson.core : jackson-databind

Requiring this lot is a bit of a hidden gotcha for a micro library.

Dependency on Play

Thanks for creating this library. I'm trying to use it and getting this error:

[error] missing or invalid dependency detected while loading class file 'EmailAddress.class'.
[error] Could not access term play in package ,

Looks like there is a dependency on the Play project? I'm reluctant to pull in a big framework for a microlib, and it looks like the dependency is there for a very small part of the lib. Any chance it could be factored out, maybe a separate emailaddress-play lib?

Email address with apostrophe is treated as invalid

One of my colleagues has a digital email address with an apostrophe in it:-
EmailAddress.isValid("john.o'[email protected]”) returns false
Is there any reason that https://github.com/hmrc/emailaddress/blob/master/src/main/scala/uk/gov/hmrc/emailaddress/EmailAddress.scala doesn’t allow it. Does this regex fully comply with the RFC for email address? Although most sites only allow basic email address’s (like creating an Oracle account) even gmail returns a “Please only use letters (a-z), numbers and periods”. GDS’s blog registration does allow the above email though.

Scala 2.13 support

It would be great to have a cross-build for Scala 2.13. emailaddress is one of the last libs in my dependency tree not available for Scala 2.13

⚠ Artifacts download error on Bintray ⚠

I got SBT errors and cannot build my app anymore, and I suspect all apps using this lib won't build neither. The download request on Bintray results in a 403 forbidden response. Can you fix the repository ASAP ?

Distribution that includes test code

Hi,

Great package! I'd like to use the email address generators in my own test code; any chance you can publish a distribution that includes those classes?

Cheers!

Support for Scala 2.12

Hey,

Could you provide support for Scala 2.12? If you can provide me some help I can do the change :)

Thanks!

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.