summaryrefslogtreecommitdiffstats
path: root/ParseMail.hs
diff options
context:
space:
mode:
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]