module EmailAddress
where
-import qualified Data.ByteString as BS
-import qualified Data.ByteString.UTF8 as BSU
+import qualified Data.ByteString.Char8 as BS (
+ ByteString,
+ break,
+ empty,
+ length,
+ pack,
+ tail)
import Text.Email.Validate (isValid)
import Test.HUnit (assertEqual)
import Test.Framework (Test, testGroup)
utf8
)
-type Address = BSU.ByteString
-type LocalPart = BSU.ByteString
-type DomainPart = BSU.ByteString
+type Address = BS.ByteString
+type LocalPart = BS.ByteString
+type DomainPart = BS.ByteString
(before, after)
where
break_func = (== '@')
- (before, rest) = BSU.break break_func address
+ (before, rest) = BS.break break_func address
after =
if rest == BS.empty
then BS.empty
-- | Check that the lengths of the local/domain parts are within spec.
validate_length :: Address -> Bool
validate_length address =
- (BSU.length localpart <= 64) && (BSU.length domain <= 255)
+ (BS.length localpart <= 64) && (BS.length domain <= 255)
where
(localpart, domain) = parts address
_ -> True
where
regex_str = "(\\w+)([\\w\\-\\.]*)@(([a-z0-9\\-]+\\.)+)[a-z]{2,4}$"
- regex_bs = BSU.fromString regex_str
+ regex_bs = BS.pack regex_str
regex = compile regex_bs [anchored, caseless, dollar_endonly, utf8]
matches = match regex address []
-- HUnit tests
good_addresses :: [Address]
good_addresses =
- map BSU.fromString [
+ map BS.pack [
"phil@hotmail.com",
"philq23562@hotmail.com",
"gsdfg22-2_22@hot-mail.com",
bad_addresses :: [Address]
bad_addresses =
- map BSU.fromString [
--- Bad, but not caught by email-validate-1.0.0.
--- "badunderscore@dom_ain.com",
+ map BS.pack [
+ -- Bad, but not caught by email-validate-0.0.1.
+ -- "badunderscore@dom_ain.com",
"(fail)@domain.com",
"no spaces@domain.com",
".beginswith@a-dot.com",
unsupported_addresses :: [Address]
unsupported_addresses =
- map BSU.fromString [
+ map BS.pack [
"ok!char@domain.com",
"ok#char@domain.com",
"ok$char@domain.com",