-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notify-mail.hs
36 lines (30 loc) · 911 Bytes
/
Notify-mail.hs
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
{-# LANGUAGE DeriveGeneric #-}
import Data.Aeson
import Data.Text
import qualified Data.ByteString.Lazy as B
import GHC.Generics
import DBus.Notify
data Email =
Email { authors :: Text
, subject :: Text
} deriving (Show,Generic)
instance FromJSON Email
main :: IO ()
main = do
myJSON <- B.getContents
let d = eitherDecode myJSON
case d of
Left err -> putStrLn err
Right ps -> printNotify ps
printNotify :: [Email] -> IO ()
printNotify [] = return ()
printNotify (email:emails) = do
client <- connectSession
notification <- notify client $ notifyemail email
printNotify emails
notifyemail :: Email -> Note
notifyemail email =
blankNote { summary="New Email"
, body=(Just $ Text ("From: " ++ unpack (authors email) ++ "\nSubject: " ++ unpack (subject email) ) )
, appImage=(Just $ Icon "internet-mail")
, expiry=(Milliseconds 20000) }