+-- |Email functions and data types.
+
module Mail
where
type Header = String
+-- |A crude model of an RFC821 email message.
data Message = Message { headers :: [Header],
subject :: String,
body :: String,
to :: String }
deriving (Eq)
-instance Show Message where
+-- |Showing a message will print it in roughly RFC-compliant
+-- form. This form is sufficient for handing the message off to
+-- sendmail.
+instance Show Message where
show m =
concat [ if (length (headers m) == 0) then "" else (intercalate "\n" (headers m)) ++ "\n",
"Subject: " ++ (subject m) ++ "\n",
"\n",
(body m) ]
-
+
+-- |Takes a message as an argument, and passes it to the system's
+-- sendmail binary.
sendmail :: Message -> IO (String, String, ExitCode)
sendmail message = do
let sendmail_args = ["-f",
return (outs, errs, ec)
+-- |The 'sendmail' function returns a three-tuple of its outputs,
+-- errors, and exit codes. This function pretty-prints one of those
+-- three-tuples.
print_sendmail_result :: (String, String, ExitCode) -> IO ()
print_sendmail_result (outs, errs, ec) = do
case ec of