]> code.delx.au - offlineimap/commitdiff
Working on getFullLine_count
authorJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 14:12:25 +0000 (09:12 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Tue, 12 Aug 2008 14:12:25 +0000 (09:12 -0500)
src/Network/IMAP/Parser.hs
testsrc/TestParser.hs

index 7e0b13a0f030b4875267e97a6fad82d492b3b2a0..c8cf6cac9a4981bec4da700d61c97079679d040e 100644 (file)
@@ -36,8 +36,10 @@ readFullResponse conn expectedtag =
 
 {- | 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)
@@ -50,9 +52,9 @@ getFullLine accum conn =
          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
index 4049869e3978d189561bc01249fce9d9c16c5773..1ccc3f1075ce521ac174ffd697dc9852508a1116 100644 (file)
@@ -45,9 +45,9 @@ prop_getFullLine_count s =
            ==> 
            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,