{-# LANGUAGE OverloadedStrings #-} module Data.SMTP.Types.Account (Account(..), PersonalName(..), AccountName(..), HostName(..), AccountTag(..), normalize) where import Data.ByteString (ByteString) import qualified Data.ByteString as BS import Data.Default.Class newtype PersonalName = PersonalName ByteString deriving (Show, Read, Eq, Ord) newtype HostName = HostName ByteString deriving (Show, Read, Eq, Ord) newtype AccountTag = AccountTag ByteString deriving (Show, Read, Eq, Ord) newtype AccountName = AccountName ByteString deriving (Show, Read, Eq, Ord) data Account = Account {fullAccount :: ByteString, personalName :: PersonalName, name :: AccountName, domain :: HostName, tags :: [AccountTag]} deriving (Show, Read) instance Eq Account where a == b = name a == name b && domain a == domain b instance Ord Account where compare a b = case compare (name a) (name b) of LT -> LT GT -> GT EQ -> compare (domain a) (domain b) instance Default Account where def = Account "<>" (PersonalName "") (AccountName "") (HostName "") [] normalize :: Account -> ByteString normalize a = let AccountName an = name a HostName hn = domain a in if BS.null hn then an else BS.concat [an, "@", hn]