-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.hs
27 lines (24 loc) · 1.23 KB
/
State.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
module State where
import System.IO
data SmtpState = Init
| Helo { name :: String }
| Mail { name :: String, from :: String }
| Rcpt { name :: String, from :: String, to :: [String] }
| DataReady { name :: String, from :: String, to :: [String] }
| DataIn { name :: String, from :: String, to :: [String],
msg :: [String] }
instance Show SmtpState where
show Init = "Initial state"
show (Helo name) = "Recieved HELO from " ++ name
show (Mail name from) = "Recieved MAIL from " ++ name ++ " from sender "
++ from
show (Rcpt name from to) = "Recieved MAIL from " ++ name ++ " from sender "
++ from ++ " for user " ++ (foldl (++) [] to)
show (DataReady name _ _) = "Waiting for data from " ++ name
show (DataIn name _ _ _) = "Recieved data from " ++ name
printData :: SmtpState -> String -> String
printData (DataIn name from to msg) =
\time -> ("Message received from host " ++ name ++ "\r\nTimestamp: "
++ time ++ "\r\nReturnPath:" ++ from
++ (foldl (++) "" (map ("\r\nForwardPath:"++) to)) ++ "\r\n"
++ (foldl (++) "" msg))