diff options
author | evuez <julien@mulga.net> | 2024-04-01 15:17:30 +0200 |
---|---|---|
committer | evuez <julien@mulga.net> | 2024-04-03 22:45:36 +0200 |
commit | 985974c264804ff788b3b5242fef707d4b7fa9a6 (patch) | |
tree | d80f83db178c3fd1b83b3b749793d47236dde35d /src/Mail.hs | |
download | webmaild-985974c264804ff788b3b5242fef707d4b7fa9a6.tar.gz |
Initial commit
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) |