rendered paste bodymodule ProcessMail (processMail,printMail,fixEol,module Text.ParserCombinators.Parsec, module Text.ParserCombinators.Parsec.Rfc2822 ) where
-- Load the parser!
import Text.ParserCombinators.Parsec ( parse )
import Text.ParserCombinators.Parsec.Rfc2822
printMail input = do
print (processMail input)
processMail input = case (parse message "" (fixEol input) ) of
Left err -> do { return (Message [] input ) }
Right x -> do {return x}
-- Make sure all lines are terminated by CRLF.
fixEol :: String -> String
fixEol ('\r':'\n':xs) = '\r' : '\n' : (fixEol xs)
fixEol ('\n':xs) = '\r' : '\n' : (fixEol xs)
fixEol (x:xs) = x : (fixEol xs)
fixEol [] = []