{- | Read a full line from the server, handling any continuation stuff.
-FIXME: for now, we naively assume that any line ending in '}\r\n' is
-having a continuation piece. -}
+If a {x}\r\n occurs, then that string (including the \r\n) will occur
+literally in the result, followed by the literal read, and the rest of the
+data.
+ -}
getFullLine :: Monad m =>
IMAPString -> -- ^ The accumulator (empty for first call)
Nothing -> return (accum ++ input)
Just (size) ->
do literal <- readBytes conn size
- getFullLine (accum ++ input ++ literal) conn
+ getFullLine (accum ++ input ++ "\r\n" ++ literal) conn
where checkContinuation :: String -> Maybe Int64
checkContinuation i =
- case i =~ "\\{([0-9]+)\\}$" of
- [] -> Nothing
- x -> Just (read x)
+ case i =~ "\\{([0-9]+)\\}$" :: (String, String, String, [String]) of
+ (_, _, _, [x]) -> Just (read x)
+ _ -> Nothing
==>
runLinesConnection lenS (getFullLine []) @?=
Right (expectedResult, (expectedRemain, []))
- where lenS = [head s ++ "{" ++ show (length (s !! 1)) ++ "}\r\n" ++ (s !! 1)]
- ++ (drop 2 s)
- expectedResult = concat (take 2 s)
+ where lenS = [braceString] ++ [(head . tail $ s)] ++ drop 2 s
+ braceString = head s ++ "{" ++ show (length (s !! 1)) ++ "}"
+ expectedResult = braceString ++ "\r\n" ++ (s !! 1)
expectedRemain = expectedString (drop 2 s)
allt = [q "getFullLine_basic" prop_getFullLine_basic,