summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-03-01 10:50:43 +0100
committertv <tv@shackspace.de>2015-03-01 10:50:43 +0100
commit4ed22b4a12078c8c905b59d9e0da0f47b1a5058c (patch)
tree87b65ddc3b31607cd83fe50df9d3e5762bd0a1bc
parent01bf79c915a53c6587ef3cad0f641f0b5f81af7b (diff)
ParseMail: use parseOnly
-rw-r--r--ParseMail.hs28
1 files changed, 7 insertions, 21 deletions
diff --git a/ParseMail.hs b/ParseMail.hs
index ba83833..b8fad79 100644
--- a/ParseMail.hs
+++ b/ParseMail.hs
@@ -33,14 +33,6 @@ readMail :: FilePath -> IO M.Mail
readMail p =
fromMIMEValue . parseMIMEMessage <$> T.readFile p
---meh0 :: IO M.Mail
---meh0 =
--- return . xxx . parseMIMEMessage =<< T.readFile "/home/tv/tmp/testmail"
---
---meh :: IO ()
---meh =
--- LBS8.putStr =<< M.renderMail' =<< return . xxx . parseMIMEMessage =<< T.readFile "/home/tv/tmp/testmail"
---
fromMIMEValue :: MIMEValue -> M.Mail
fromMIMEValue val =
@@ -111,8 +103,10 @@ fromMIMEValue val =
_ ->
m { M.mailHeaders =
( CI.original k
- , either "I am made of stupid" LT.toStrict $
- LT.decodeUtf8' v
+ , either
+ (const "I am made of stupid")
+ LT.toStrict
+ (LT.decodeUtf8' v)
) :
M.mailHeaders m
}
@@ -120,20 +114,12 @@ fromMIMEValue val =
parseAddress :: BS.ByteString -> Either String Address
parseAddress =
- (\x0 -> case x0 of
- A8.Done "" r -> Right r
- x -> Left $ show x
- ) .
- A8.parse (P.cfws *> address <* A8.endOfInput)
+ A8.parseOnly (P.cfws *> address <* A8.endOfInput)
parseAddresses :: BS.ByteString -> Either String [Address]
parseAddresses =
- (\x0 -> case x0 of
- A8.Done "" r -> Right r
- x -> Left $ show x
- ) .
- A8.parse (P.cfws *> address `A8.sepBy1` A8.char ',' <* A8.endOfInput)
+ A8.parseOnly (P.cfws *> address `A8.sepBy1` A8.char ',' <* A8.endOfInput)
fromMIMEParams :: [MIMEParam] -> H.Headers
@@ -214,7 +200,7 @@ localPart =
domain :: A8.Parser T.Text
domain =
(A8.<?> "domain") $
- mconcat <$> (subDomain `A8.sepBy1` A8.char '.')
+ T.intercalate "." <$> (subDomain `A8.sepBy1` A8.char '.')
-- sub-domain = domain-ref / domain-literal
subDomain :: A8.Parser T.Text