-- |Email functions and data types.
-module Mail
+module Mail (
+ Message(..),
+ default_headers,
+ print_sendmail_result,
+ rfc822_now,
+ sendmail
+ )
where
import Control.Concurrent
import Control.Exception (evaluate)
+import Control.Monad (liftM)
import Data.List (intercalate)
import Data.Time (formatTime, getZonedTime)
import System.Exit
(body m) ]
where
formatted_headers =
- if (length (headers m) == 0)
+ if null (headers m)
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)
-
-
-- | Constructs a 'String' in RFC822 date format for the current
-- date/time.
rfc822_now :: IO String
-rfc822_now = do
- date <- getZonedTime
- return $ formatTime defaultTimeLocale rfc822DateFormat date
+rfc822_now =
+ liftM (formatTime defaultTimeLocale rfc822DateFormat) getZonedTime
+
-- 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
+print_sendmail_result (outs, errs, ec) =
case ec of
ExitSuccess -> return ()
_ -> putStrLn $ concat ["Output: " ++ outs,