aboutsummaryrefslogtreecommitdiff
path: root/src/Mail.hs
blob: 830f4da61bb6aac5792a6ac7364a518761f459c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)