X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FMail.hs;h=e1884afb9daf0c9fa2df33b67b30e81f82ab79a9;hp=c54255a56a26a1e620a0f53f0d7386545ed55161;hb=9b6d95a82745ced2a58d9bc4ded555ee36b36673;hpb=81f6cb2ec955695d8d1a4619dab69e8fa4b3fb27 diff --git a/src/Mail.hs b/src/Mail.hs index c54255a..e1884af 100644 --- a/src/Mail.hs +++ b/src/Mail.hs @@ -15,7 +15,7 @@ import System.IO (hClose, hGetContents, hPutStr) type Header = String --- |A crude model of an RFC821 email message. +-- | A crude model of an RFC821 email message. data Message = Message { headers :: [Header], subject :: String, body :: String, @@ -23,35 +23,39 @@ data Message = Message { headers :: [Header], to :: String } deriving (Eq) --- |The default headers attached to each message. --- The MIME junk is needed for UTF-8 to work properly. --- Note that your mail server should support the 8BITMIME extension. +-- | The default headers attached to each message. The MIME junk is +-- needed for UTF-8 to work properly. Note that your mail server +-- should support the 8BITMIME extension. default_headers :: [Header] default_headers = ["MIME-Version: 1.0", "Content-Type: text/plain; charset=UTF-8", "Content-Transfer-Encoding: 8bit"] --- |Showing a message will print it in roughly RFC-compliant --- form. This form is sufficient for handing the message off to --- sendmail (or compatible). +-- | Showing a message will print it in roughly RFC-compliant +-- form. This form is sufficient for handing the message off to +-- sendmail (or compatible). instance Show Message where - show m = - concat [ if (length (headers m) == 0) then "" else (intercalate "\n" (headers m)) ++ "\n", - "Subject: " ++ (subject m) ++ "\n", - "From: " ++ (from m) ++ "\n", - "To: " ++ (to m) ++ "\n", - "\n", - (body m) ] - + show m = + concat [ formatted_headers, + "Subject: " ++ (subject m) ++ "\n", + "From: " ++ (from m) ++ "\n", + "To: " ++ (to m) ++ "\n", + "\n", + (body m) ] + where + formatted_headers = + if (length (headers m) == 0) + then "" + else (intercalate "\n" (headers m)) ++ "\n" -- |Pad a string on the left with zeros until the entire string has -- length n. pad_left :: String -> Int -> String pad_left str n - | n < (length str) = str - | otherwise = (replicate num_zeros '0') ++ str - where num_zeros = n - (length str) + | n < (length str) = str + | otherwise = (replicate num_zeros '0') ++ str + where num_zeros = n - (length str) @@ -97,8 +101,8 @@ sendmail sendmail_path message = do -- three-tuples. print_sendmail_result :: (String, String, ExitCode) -> IO () print_sendmail_result (outs, errs, ec) = do - case ec of - ExitSuccess -> return () - _ -> putStrLn $ concat ["Output: " ++ outs, - "\nErrors: " ++ errs, - "\nExit Code: " ++ (show ec)] + case ec of + ExitSuccess -> return () + _ -> putStrLn $ concat ["Output: " ++ outs, + "\nErrors: " ++ errs, + "\nExit Code: " ++ (show ec)]