-- an idea for splitting fields a la RFC2822. -- for Haskell Libraries email list 2004-06-08. module Fieldsplit where import Char fieldsplit :: String -> [(String,String)] fieldsplit s = goheader (lines s) where goheader [] = [] goheader ("":ls) = goheader ls -- in RFC-2822, this marks the end of headers goheader (r@(c:_):ls) | isSpace c = error "Missing field header" | otherwise = case break (== ':') r of (h,':':r') -> gobody h ls [r'] _ -> error "Missing colon" gobody h (r@(c:_):ls) rs | isSpace c = gobody h ls (r:rs) gobody h ls rs = (h, unwords (reverse rs)) : goheader ls