splitHeader :: BS.ByteString -> String -> ([String], BS.ByteString)
splitHeader msg delim = (hdr, BS.pack $ unlines csv)
   where
      (hdr, csv) = let ((hdrr, csvr), _) = foldl' foldFn initAcc lns in
         (reverse hdrr, reverse csvr)
      lns = lines $ BS.unpack msg
      initAcc = (([],[]), False)
      foldFn ((ls, rs), True) e = ((ls, e:rs), True)
      foldFn ((ls, rs), False) e = if e == delim
                                      then
                                      ((ls, rs), True)
                                      else
                                      ((e:ls, rs), False)
splitHeader :: BS.ByteString -> String -> ([String], BS.ByteString)
splitHeader msg delim = (hdr, BS.pack $ unlines csv)
   where
      (hdr, csv) = let ((hdrr, csvr), _) = foldl' foldFn initAcc lns in
         (reverse hdrr, reverse csvr)
      lns = lines $ BS.unpack msg
      initAcc = (([],[]), False)
      foldFn ((ls, rs), True) e = ((ls, e:rs), True)
      foldFn ((ls, rs), False) e = if e == delim
                                      then
                                      ((ls, rs), True)
                                      else
                                      ((e:ls, rs), False)
splitHeader msg delim = (hdr, BS.pack $ unlines csv)
   where
      (hdr, csv) = let ((hdrr, csvr), _) = foldl' foldFn initAcc lns in
         (reverse hdrr, reverse csvr)
      lns = lines $ BS.unpack msg
      initAcc = (([],[]), False)
      foldFn ((ls, rs), True) e = ((ls, e:rs), True)
      foldFn ((ls, rs), False) e = if e == delim
                                      then
                                      ((ls, rs), True)
                                      else
                                      ((e:ls, rs), False)