where
break_func = (== '@')
(before, rest) = BSU.break break_func address
- after = BS.tail rest
+ after =
+ if rest == BS.empty
+ then BS.empty
+ else BS.tail rest
-- | Check that the lengths of the local/domain parts are within spec.
matches = match regex address []
+-- | Validate the syntax of an email address by checking its length
+-- and validating it against a simple regex.
+validate_syntax :: Address -> Bool
+validate_syntax address =
+ (validate_length address) && (validate_regex address)
+
-- HUnit tests
good_addresses :: [Address]
"badunderscore@dom_ain.com",
"(fail)@domain.com",
"no spaces@domain.com",
- ".beginswith@a-dot.com" ]
+ ".beginswith@a-dot.com",
+ "a",
+ "a.com",
+ "@b.com",
+ "b@",
+ (replicate 65 'a') ++ "@" ++ "domain.com",
+ "abcdefg@" ++ (replicate 253 'a') ++ ".com",
+ (replicate 100 'a') ++ "@" ++ (replicate 300 'a') ++ ".com" ]
unsupported_addresses :: [Address]
unsupported_addresses =
where
desc = "Good addresses are accepted."
expected = True
- actual = and (map validate_regex good_addresses)
+ actual = and (map validate_syntax good_addresses)
test_bad_addresses :: Test
test_bad_addresses =
where
desc = "Bad addresses are not accepted."
expected = True
- actual = and (map (not . validate_regex) bad_addresses)
+ actual = and (map (not . validate_syntax) bad_addresses)
test_unsupported_addresses :: Test
test_unsupported_addresses =
where
desc = "Unsupported addresses are not accepted."
expected = True
- actual = and (map (not . validate_regex) unsupported_addresses)
+ actual = and (map (not . validate_syntax) unsupported_addresses)
email_address_tests :: Test
_ -> return True
--- | Validate the syntax of an email address by checking its length
--- and validating it against a simple regex.
-validate_syntax :: Address -> Bool
-validate_syntax address =
- (validate_length address) && (validate_regex address)
-
-- | Validate an email address by doing some simple syntax checks and
-- (if those fail) an MX lookup. We don't count an A record as a mail