module Text.Email.Validate
( isValid
, validate
, emailAddress
, canonicalizeEmail
, EmailAddress
, domainPart
, localPart
, toByteString
, unsafeEmailAddress
)
where
import Data.Attoparsec.ByteString (endOfInput, parseOnly)
import Data.ByteString (ByteString)
import Text.Email.Parser
( EmailAddress
, addrSpec
, domainPart
, localPart
, toByteString
, unsafeEmailAddress)
emailAddress :: ByteString -> Maybe EmailAddress
emailAddress :: ByteString -> Maybe EmailAddress
emailAddress = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String EmailAddress
validate
canonicalizeEmail :: ByteString -> Maybe ByteString
canonicalizeEmail :: ByteString -> Maybe ByteString
canonicalizeEmail = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EmailAddress -> ByteString
toByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Maybe EmailAddress
emailAddress
isValid :: ByteString -> Bool
isValid :: ByteString -> Bool
isValid = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const Bool
False) (forall a b. a -> b -> a
const Bool
True) forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String EmailAddress
validate
validate :: ByteString -> Either String EmailAddress
validate :: ByteString -> Either String EmailAddress
validate = forall a. Parser a -> ByteString -> Either String a
parseOnly (Parser ByteString EmailAddress
addrSpec forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \EmailAddress
r -> forall t. Chunk t => Parser t ()
endOfInput forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return EmailAddress
r)