Address.hs 723 B

1234567891011121314151617181920212223
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Data.SMTP.Types.Address where
  3. import qualified Data.SMTP.Account as Ac
  4. import qualified Data.SMTP.URI as URI
  5. import qualified Data.SMTP.Seal as Seal
  6. import Data.ByteString (ByteString)
  7. import qualified Data.ByteString as BS
  8. data Address = Address {uri :: Maybe URI.URI, account :: Ac.Account, seal :: Maybe Seal.Seal}
  9. deriving (Read, Show, Eq, Ord)
  10. asToURI :: Address -> ByteString
  11. asToURI a@Address{uri = Nothing} = BS.concat ["<", Ac.normalize . account $ a, ">"]
  12. asToURI Address{uri = (Just u)} = URI.fullURI u
  13. hostFrom :: Address -> Ac.HostName
  14. hostFrom = Ac.domain . account
  15. fromAccount :: Ac.Account -> Address
  16. fromAccount a = Address Nothing a Nothing