mime-mail 0.4 → 0.4.1.0
raw patch · 2 files changed
+44/−21 lines, 2 filesdep +base64-bytestringdep +filepathdep −dataencPVP ok
version bump matches the API change (PVP)
Dependencies added: base64-bytestring, filepath
Dependencies removed: dataenc
API changes (from Hackage documentation)
+ Network.Mail.Mime: renderSendMailCustom :: FilePath -> [String] -> Mail -> IO ()
+ Network.Mail.Mime: sendmailCustom :: FilePath -> [String] -> ByteString -> IO ()
Files
- Network/Mail/Mime.hs +41/−19
- mime-mail.cabal +3/−2
Network/Mail/Mime.hs view
@@ -13,7 +13,9 @@ , renderMail' -- * Sending messages , sendmail+ , sendmailCustom , renderSendMail+ , renderSendMailCustom -- * High-level 'Mail' creation , simpleMail -- * Utilities@@ -31,7 +33,8 @@ import System.Process import System.IO import System.Exit-import qualified Codec.Binary.Base64 as Base64+import System.FilePath (takeFileName)+import qualified Data.ByteString.Base64 as Base64 import Control.Monad ((<=<), forM) import Data.List (intersperse) import qualified Data.Text.Lazy as LT@@ -249,11 +252,25 @@ setStdGen g' return lbs --- | Send a fully-formed email message via the sendmail executable.+-- | Send a fully-formed email message via the default sendmail+-- executable with default options. sendmail :: L.ByteString -> IO ()-sendmail lbs = do- (Just hin, _, _, phandle) <- createProcess $ (proc- "/usr/sbin/sendmail" ["-t"]) { std_in = CreatePipe }+sendmail = sendmailCustom "/usr/sbin/sendmail" ["-t"]++-- | Render an email message and send via the default sendmail+-- executable with default options.+renderSendMail :: Mail -> IO ()+renderSendMail = sendmail <=< renderMail'++-- | Send a fully-formed email message via the specified sendmail+-- executable with specified options.+sendmailCustom :: FilePath -- ^ sendmail executable path+ -> [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 } L.hPut hin lbs hClose hin exitCode <- waitForProcess phandle@@ -261,9 +278,13 @@ ExitSuccess -> return () _ -> error $ "sendmail exited with error code " ++ show exitCode --- | Render an email message and send via 'sendmail'.-renderSendMail :: Mail -> IO ()-renderSendMail = sendmail <=< renderMail'+-- | Render an email message and send via the specified sendmail+-- executable with specified options.+renderSendMailCustom :: FilePath -- ^ sendmail executable path+ -> [String] -- ^ sendmail command-line options+ -> Mail -- ^ mail to render and send+ -> IO ()+renderSendMailCustom sm opts = sendmailCustom sm opts <=< renderMail' -- FIXME usage of FilePath below can lead to issues with filename encoding @@ -295,7 +316,7 @@ $ LT.encodeUtf8 htmlBody ] : (map (\(ct, fn, content) ->- [Part ct Base64 (Just $ T.pack fn) [] content]) as)+ [Part ct Base64 (Just $ T.pack (takeFileName fn)) [] content]) as) } -- | The first parameter denotes whether the input should be treated as text.@@ -373,14 +394,15 @@ go'' w = fromWord8 61 `mappend` hex (w `shiftR` 4) `mappend` hex (w .&. 15) --- Encode data into base64. Base64.encode cannot be used here--- because it suffers from stack overflow when used with larget input.+-- 57 bytes, when base64-encoded, becomes 76 characters.+-- Perform the encoding 57-bytes at a time, and then append a newline. base64 :: L.ByteString -> Builder-base64 = go Base64.encodeInc . groupN 10 . L.unpack- where- go encoder [] = case encoder Base64.EDone of- Base64.EFinal str -> fromChar8String str- go encoder (chunk:rest) = case encoder $ Base64.EChunk chunk of- Base64.EPart str next -> fromChar8String str `mappend` go next rest- fromChar8String = fromWriteList writeWord8 . map (toEnum . fromEnum)- groupN n = map (take n) . takeWhile (not . null) . iterate (drop n)+base64 lbs+ | L.null lbs = mempty+ | otherwise = fromByteString x64 `mappend`+ fromByteString "\r\n" `mappend`+ base64 y+ where+ (x', y) = L.splitAt 57 lbs+ x = S.concat $ L.toChunks x'+ x64 = Base64.encode x
mime-mail.cabal view
@@ -1,5 +1,5 @@ Name: mime-mail-Version: 0.4+Version: 0.4.1.0 Synopsis: Compose MIME email messages. Description: This package provides some high-level datatypes for declaring MIME email messages, functions for automatically composing these into bytestrings, and the ability to send bytestrings via the sendmail executable. You can also use any other library you wish to send via different methods, eg directly to SMTP. Homepage: http://github.com/snoyberg/mime-mail@@ -17,12 +17,13 @@ Library Exposed-modules: Network.Mail.Mime Build-depends: base >= 4 && < 5- , dataenc >= 0.14 && < 0.15+ , base64-bytestring >= 0.1 && < 0.2 , process >= 1.0 && < 1.2 , random >= 1.0 && < 1.1 , blaze-builder >= 0.2.1 && < 0.4 , bytestring >= 0.9.1 && < 0.10 , text >= 0.7 && < 0.12+ , filepath >= 1.2 && < 1.3 source-repository head type: git