module Network.DomainAuth.Mail.XMail (
XMail(..)
, initialXMail
, pushField
, pushBody
, finalizeMail
) where
import qualified Data.ByteString.Char8 as BS
import Data.Sequence (fromList)
import Network.DomainAuth.Mail.Types
import Network.DomainAuth.Utils
data XMail = XMail {
xmailHeader :: Header
, xmailBody :: [RawBodyChunk]
} deriving (Eq,Show)
initialXMail :: XMail
initialXMail = XMail [] []
pushField :: RawFieldKey -> RawFieldValue -> XMail -> XMail
pushField key val xmail = xmail {
xmailHeader = fld : xmailHeader xmail
}
where
fld = Field ckey key (blines val)
ckey = canonicalizeKey key
pushBody :: RawBodyChunk -> XMail -> XMail
pushBody bc xmail = xmail {
xmailBody = bc : xmailBody xmail
}
finalizeMail :: XMail -> Mail
finalizeMail xmail = Mail {
mailHeader = reverse . xmailHeader $ xmail
, mailBody = fromList . blines . BS.concat . reverse . xmailBody $ xmail
}