import Data.String.Utils ( split, strip )
-import DNS ( normalize_string_domain )
+import DNS ( NormalDomain, normalize_string )
-- | Type synonym to make the signatures below a little more clear.
-- WARNING: Also defined in the "Report" module.
parts = split "@" address
--- | Given a list of 'Domain's @domains@ and a list of 'Forward's
+-- | Given a list of 'NormalDomain's @domains@ and a list of 'Forward's
-- @forwards@, filter out all elements of @forwards@ that have a
-- goto domain in the list of @domains@.
--
-- ==== __Examples__
--
--- >>> let ds = ["example.com", "example.net"]
+-- >>> let ds = map normalize_string ["example.com", "example.net"]
-- >>> let f1 = fwd "a@example.com" "a@example.com"
-- >>> let f2 = fwd "a@example.com" "a1@example.net"
-- >>> let f3 = fwd "a@example.com" "a2@example.org"
-- >>> map pretty_print (dropby_goto_domains ds [f1,f2,f3])
-- ["a@example.com -> a2@example.org"]
--
-dropby_goto_domains :: [Domain] -> [Forward] -> [Forward]
-dropby_goto_domains domains =
+dropby_goto_domains :: [NormalDomain] -> [Forward] -> [Forward]
+dropby_goto_domains normal_domains =
filter (not . is_bad)
where
- -- If we don't normalize these first, comparison (i.e. `elem`)
- -- doesn't work so great.
- normalized_domains = map normalize_string_domain domains
-
-- | A 'Forward' is bad if its goto domain appears in the list, or
-- if we can't figure out its goto domain.
--
is_bad f =
case (goto_domain f) of
Nothing -> True -- Drop these, too.
- Just d -> (normalize_string_domain d) `elem` normalized_domains
+ -- Nice, we can't compare unless we normalize @d@!
+ Just d -> (normalize_string d) `elem` normal_domains