mime-mail 0.4.8.2 → 0.4.9
raw patch · 3 files changed
+47/−6 lines, 3 files
Files
- ChangeLog.md +4/−0
- Network/Mail/Mime.hs +42/−5
- mime-mail.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.4.9++* Add `sendmailCustomCaptureOutput` [#42](https://github.com/snoyberg/mime-mail/pull/42)+ ## 0.4.8.1 * Bump blaze-builder upper bound [#39](https://github.com/snoyberg/mime-mail/pull/39)
Network/Mail/Mime.hs view
@@ -15,6 +15,7 @@ -- * Sending messages , sendmail , sendmailCustom+ , sendmailCustomCaptureOutput , renderSendMail , renderSendMailCustom -- * High-level 'Mail' creation@@ -36,6 +37,7 @@ import qualified Data.ByteString.Lazy as L import Blaze.ByteString.Builder.Char.Utf8 import Blaze.ByteString.Builder+import Control.Concurrent (forkIO, putMVar, takeMVar, newEmptyMVar) import Data.Monoid import System.Random import Control.Arrow@@ -44,7 +46,7 @@ import System.Exit import System.FilePath (takeFileName) import qualified Data.ByteString.Base64 as Base64-import Control.Monad ((<=<), foldM)+import Control.Monad ((<=<), foldM, void) import Control.Exception (throwIO, ErrorCall (ErrorCall)) import Data.List (intersperse) import qualified Data.Text.Lazy as LT@@ -293,14 +295,49 @@ -> [String] -- ^ sendmail command-line options -> L.ByteString -- ^ mail message as lazy bytestring -> IO ()-sendmailCustom sm opts lbs = do- (Just hin, _, _, phandle) <- createProcess $- (proc sm opts) { std_in = CreatePipe }+sendmailCustom sm opts lbs = void $ sendmailCustomAux False sm opts lbs++-- | Like 'sendmailCustom', but also returns sendmail's output to stderr and+-- stdout as strict ByteStrings.+--+-- Since 0.4.9+sendmailCustomCaptureOutput :: FilePath+ -> [String]+ -> L.ByteString+ -> IO (S.ByteString, S.ByteString)+sendmailCustomCaptureOutput sm opts lbs = sendmailCustomAux True sm opts lbs++sendmailCustomAux :: Bool + -> FilePath+ -> [String]+ -> L.ByteString+ -> IO (S.ByteString, S.ByteString)+sendmailCustomAux captureOut sm opts lbs = do+ let baseOpts = (proc sm opts) { std_in = CreatePipe }+ pOpts = if captureOut+ then baseOpts { std_out = CreatePipe+ , std_err = CreatePipe+ }+ else baseOpts+ (Just hin, mHOut, mHErr, phandle) <- createProcess pOpts L.hPut hin lbs hClose hin+ errMVar <- newEmptyMVar+ outMVar <- newEmptyMVar+ case (mHOut, mHErr) of+ (Nothing, Nothing) -> return ()+ (Just hOut, Just hErr) -> do+ void . forkIO $ S.hGetContents hOut >>= putMVar outMVar+ void . forkIO $ S.hGetContents hErr >>= putMVar errMVar+ _ -> error "error in sendmailCustomAux: missing a handle" exitCode <- waitForProcess phandle case exitCode of- ExitSuccess -> return ()+ ExitSuccess -> if captureOut+ then do+ errOutput <- takeMVar errMVar+ outOutput <- takeMVar outMVar+ return (outOutput, errOutput)+ else return (S.empty, S.empty) _ -> throwIO $ ErrorCall ("sendmail exited with error code " ++ show exitCode) -- | Render an email message and send via the specified sendmail
mime-mail.cabal view
@@ -1,5 +1,5 @@ Name: mime-mail-Version: 0.4.8.2+Version: 0.4.9 Synopsis: Compose MIME email messages. description: Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/mime-mail>. Homepage: http://github.com/snoyberg/mime-mail