All pastes #836126 Raw Edit

confusedpantsd

public text v1 · immutable
#836126 ·published 2007-12-29 06:42 UTC
rendered paste body
module 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 []               = []