From 985974c264804ff788b3b5242fef707d4b7fa9a6 Mon Sep 17 00:00:00 2001 From: evuez Date: Mon, 1 Apr 2024 15:17:30 +0200 Subject: Initial commit --- src/Mail.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Mail.hs (limited to 'src/Mail.hs') 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) -- cgit v1.2.3