attomail

Safe HaskellSafe
LanguageHaskell2010

EmailAddress

Contents

Description

Adapted from Text.EmailAddress by Dennis Gosnell (see https://hackage.haskell.org/package/emailaddress) but without all the dependencies (like postgresql-simple ...). Uses the email-validate package, instead.

Synopsis

Data Type

newtype EmailAddress Source #

wrapper around our implementation - EmailAddress.

Constructors

EmailAddress 

Instances

Eq EmailAddress Source # 
Ord EmailAddress Source # 
Read EmailAddress Source #
>>> (read "\"foo@gmail.com\"") :: EmailAddress
"foo@gmail.com"
Show EmailAddress Source #
>>> import qualified Data.ByteString.Char8 as BS
>>> :set -XOverloadedStrings
>>> show $ unsafeEmailAddress "foo" "gmail.com"
"\"foo@gmail.com\""

Create EmailAddress

emailAddress :: ByteString -> Maybe EmailAddress Source #

Wrapper around emailAddress.

Similar to validate, but returns Nothing if the email address fails to parse.

>>> emailAddress "foo@gmail.com"
Just "foo@gmail.com"
>>> emailAddress "not an email address"
Nothing

validation

validate :: ByteString -> Either String EmailAddress Source #

Wrapper around validate.

>>> validate "foo@gmail.com"
Right "foo@gmail.com"
>>> import Data.Either (isLeft)
>>> isLeft $ validate "not an email address"
True

Unsafe creation

unsafeEmailAddress Source #

Arguments

:: ByteString

Local part

-> ByteString

Domain part

-> EmailAddress 

Wrapper around unsafeEmailAddress.

Unsafely create an EmailAddress from a local part and a domain part. The first argument is the local part, and the second argument is the domain part.

For example, in the email address foo@gmail.com, the local part is foo and the domain part is gmail.com.

>>> unsafeEmailAddress "foo" "gmail.com"
"foo@gmail.com"