]> code.delx.au - offlineimap/commitdiff
Added runLinesConnection
authorJohn Goerzen <jgoerzen@complete.org>
Mon, 11 Aug 2008 21:35:43 +0000 (16:35 -0500)
committerJohn Goerzen <jgoerzen@complete.org>
Mon, 11 Aug 2008 21:35:43 +0000 (16:35 -0500)
src/Network/IMAP/Connection.hs

index 17fd82f83ebe8ce55b8026424c87837e7799d180..7608818b92fbdd8ea8f621fad1b9c410db7a135a 100644 (file)
@@ -20,7 +20,7 @@ module Network.IMAP.Connection where
 import Network.IMAP.Types
 import Control.Monad.State
 import Data.List.Utils(spanList)
-import Data.List(genericSplitAt, genericLength)
+import Data.List(genericSplitAt, genericLength, intercalate)
 
 type IMAPState = State (IMAPString, IMAPString)
 
@@ -65,3 +65,17 @@ runStringConnection ::
     -> (a, (String, String))    -- ^ Results: func result, buffer status
 runStringConnection sbuf func =
     runState (func newStringConnection) (sbuf::String, []::String)
+
+{- | Runs a State monad with a String connection, initializing it with 
+the passed lines.  -}
+runLinesConnection ::
+       [IMAPString]             -- ^ Buffer to send to clients
+    -> (IMAPConnection IMAPState -> IMAPState a) -- ^ Function to run
+    -> (a, (String, String))    -- ^ Results: func result, buffer status
+runLinesConnection sbuf func 
+    | sbuf == [] = 
+        -- For the empty input, no \r\n after.
+        runStringConnection [] func
+    | otherwise = 
+        -- Put \r\n between the lines, and also after the last one.
+        runStringConnection (intercalate "\r\n" sbuf ++ "\r\n") func
\ No newline at end of file