Address.hs 966 B

1234567891011121314151617181920212223242526272829303132333435
  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 Text.StringConvert
  7. data Address = AccountAdd Ac.Account (Maybe Seal.Seal)
  8. | URIAdd URI.URI (Maybe Seal.Seal)
  9. deriving (Read, Show, Eq, Ord)
  10. asToURI :: Address -> String
  11. asToURI (AccountAdd a _) = concat ["<", s . Ac.normalize $ a, ">"]
  12. asToURI (URIAdd u _) = URI.fullURI u
  13. hostFrom :: Address -> Ac.HostName
  14. hostFrom = Ac.domain . account
  15. fromAccount :: Ac.Account -> Address
  16. fromAccount a = AccountAdd a Nothing
  17. account :: Address -> Ac.Account
  18. account (AccountAdd a _) = a
  19. account (URIAdd u _) = URI.account u
  20. seal :: Address -> Maybe Seal.Seal
  21. seal (AccountAdd _ se) = se
  22. seal (URIAdd _ se) = se
  23. setSeal :: Address -> Maybe Seal.Seal -> Address
  24. setSeal (AccountAdd a _) se = AccountAdd a se
  25. setSeal (URIAdd u _) se = URIAdd u se