]> code.delx.au - offlineimap/blobdiff - src/Network/IMAP/Parser.hs
Initial stab at readFullResponse
[offlineimap] / src / Network / IMAP / Parser.hs
index 7e0b13a0f030b4875267e97a6fad82d492b3b2a0..1158c070321d30cf4e11aad322b69d31a8f15b63 100644 (file)
@@ -21,23 +21,26 @@ import Text.ParserCombinators.Parsec
 import Network.IMAP.Types
 import Text.Regex.Posix
 import Data.Int
+import Data.List
 
 {- | Read a full response from the server. -}
-{-
 readFullResponse :: Monad m => 
     IMAPConnection m ->         -- ^ The connection to the server
-    IMAPString ->               -- ^ The tag that we are awaiting
     m IMAPString
-readFullResponse conn expectedtag =
+readFullResponse conn =
     accumLines []
     where accumLines accum = 
-              do line <- getFullLine []
--}
+              do line <- getFullLine [] conn
+                 if "* " `isPrefixOf` line
+                    then accumLines (accum ++ line ++ "\r\n")
+                    else return (accum ++ line ++ "\r\n")
 
 {- | 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 +53,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