| Copyright | (c) Dennis Gosnell 2016 |
|---|---|
| License | BSD3 |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.EmailAddress
Contents
Description
This module is a wrapper around Text.Email.Validate from email-validate.
This module exports EmailAddress, a newtype wrapper around
Text.Email.Validate.EmailAddress.
Additional instances are defined for our
new EmailAddress, including ToJSON and FromJSON. This is done so that no
orphan instances need to be used.
If you would like additional instances to be defined, please send a pull request. Additional instances will be accepted for any typeclass from any package available on stackage.
- newtype EmailAddress = EmailAddress {}
- emailAddress :: ByteString -> Maybe EmailAddress
- validate :: ByteString -> Either String EmailAddress
- emailAddressFromText :: Text -> Maybe EmailAddress
- validateFromText :: Text -> Either String EmailAddress
- emailAddressFromString :: String -> Maybe EmailAddress
- validateFromString :: String -> Either String EmailAddress
- isValid :: ByteString -> Bool
- toText :: EmailAddress -> Text
- toByteString :: EmailAddress -> ByteString
- localPart :: EmailAddress -> ByteString
- domainPart :: EmailAddress -> ByteString
- canonicalizeEmail :: ByteString -> Maybe ByteString
- unsafeEmailAddress :: ByteString -> ByteString -> EmailAddress
Data Type
newtype EmailAddress #
Type to represent an email address. Newtype wrapper around
EmailAddress with additional typeclass instances.
Constructors
| EmailAddress | |
Fields | |
Instances
| Eq EmailAddress # | |
| Data EmailAddress # | |
| Ord EmailAddress # | |
| Read EmailAddress # |
|
| Show EmailAddress # |
|
| Generic EmailAddress # | |
| ToJSON EmailAddress # | Turn
|
| FromJSON EmailAddress # | Parse
|
| ToHttpApiData EmailAddress # | This instance assumes
|
| FromHttpApiData EmailAddress # | This instance assumes
|
| FromField EmailAddress # | |
| PathPiece EmailAddress # | See
|
| PersistFieldSql EmailAddress # | Treat
|
| PersistField EmailAddress # | Treat
|
| QueryRunnerColumnDefault PGText EmailAddress # | |
| Default Constant EmailAddress (Column PGText) # | |
| type Rep EmailAddress # | |
Create EmailAddress
emailAddress :: ByteString -> Maybe EmailAddress #
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
validate :: ByteString -> Either String EmailAddress #
Wrapper around validate.
>>>validate "foo@gmail.com"Right "foo@gmail.com">>>import Data.Either (isLeft)>>>isLeft $ validate "not an email address"True
emailAddressFromText :: Text -> Maybe EmailAddress #
Create an EmailAddress from a Text value. See emailAddress.
validateFromText :: Text -> Either String EmailAddress #
Create an EmailAddress from a Text value. See validate.
emailAddressFromString :: String -> Maybe EmailAddress #
Create an EmailAddress from a String value. See emailAddress.
validateFromString :: String -> Either String EmailAddress #
Create an EmailAddress from a String value. See validate.
Check validity
isValid :: ByteString -> Bool #
Validates whether a particular string is an email address according to RFC5322.
Convert to Text
toText :: EmailAddress -> Text #
Convert an email address to Text.
This assumes the EmailAddress is UTF8-encoded.
>>>let email = unsafeEmailAddress "foo" "gmail.com">>>>>>toText email"foo@gmail.com"
Convert back to ByteString
toByteString :: EmailAddress -> ByteString #
Wrapper around toByteString.
>>>let email = unsafeEmailAddress "foo" "gmail.com">>>>>>toByteString email"foo@gmail.com"
localPart :: EmailAddress -> ByteString #
Wrapper around localPart.
Extracts the local part from an email address.
For example, in the email address foo@gmail.com, the local part is foo.
>>>let email = unsafeEmailAddress "foo" "gmail.com">>>>>>localPart email"foo"
domainPart :: EmailAddress -> ByteString #
Wrapper around domainPart.
Extracts the domain part from an email address.
For example, in the email address foo@gmail.com, the domain part is
gmail.com.
>>>let email = unsafeEmailAddress "foo" "gmail.com">>>>>>domainPart email"gmail.com"
Helper functions
canonicalizeEmail :: ByteString -> Maybe ByteString #
Checks that an email is valid and returns a version of it where comments and whitespace have been removed.
Example:
>>>canonicalizeEmail "spaces. are. allowed@example.com"Just "spaces.are.allowed@example.com"
Unsafe creation
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"