From d01c63788d09a887ffb114ee36d6787192a91e4d Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 8 Mar 2015 21:15:42 +0100 Subject: ParseMail: parse multipart messages --- ParseMail.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ParseMail.hs b/ParseMail.hs index 58b1a52..a1f91ab 100644 --- a/ParseMail.hs +++ b/ParseMail.hs @@ -34,16 +34,17 @@ readMail = fromMIMEValue :: MIMEValue -> M.Mail -fromMIMEValue val = +fromMIMEValue val0 = let m = foldr f (M.emptyMail $ M.Address Nothing "anonymous@localhost") $ fromMIMEParams - $ mime_val_headers val - in m { M.mailParts = [[part]] } + $ mime_val_headers val0 + in m { M.mailParts = [part val0] } where - part = + part val = case mime_val_content val of Single content -> + (:[]) $ M.Part -- TODO actually check if we're utf-8 or ascii(?) { M.partType = "text/plain; charset=utf-8" @@ -52,7 +53,8 @@ fromMIMEValue val = , M.partHeaders = [] , M.partContent = LT.encodeUtf8 $ LT.fromStrict content } - _ -> error ("meh: " ++ show val) + Multi vals -> + concatMap part vals --f :: H.Header -> M.Mail -> M.Mail f (k, v) m = case k of -- cgit v1.2.3