From e4cc85a6fbf1eb3dcdc8304404183ea8db0a39ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Thu, 29 Aug 2013 22:37:11 -0300 Subject: Towards email scrolling --- Email.hs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'Email.hs') diff --git a/Email.hs b/Email.hs index 40d1c4c..2281703 100644 --- a/Email.hs +++ b/Email.hs @@ -18,7 +18,7 @@ data Email = Email { emailPath :: String } parseEmail :: String -> Message -parseEmail msg = unwrapEmail $ parse message "" $ fixEol msg +parseEmail msg = unwrapEmail $ parse message "" $ fixEol $ uglyWorkaround msg unwrapEmail (Right email) = email getFields (Message fs _) = fs @@ -49,6 +49,15 @@ getResentMessageID fs = do { ResentMessageID f <- fs; f } getBody (Message _ []) = "Empty body" getBody (Message _ body) = body +-- | Convert a String to multiple Strings, cropped by the maximum column +-- size if necessary. +formatBody :: String -> Int -> [String] +formatBody body maxColumns = format [] [] body where + format parsed acc [] = parsed ++ [acc] + format parsed acc ('\r':'\n':xs) = format (parsed ++ [acc]) [] xs + format parsed acc rest@(x:xs) | length acc < maxColumns = format parsed (acc ++ [x]) xs + | otherwise = format (parsed ++ [acc]) "+" rest + -- Make sure all lines are terminated by CRLF. fixEol :: String -> String fixEol ('\r':'\n':xs) = '\r' : '\n' : fixEol xs @@ -65,4 +74,18 @@ fixEol [] = [] -- emailDescriptionWithPP pp +{- This is an ugly, Ugly, UGLY workaround for the encoding problems that I + - have with Rfc2822 module. I've reported the bug. I hope it get fixed any time soon so + - I can kill this function with fire -} +uglyWorkaround :: String -> String +uglyWorkaround = map replace where + replace c = + case c of + 'á' -> 'a' + 'é' -> 'e' + 'í' -> 'i' + 'ó' -> 'o' + 'ú' -> 'u' + 'ñ' -> 'n' + _ -> c -- cgit v1.2.3