module Network.DomainAuth.PRD.Domain (
extractDomain
) where
import Network.DNS (Domain)
import Network.DomainAuth.Mail
import Network.DomainAuth.PRD.Lexer
import qualified Data.Attoparsec.ByteString as P
import qualified Data.ByteString.Char8 as BS
extractDomain :: RawFieldValue -> Maybe Domain
extractDomain bs = case P.parseOnly structured bs of
Left _ -> Nothing
Right st -> takeDomain st
where
takeDomain = dropTail . dropWhile (/="@")
dropTail [] = Nothing
dropTail xs = (Just . BS.concat . takeWhile (/=">") . tail) xs