packages feed

mime-mail 0.4.10 → 0.4.11

raw patch · 4 files changed

+82/−1 lines, 4 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.4.11++* Export renderAddress as a utility (e.g. Reply-to) [#44](https://github.com/snoyberg/mime-mail/pull/44)+ ## 0.4.10  * addParts: append mail parts to a Mail [#43](https://github.com/snoyberg/mime-mail/pull/43)
Network/Mail/Mime.hs view
@@ -28,6 +28,7 @@     , addAttachments     , addAttachmentBS     , addAttachmentsBS+    , renderAddress     , htmlPart     , plainPart     , randomString@@ -216,6 +217,15 @@         , fromByteString "\n"         , finalBuilder         ]++-- | Format an E-Mail address according to the name-addr form (see: RFC5322+-- § 3.4 "Address specification", i.e: [display-name] '<'addr-spec'>')+-- This can be handy for adding custom headers that require such format.+--+-- @since 0.4.11+renderAddress :: Address -> Text+renderAddress address =+    TE.decodeUtf8 $ toByteString $ showAddress address  showHeader :: (S.ByteString, Text) -> Builder showHeader (k, v) = mconcat
mime-mail.cabal view
@@ -1,5 +1,5 @@ Name:                mime-mail-Version:             0.4.10+Version:             0.4.11 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@@ -30,6 +30,7 @@ test-suite tests     type: exitcode-stdio-1.0     main-is: Spec.hs+    other-modules: Network.Mail.MimeSpec     hs-source-dirs: test      build-depends: base
+ test/Network/Mail/MimeSpec.hs view
@@ -0,0 +1,66 @@+{-# LANGUAGE OverloadedStrings #-}+module Network.Mail.MimeSpec where++import Test.Hspec+import Test.Hspec.QuickCheck+import Network.Mail.Mime+import qualified Data.ByteString.Lazy.Char8 as L8+import Blaze.ByteString.Builder (toLazyByteString)+import Control.Monad (forM_)+import Data.Text.Lazy.Encoding (encodeUtf8)++spec :: Spec+spec = describe "Network.Mail.Mime" $ do+    describe "quotedPrintable" $ do+        it "doesn't generate lines longer than 76 characters" $ do+            let lbs = toLazyByteString+                    $ quotedPrintable True (L8.replicate 1000 'x')+            forM_ (lines' lbs) $ (\l -> L8.length l `shouldSatisfy` (<= 76))+        it "under 76 in presence of terminating space" $ do+            let lbs = toLazyByteString+                    $ quotedPrintable True+                    $ L8.pack+                    $ foldr+                        (\a b -> b ++ replicate 74 'x' ++ [a])+                        ""+                        [' ']+            forM_ (lines' lbs) $ (\l -> L8.length l `shouldSatisfy` (<= 76))+        prop "always under 76 characters, text" $ \s ->+            let orig = L8.pack s+                gen = toLazyByteString $ quotedPrintable True orig+             in all (\l -> L8.length l <= 76) $ lines' gen+        prop "always under 76 characters, binary" $ \s ->+            let orig = L8.pack s+                gen = toLazyByteString $ quotedPrintable True orig+             in all (\l -> L8.length l <= 76) $ lines' gen++        it "example from Wikipedia" $+            let enc = "If you believe that truth=3Dbeauty, then surely mathematics is the most bea=\r\nutiful branch of philosophy=2E"+                dec = "If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy."+             in toLazyByteString (quotedPrintable True dec) `shouldBe` enc++        it "issue #17- as text" $+            let enc = "</a>=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E3=81=AE=E3=83=86=E3=82=B9=E3=83=\r\n=88"+                dec = encodeUtf8 "</a>についてのテスト"+             in toLazyByteString (quotedPrintable True dec) `shouldBe` enc++        it "issue #17- as binary" $+            let enc = "</a>=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E3=81=AE=E3=83=86=E3=82=B9=E3=83=\r\n=88"+                dec = encodeUtf8 "</a>についてのテスト"+             in toLazyByteString (quotedPrintable False dec) `shouldBe` enc++        it "concrete example: over 76 characters" $+            let orig = "\240\238\191aa\149aa\226a\235\255a=aa\SI\159a\187a\147aa\ACKa\184aaaaaa\191a\237aaaa\EM a"+                gen = toLazyByteString $ quotedPrintable True orig+             in if all (\l -> L8.length l <= 76) $ lines' gen+                    then True+                    else error $ show $ lines' gen++lines' :: L8.ByteString -> [L8.ByteString]+lines' =+    map stripCR . L8.lines+  where+    stripCR bs+        | L8.null bs = bs+        | L8.last bs == '\r' = L8.init bs+        | otherwise = bs