| 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 Source #
Type to represent an email address. Newtype wrapper around EmailAddress with additional typeclass instances.
Constructors
| EmailAddress | |
Fields | |
Instances
| Eq EmailAddress Source # | |
| Data EmailAddress Source # | |
| Ord EmailAddress Source # | |
| Read EmailAddress Source # |
|
| Show EmailAddress Source # |
|
| Generic EmailAddress Source # | |
| ToJSON EmailAddress Source # | Turn
|
| FromJSON EmailAddress Source # | Parse
|
| ToHttpApiData EmailAddress Source # | This instance assumes
|
| FromHttpApiData EmailAddress Source # | This instance assumes
|
| FromField EmailAddress Source # | |
| PathPiece EmailAddress Source # | See
|
| PersistFieldSql EmailAddress Source # | Treat
|
| PersistField EmailAddress Source # | Treat
|
| QueryRunnerColumnDefault PGText EmailAddress Source # | |
| Default Constant EmailAddress (Column PGText) Source # | |
| type Rep EmailAddress Source # | |
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
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
emailAddressFromText :: Text -> Maybe EmailAddress Source #
Create an EmailAddress from a Text value. See emailAddress.
validateFromText :: Text -> Either String EmailAddress Source #
Create an EmailAddress from a Text value. See validate.
emailAddressFromString :: String -> Maybe EmailAddress Source #
Create an EmailAddress from a String value. See emailAddress.
validateFromString :: String -> Either String EmailAddress Source #
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 Source #
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 Source #
Wrapper around toByteString.
>>>let email = unsafeEmailAddress "foo" "gmail.com">>>>>>toByteString email"foo@gmail.com"
localPart :: EmailAddress -> ByteString Source #
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 Source #
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.
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"