]> code.delx.au - offlineimap/commitdiff
Added Parser.hs, working on initial code
authorJohn Goerzen <jgoerzen@complete.org>
Mon, 11 Aug 2008 05:03:21 +0000 (00:03 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Mon, 11 Aug 2008 05:03:21 +0000 (00:03 -0500)
OfflineIMAP.cabal
src/Network/IMAP/Parser.hs
src/Network/IMAP/Types.hs [new file with mode: 0644]

index 28fd5ebc178e04f3516bc05d450ec291d470328c..7769796c839bf0651c5bcbf761bfda38910b4bb7 100644 (file)
@@ -50,9 +50,10 @@ Library
 
   Build-Depends: haskell98, network, unix, parsec, MissingH>=1.0.0,
     HDBC>=1.1.0, mtl, base, hslogger,
-    ConfigFile, filepath, directory, process
+    ConfigFile, filepath, directory, process, regex-posix
 
   Exposed-Modules: Data.Syncable,
+     Network.IMAP.Types,
      Network.IMAP.Parser
 
   If flag(splitBase)
index 16522f4521384bfdbe866a18727fe064f9b70ebc..7e0b13a0f030b4875267e97a6fad82d492b3b2a0 100644 (file)
@@ -17,5 +17,42 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 -}
 
 module Network.IMAP.Parser where
+import Text.ParserCombinators.Parsec
+import Network.IMAP.Types
+import Text.Regex.Posix
+import Data.Int
 
-import 
\ No newline at end of file
+{- | 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 =
+    accumLines []
+    where accumLines accum = 
+              do line <- getFullLine []
+-}
+
+{- | 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. -}
+
+getFullLine :: Monad m => 
+               IMAPString ->    -- ^ The accumulator (empty for first call)
+               IMAPConnection m -> -- ^ IMAP connection
+               m IMAPString        -- ^ Result
+
+getFullLine accum conn =
+    do input <- readLine conn
+       case checkContinuation input of
+         Nothing -> return (accum ++ input)
+         Just (size) -> 
+             do literal <- readBytes conn size
+                getFullLine (accum ++ input ++ literal) conn
+    where checkContinuation :: String -> Maybe Int64
+          checkContinuation i =
+              case i =~ "\\{([0-9]+)\\}$" of
+                [] -> Nothing
+                x -> Just (read x)
diff --git a/src/Network/IMAP/Types.hs b/src/Network/IMAP/Types.hs
new file mode 100644 (file)
index 0000000..71a4c17
--- /dev/null
@@ -0,0 +1,32 @@
+{- offlineimap component
+Copyright (C) 2008 John Goerzen <jgoerzen@complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+module Network.IMAP.Types where
+import Data.Int
+
+-- | The fundamental type of low-level communication
+type IMAPString = String
+
+-- | The low-level IMAP connection type.
+data (Monad m) => IMAPConnection m = IMAPConnection {
+      readBytes :: Int64 -> m IMAPString, -- ^ Read exactly x bytes
+      readLine :: m IMAPString,           -- ^ Read next line, stripping off trailing CRLF
+      writeBytes :: IMAPString -> m (),   -- ^ Write text to server
+      closeConn :: m ()                   -- ^ Close IMAP connection
+    }
+