packages feed

HaskellNet-SSL 0.2 → 0.2.1

raw patch · 6 files changed

+54/−42 lines, 6 files

Files

HaskellNet-SSL.cabal view
@@ -1,6 +1,6 @@ name:                HaskellNet-SSL synopsis:            Helpers to connect to SSL/TLS mail servers with HaskellNet-version:             0.2+version:             0.2.1 description:         This package ties together the HaskellNet and connection                      packages to make it easy to open IMAP and SMTP connections                      over SSL.@@ -25,7 +25,8 @@   exposed-modules:     Network.HaskellNet.IMAP.SSL                        Network.HaskellNet.POP3.SSL                        Network.HaskellNet.SMTP.SSL-  other-modules:       Network.HaskellNet.SSL+                       Network.HaskellNet.SSL+  other-modules:       Network.HaskellNet.SSL.Internal   build-depends:       base >= 4 && < 5,                        HaskellNet >= 0.3.1,                        tls >= 1.1.2,
src/Network/HaskellNet/IMAP/SSL.hs view
@@ -8,6 +8,8 @@ import Network.HaskellNet.IMAP import Network.HaskellNet.SSL +import Network.HaskellNet.SSL.Internal+ connectIMAPSSL :: String -> IO IMAPConnection connectIMAPSSL hostname = connectIMAPSSLWithSettings hostname cfg   where cfg = defaultSettingsWithPort 993
src/Network/HaskellNet/POP3/SSL.hs view
@@ -8,6 +8,8 @@ import Network.HaskellNet.POP3 import Network.HaskellNet.SSL +import Network.HaskellNet.SSL.Internal+ connectPop3SSL :: String -> IO POP3Connection connectPop3SSL hostname = connectPop3SSLWithSettings hostname cfg   where cfg = defaultSettingsWithPort 995
src/Network/HaskellNet/SMTP/SSL.hs view
@@ -14,6 +14,8 @@ import Network.HaskellNet.SMTP import Network.HaskellNet.SSL +import Network.HaskellNet.SSL.Internal+ import Network.HaskellNet.BSStream import Network.BSD (getHostName) 
src/Network/HaskellNet/SSL.hs view
@@ -1,19 +1,10 @@ module Network.HaskellNet.SSL   ( Settings (..)   , defaultSettingsWithPort-  , connectSSL-  , connectPlain   ) where -import Network.Connection-import Network.HaskellNet.BSStream import Network.Socket.Internal (PortNumber) -import qualified Data.ByteString.Char8 as B-import Data.Default--type STARTTLS = IO ()- data Settings = Settings               { sslPort          :: PortNumber               , sslMaxLineLength :: Int@@ -24,34 +15,3 @@   { sslPort = p   , sslMaxLineLength = 10000   }--connectionGetBytes :: Connection -> Int -> IO B.ByteString-connectionGetBytes = loop B.empty where-  loop buf _ 0 = return buf-  loop buf c l = connectionGet c l >>= nextIteration-    where nextIteration b = loop (buf `B.append` b) c $ l - B.length b--connectionToStream :: Connection -> Settings -> BSStream-connectionToStream c cfg = BSStream-  { bsGet = connectionGetBytes c-  , bsPut = connectionPut c-  , bsFlush = return ()-  , bsClose = connectionClose c-  , bsIsOpen = return True-  , bsGetLine = connectionGetLine maxl c-  } where maxl = sslMaxLineLength cfg--connectSSL :: String -> Settings -> IO BSStream-connectSSL hostname cfg = do-    c <- initConnectionContext >>= flip connectTo params-    return $ connectionToStream c cfg-  where params = ConnectionParams hostname port (Just def) Nothing-        port = sslPort cfg--connectPlain :: String -> Settings -> IO (BSStream, STARTTLS)-connectPlain hostname cfg = do-    ctx <- initConnectionContext-    c <- connectTo ctx params-    return (connectionToStream c cfg, connectionSetSecure ctx c def)-  where params = ConnectionParams hostname port Nothing Nothing-        port = sslPort cfg
+ src/Network/HaskellNet/SSL/Internal.hs view
@@ -0,0 +1,45 @@+module Network.HaskellNet.SSL.Internal+  ( connectSSL+  , connectPlain+  ) where+++import Network.Connection+import Network.HaskellNet.SSL+import Network.HaskellNet.BSStream++import qualified Data.ByteString.Char8 as B+import Data.Default++type STARTTLS = IO ()++connectionGetBytes :: Connection -> Int -> IO B.ByteString+connectionGetBytes = loop B.empty where+  loop buf _ 0 = return buf+  loop buf c l = connectionGet c l >>= nextIteration+    where nextIteration b = loop (buf `B.append` b) c $ l - B.length b++connectionToStream :: Connection -> Settings -> BSStream+connectionToStream c cfg = BSStream+  { bsGet = connectionGetBytes c+  , bsPut = connectionPut c+  , bsFlush = return ()+  , bsClose = connectionClose c+  , bsIsOpen = return True+  , bsGetLine = connectionGetLine maxl c+  } where maxl = sslMaxLineLength cfg++connectSSL :: String -> Settings -> IO BSStream+connectSSL hostname cfg = do+    c <- initConnectionContext >>= flip connectTo params+    return $ connectionToStream c cfg+  where params = ConnectionParams hostname port (Just def) Nothing+        port = sslPort cfg++connectPlain :: String -> Settings -> IO (BSStream, STARTTLS)+connectPlain hostname cfg = do+    ctx <- initConnectionContext+    c <- connectTo ctx params+    return (connectionToStream c cfg, connectionSetSecure ctx c def)+  where params = ConnectionParams hostname port Nothing Nothing+        port = sslPort cfg