summaryrefslogtreecommitdiffstats
path: root/ParseMail.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2017-04-30 15:26:42 +0200
committertv <tv@krebsco.de>2017-04-30 15:46:32 +0200
commitb926f842b25e6f85fb4e21c25f8cfe317e7d0274 (patch)
tree669d19c05d51ba2acbc0b0f74c50fdf6d86d9f6c /ParseMail.hs
parentf5eb629cc93920cec9b48d13c5600cf64c8e5b85 (diff)
ParseMail.parseAddress: return Maybe Address
Diffstat (limited to 'ParseMail.hs')
-rw-r--r--ParseMail.hs19
1 files changed, 8 insertions, 11 deletions
diff --git a/ParseMail.hs b/ParseMail.hs
index 4a6c218..497af0f 100644
--- a/ParseMail.hs
+++ b/ParseMail.hs
@@ -61,15 +61,12 @@ fromMIMEValue val0 =
--f :: H.Header -> M.Mail -> M.Mail
f (k, v) m = case k of
"from" ->
- m { M.mailFrom =
- (\case
- Mailbox a -> a
- Group _ _ ->
- error "cannot use group in from header"
- ) $
- either error id $
- parseAddress $
- LBS.toStrict v
+ m { M.mailFrom = case parseAddress (LBS.toStrict v) of
+ Left msg -> error msg
+ Right Nothing -> M.mailFrom m
+ Right (Just (Mailbox a)) -> a
+ Right (Just (Group _ _)) ->
+ error "cannot use group in from header"
}
"to" ->
m { M.mailTo =
@@ -116,9 +113,9 @@ fromMIMEValue val0 =
}
-parseAddress :: BS.ByteString -> Either String Address
+parseAddress :: BS.ByteString -> Either String (Maybe Address)
parseAddress =
- A8.parseOnly (P.cfws *> address <* A8.endOfInput)
+ A8.parseOnly (P.cfws *> (Just <$> address <|> return Nothing) <* A8.endOfInput)
parseAddresses :: BS.ByteString -> Either String [Address]