38 lines
997 B
Haskell
38 lines
997 B
Haskell
{-# LANGUAGE OverloadedLists #-}
|
|
module Test.Data.Email where
|
|
|
|
import Test.Tasty
|
|
import Test.Tasty.HUnit
|
|
|
|
import Data.ByteString.Lazy.Char8 (ByteString)
|
|
|
|
import qualified Data.Conduit.List as CL
|
|
import qualified Data.Conduit.Binary as CB
|
|
import Conduit
|
|
|
|
import Data.Email.Header
|
|
import Data.Email
|
|
|
|
sample :: ByteString
|
|
sample =
|
|
"Subject: Hello worldddd\n\
|
|
\From: me@example.com\n\
|
|
\Dkim: asd\n\
|
|
\To: you <you@example.com>\n\
|
|
\\n\n\
|
|
\From: foo bar <a mailto=\"me2@example.com\" />\n\
|
|
\asd\n"
|
|
|
|
parseToList :: ByteString -> IO [Header]
|
|
parseToList _ = runConduit (CB.sourceLbs sample .| parseEmail .| CL.consume)
|
|
|
|
tests :: TestTree
|
|
tests = testGroup "Data.Email"
|
|
[ testCase "Can parse a sample email" $ do
|
|
got <- parseToList sample
|
|
got @?= [ From "me@example.com", To ["you@example.com"]]
|
|
, testCase "Combined mailto" $ do
|
|
let got = decode "To: James Doe<james.doe@example.com<mailto:james.doe@example.com>>"
|
|
got @?= Right (To ["james.doe@example.com"])
|
|
]
|