diff options
Diffstat (limited to 'src/Mail.hs')
-rw-r--r-- | src/Mail.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Mail.hs b/src/Mail.hs new file mode 100644 index 0000000..830f4da --- /dev/null +++ b/src/Mail.hs @@ -0,0 +1,39 @@ +module Mail + ( Mail (..) + , subject + , Header + , P.Part (..) + , MailM + , newMail + , setData + ) +where + +import Common (toLower) +import Control.Monad.State.Lazy (StateT) +import Data.List (find) +import Intro +import Mail.Header (Header) +import qualified Mail.Parser as P + +data Mail = Mail + { client :: String + , from :: String + , to :: [String] + , headers :: [Header] + , body :: [P.Part] + } + deriving (Show, Eq) + +type MailM a = StateT Mail IO a + +newMail :: Mail +newMail = Mail "" "" [] [] [] + +setData :: [String] -> Mail -> Mail +setData xs m = m{headers = msg.headers, body = msg.body} + where + msg = P.run xs + +subject :: Mail -> Maybe String +subject m = snd <$> find (\(k, _) -> toLower k == "subject") (headers m) |