X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FMail.hs;h=ba605f977673ae3a76694888131767bfd383e255;hp=c280f1e82d2f6324385d484b6c8570af7989e041;hb=69b8af30f49aaad0f5c051998d2556b9ec291df7;hpb=53c26134670775854677470e402b8b41f19246d1 diff --git a/src/Mail.hs b/src/Mail.hs index c280f1e..ba605f9 100644 --- a/src/Mail.hs +++ b/src/Mail.hs @@ -1,3 +1,5 @@ +-- |Email functions and data types. + module Mail where @@ -11,6 +13,7 @@ import System.IO type Header = String +-- |A crude model of an RFC821 email message. data Message = Message { headers :: [Header], subject :: String, body :: String, @@ -18,7 +21,10 @@ data Message = Message { headers :: [Header], 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", @@ -28,6 +34,8 @@ instance Show Message where (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", @@ -53,6 +61,9 @@ sendmail message = do 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