Replace *Port connection functions with Settings equivalents
This fixes Issue 1 by allowing the user to set the maximum line length. It does slightly break the similarity with HaskellNet, which uses the *Port suffix to specify a port for each connection, but it seems like the only sensible way to do it, really. I opted not to keep the *Port functions in because the proliferation of functions doing basically the same thing would be too much, I think.
This commit is contained in:
parent
f910cef262
commit
594bd9e1f8
@ -1,17 +1,16 @@
|
|||||||
module Network.HaskellNet.IMAP.SSL
|
module Network.HaskellNet.IMAP.SSL
|
||||||
( -- * Establishing connection
|
( -- * Establishing connection
|
||||||
connectIMAPSSL
|
connectIMAPSSL
|
||||||
, connectIMAPSSLPort
|
, connectIMAPSSLWithSettings
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Network.Socket.Internal (PortNumber)
|
|
||||||
import Network.HaskellNet.IMAP.Connection
|
import Network.HaskellNet.IMAP.Connection
|
||||||
import Network.HaskellNet.IMAP
|
import Network.HaskellNet.IMAP
|
||||||
import Network.HaskellNet.SSL
|
import Network.HaskellNet.SSL
|
||||||
|
|
||||||
connectIMAPSSL :: String -> IO IMAPConnection
|
connectIMAPSSL :: String -> IO IMAPConnection
|
||||||
connectIMAPSSL hostname = connectIMAPSSLPort hostname 993
|
connectIMAPSSL hostname = connectIMAPSSLWithSettings hostname cfg
|
||||||
|
where cfg = defaultSettingsWithPort 993
|
||||||
|
|
||||||
connectIMAPSSLPort :: String -> PortNumber -> IO IMAPConnection
|
connectIMAPSSLWithSettings :: String -> Settings -> IO IMAPConnection
|
||||||
connectIMAPSSLPort hostname port = connectSSL hostname cfg >>= connectStream
|
connectIMAPSSLWithSettings hostname cfg = connectSSL hostname cfg >>= connectStream
|
||||||
where cfg = defaultSettingsWithPort port
|
|
||||||
|
|||||||
@ -1,17 +1,16 @@
|
|||||||
module Network.HaskellNet.POP3.SSL
|
module Network.HaskellNet.POP3.SSL
|
||||||
( -- * Establishing connection
|
( -- * Establishing connection
|
||||||
connectPop3SSL
|
connectPop3SSL
|
||||||
, connectPop3SSLPort
|
, connectPop3SSLWithSettings
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Network.Socket.Internal (PortNumber)
|
|
||||||
import Network.HaskellNet.POP3.Connection
|
import Network.HaskellNet.POP3.Connection
|
||||||
import Network.HaskellNet.POP3
|
import Network.HaskellNet.POP3
|
||||||
import Network.HaskellNet.SSL
|
import Network.HaskellNet.SSL
|
||||||
|
|
||||||
connectPop3SSL :: String -> IO POP3Connection
|
connectPop3SSL :: String -> IO POP3Connection
|
||||||
connectPop3SSL hostname = connectPop3SSLPort hostname 995
|
connectPop3SSL hostname = connectPop3SSLWithSettings hostname cfg
|
||||||
|
where cfg = defaultSettingsWithPort 995
|
||||||
|
|
||||||
connectPop3SSLPort :: String -> PortNumber -> IO POP3Connection
|
connectPop3SSLWithSettings :: String -> Settings -> IO POP3Connection
|
||||||
connectPop3SSLPort hostname port = connectSSL hostname cfg >>= connectStream
|
connectPop3SSLWithSettings hostname cfg = connectSSL hostname cfg >>= connectStream
|
||||||
where cfg = defaultSettingsWithPort port
|
|
||||||
|
|||||||
@ -1,17 +1,16 @@
|
|||||||
module Network.HaskellNet.SMTP.SSL
|
module Network.HaskellNet.SMTP.SSL
|
||||||
( -- * Establishing connection
|
( -- * Establishing connection
|
||||||
connectSMTPSSL
|
connectSMTPSSL
|
||||||
, connectSMTPSSLPort
|
, connectSMTPSSLWithSettings
|
||||||
, connectSMTPSTARTTLS
|
, connectSMTPSTARTTLS
|
||||||
, connectSMTPSTARTTLSPort
|
, connectSMTPSTARTTLSWithSettings
|
||||||
-- * Other Useful Operations
|
-- * Other Useful Operations
|
||||||
, doSMTPSSL
|
, doSMTPSSL
|
||||||
, doSMTPSSLPort
|
, doSMTPSSLWithSettings
|
||||||
, doSMTPSTARTTLS
|
, doSMTPSTARTTLS
|
||||||
, doSMTPSTARTTLSPort
|
, doSMTPSTARTTLSWithSettings
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Network.Socket.Internal (PortNumber)
|
|
||||||
import Network.HaskellNet.SMTP
|
import Network.HaskellNet.SMTP
|
||||||
import Network.HaskellNet.SSL
|
import Network.HaskellNet.SSL
|
||||||
|
|
||||||
@ -25,20 +24,21 @@ import Control.Monad
|
|||||||
import Data.IORef
|
import Data.IORef
|
||||||
|
|
||||||
connectSMTPSSL :: String -> IO SMTPConnection
|
connectSMTPSSL :: String -> IO SMTPConnection
|
||||||
connectSMTPSSL hostname = connectSMTPSSLPort hostname 465
|
connectSMTPSSL hostname = connectSMTPSSLWithSettings hostname cfg
|
||||||
|
where cfg = defaultSettingsWithPort 465
|
||||||
|
|
||||||
connectSMTPSSLPort :: String -> PortNumber -> IO SMTPConnection
|
connectSMTPSSLWithSettings :: String -> Settings -> IO SMTPConnection
|
||||||
connectSMTPSSLPort hostname port = connectSSL hostname cfg >>= connectStream
|
connectSMTPSSLWithSettings hostname cfg = connectSSL hostname cfg >>= connectStream
|
||||||
where cfg = defaultSettingsWithPort port
|
|
||||||
|
|
||||||
connectSMTPSTARTTLS :: String -> IO SMTPConnection
|
connectSMTPSTARTTLS :: String -> IO SMTPConnection
|
||||||
connectSMTPSTARTTLS hostname = connectSMTPSTARTTLSPort hostname 587
|
connectSMTPSTARTTLS hostname = connectSMTPSTARTTLSWithSettings hostname cfg
|
||||||
|
where cfg = defaultSettingsWithPort 587
|
||||||
|
|
||||||
connectSMTPSTARTTLSPort :: String -> PortNumber -> IO SMTPConnection
|
connectSMTPSTARTTLSWithSettings :: String -> Settings -> IO SMTPConnection
|
||||||
connectSMTPSTARTTLSPort hostname port = connectSTARTTLS hostname port >>= connectStream
|
connectSMTPSTARTTLSWithSettings hostname cfg = connectSTARTTLS hostname cfg >>= connectStream
|
||||||
|
|
||||||
connectSTARTTLS :: String -> PortNumber -> IO BSStream
|
connectSTARTTLS :: String -> Settings -> IO BSStream
|
||||||
connectSTARTTLS hostname port = do
|
connectSTARTTLS hostname cfg = do
|
||||||
(bs, startTLS) <- connectPlain hostname cfg
|
(bs, startTLS) <- connectPlain hostname cfg
|
||||||
|
|
||||||
greeting <- bsGetLine bs
|
greeting <- bsGetLine bs
|
||||||
@ -58,7 +58,6 @@ connectSTARTTLS hostname port = do
|
|||||||
parse s = (getCode s, s)
|
parse s = (getCode s, s)
|
||||||
getCode = read . head . words
|
getCode = read . head . words
|
||||||
getResponse bs = liftM parseResponse $ bsGetLine bs
|
getResponse bs = liftM parseResponse $ bsGetLine bs
|
||||||
cfg = defaultSettingsWithPort port
|
|
||||||
|
|
||||||
failIfNot :: BSStream -> Integer -> (Integer, String) -> IO ()
|
failIfNot :: BSStream -> Integer -> (Integer, String) -> IO ()
|
||||||
failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail
|
failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail
|
||||||
@ -80,11 +79,11 @@ bracketSMTP = flip bracket closeSMTP
|
|||||||
doSMTPSSL :: String -> (SMTPConnection -> IO a) -> IO a
|
doSMTPSSL :: String -> (SMTPConnection -> IO a) -> IO a
|
||||||
doSMTPSSL host = bracketSMTP $ connectSMTPSSL host
|
doSMTPSSL host = bracketSMTP $ connectSMTPSSL host
|
||||||
|
|
||||||
doSMTPSSLPort :: String -> PortNumber -> (SMTPConnection -> IO a) -> IO a
|
doSMTPSSLWithSettings :: String -> Settings -> (SMTPConnection -> IO a) -> IO a
|
||||||
doSMTPSSLPort host port = bracketSMTP $ connectSMTPSSLPort host port
|
doSMTPSSLWithSettings host port = bracketSMTP $ connectSMTPSSLWithSettings host port
|
||||||
|
|
||||||
doSMTPSTARTTLS :: String -> (SMTPConnection -> IO a) -> IO a
|
doSMTPSTARTTLS :: String -> (SMTPConnection -> IO a) -> IO a
|
||||||
doSMTPSTARTTLS host = bracketSMTP $ connectSMTPSTARTTLS host
|
doSMTPSTARTTLS host = bracketSMTP $ connectSMTPSTARTTLS host
|
||||||
|
|
||||||
doSMTPSTARTTLSPort :: String -> PortNumber -> (SMTPConnection -> IO a) -> IO a
|
doSMTPSTARTTLSWithSettings :: String -> Settings -> (SMTPConnection -> IO a) -> IO a
|
||||||
doSMTPSTARTTLSPort host port = bracketSMTP $ connectSMTPSTARTTLSPort host port
|
doSMTPSTARTTLSWithSettings host port = bracketSMTP $ connectSMTPSTARTTLSWithSettings host port
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user