Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40393c9381 |
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,16 +0,0 @@
|
|||||||
# Revision history for HaskellNet-SSL
|
|
||||||
|
|
||||||
## 0.4.0.0 -- 2025-01-07
|
|
||||||
|
|
||||||
- drop support for connection in favour of crypton-connection
|
|
||||||
- compatibility with GHCs up to ghc 9.8 (bump base and bytestring)
|
|
||||||
- fix example
|
|
||||||
- add tested-with stanza
|
|
||||||
|
|
||||||
## 0.4.0.1 -- 2025-01-17
|
|
||||||
|
|
||||||
- Ignore 502 error on helo - fixes communication with some servers
|
|
||||||
|
|
||||||
## 0.4.0.1 -- 2025-02-15
|
|
||||||
|
|
||||||
- bump data-default and network
|
|
||||||
@ -1,24 +1,23 @@
|
|||||||
name: HaskellNet-SSL
|
name: HaskellNet-SSL
|
||||||
synopsis: Helpers to connect to SSL/TLS mail servers with HaskellNet
|
synopsis: Helpers to connect to SSL/TLS mail servers with HaskellNet
|
||||||
version: 0.4.0.2
|
version: 0.3.4.1
|
||||||
description: This package ties together the HaskellNet and connection
|
description: This package ties together the HaskellNet and connection
|
||||||
packages to make it easy to open IMAP and SMTP connections
|
packages to make it easy to open IMAP and SMTP connections
|
||||||
over SSL.
|
over SSL.
|
||||||
homepage: https://github.com/dpwright/HaskellNet-SSL
|
homepage: https://github.com/dpwright/HaskellNet-SSL
|
||||||
tested-with: GHC ==9.4.8 || ==9.6.5 || ==9.8.2
|
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Daniel P. Wright
|
author: Daniel P. Wright
|
||||||
maintainer: Leza M. Lutonda <lemol-c@outlook.com>, dani@dpwright.com, contact@mangoiv.com
|
maintainer: Leza M. Lutonda <lemol-c@outlook.com>, dani@dpwright.com
|
||||||
copyright: (c) 2013 Daniel P. Wright
|
copyright: (c) 2013 Daniel P. Wright
|
||||||
category: Network
|
category: Network
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
cabal-version: 1.18
|
cabal-version: >=1.8
|
||||||
extra-doc-files: README.md, CHANGELOG.md
|
data-files: README.md
|
||||||
|
|
||||||
flag network-bsd
|
Flag NoUpperBounds
|
||||||
description: Get Network.BSD from the network-bsd package
|
Description: Removes upper bounds from all packages
|
||||||
default: True
|
Default: False
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
@ -27,30 +26,26 @@ source-repository head
|
|||||||
library
|
library
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
default-language: Haskell2010
|
|
||||||
exposed-modules: Network.HaskellNet.IMAP.SSL
|
exposed-modules: Network.HaskellNet.IMAP.SSL
|
||||||
Network.HaskellNet.POP3.SSL
|
Network.HaskellNet.POP3.SSL
|
||||||
Network.HaskellNet.SMTP.SSL
|
Network.HaskellNet.SMTP.SSL
|
||||||
Network.HaskellNet.SSL
|
Network.HaskellNet.SSL
|
||||||
other-modules: Network.HaskellNet.SSL.Internal
|
other-modules: Network.HaskellNet.SSL.Internal
|
||||||
build-depends: base >= 4 && < 5,
|
if flag(NoUpperBounds)
|
||||||
HaskellNet >= 0.3 && < 0.7,
|
build-depends: base >= 4,
|
||||||
crypton-connection >= 0.3.1 && < 0.5,
|
HaskellNet >= 0.3,
|
||||||
bytestring >= 0.9 && < 0.13,
|
tls >= 1.2,
|
||||||
data-default >= 0.2 && < 0.9
|
connection >= 0.2.7,
|
||||||
if flag(network-bsd)
|
network >= 3,
|
||||||
build-depends: network >= 3.0 && < 3.3,
|
network-bsd >= 2.8,
|
||||||
network-bsd >= 2.7 && < 2.9
|
bytestring,
|
||||||
|
data-default
|
||||||
else
|
else
|
||||||
build-depends: network >= 2.4 && < 3.3
|
build-depends: base >= 4 && < 5,
|
||||||
|
HaskellNet >= 0.3 && < 0.6,
|
||||||
executable HaskellNet-SSL-example
|
tls >= 1.2 && < 1.6,
|
||||||
hs-source-dirs: examples
|
connection >= 0.2.7 && < 0.4,
|
||||||
main-is: gmail.hs
|
network >= 3 && < 3.2,
|
||||||
other-modules:
|
network-bsd >= 2.8 && < 2.9,
|
||||||
build-depends: base,
|
bytestring,
|
||||||
HaskellNet-SSL,
|
data-default
|
||||||
HaskellNet,
|
|
||||||
bytestring
|
|
||||||
|
|
||||||
default-language: Haskell2010
|
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
# HaskellNet-SSL
|
HaskellNet-SSL
|
||||||
|
--------------
|
||||||
|
|
||||||
[](https://github.com/dpwright/HaskellNet-SSL/actions/workflows/haskell.yml)
|
[](https://travis-ci.org/dpwright/HaskellNet-SSL)
|
||||||
|
|
||||||
This package ties together the excellent [HaskellNet][HaskellNet] and
|
This package ties together the excellent [HaskellNet][HaskellNet] and
|
||||||
[crypton-connection][crypton-connection] packages to make it easy to open IMAP and SMTP
|
[connection][connection] packages to make it easy to open IMAP and SMTP
|
||||||
connections over SSL. This is a simple "glue" library; all credit for a)
|
connections over SSL. This is a simple "glue" library; all credit for a)
|
||||||
connecting to IMAP/SMTP servers and b) making an SSL connection goes to the
|
connecting to IMAP/SMTP servers and b) making an SSL connection goes to the
|
||||||
aforementioned libraries.
|
aforementioned libraries.
|
||||||
|
|
||||||
[HaskellNet]: https://github.com/jtdaugherty/HaskellNet
|
[HaskellNet]: https://github.com/jtdaugherty/HaskellNet
|
||||||
[crypton-connection]: https://github.com/kazu-yamamoto/crypton-connection
|
[connection]: https://github.com/vincenthz/hs-connection
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
packages: .
|
|
||||||
|
|
||||||
allow-newer:
|
|
||||||
, HaskellNet:base
|
|
||||||
, HaskellNet:network
|
|
||||||
, HaskellNet:data-default
|
|
||||||
@ -3,52 +3,34 @@
|
|||||||
import Network.HaskellNet.IMAP.SSL
|
import Network.HaskellNet.IMAP.SSL
|
||||||
import Network.HaskellNet.SMTP.SSL as SMTP
|
import Network.HaskellNet.SMTP.SSL as SMTP
|
||||||
|
|
||||||
import Network.HaskellNet.Auth (AuthType(LOGIN), Password)
|
import Network.HaskellNet.Auth (AuthType(LOGIN))
|
||||||
import Network.Mail.Mime
|
|
||||||
|
|
||||||
import qualified Data.ByteString.Char8 as B
|
import qualified Data.ByteString.Char8 as B
|
||||||
import Data.String
|
|
||||||
|
|
||||||
username :: IsString s => s
|
|
||||||
username = "username@gmail.com"
|
username = "username@gmail.com"
|
||||||
|
|
||||||
password :: Password
|
|
||||||
password = "password"
|
password = "password"
|
||||||
|
|
||||||
recipient :: Address
|
|
||||||
recipient = "someone@somewhere.com"
|
recipient = "someone@somewhere.com"
|
||||||
|
|
||||||
imapTest :: IO ()
|
|
||||||
imapTest = do
|
imapTest = do
|
||||||
c <- connectIMAPSSLWithSettings "imap.gmail.com" cfg
|
c <- connectIMAPSSLWithSettings "imap.gmail.com" cfg
|
||||||
login c username password
|
login c username password
|
||||||
mboxes <- list c
|
mboxes <- list c
|
||||||
mapM_ print mboxes
|
mapM_ print mboxes
|
||||||
select c "INBOX"
|
select c "INBOX"
|
||||||
msgs@(firstMsg : _) <- search c [ALLs]
|
msgs <- search c [ALLs]
|
||||||
|
let firstMsg = head msgs
|
||||||
msgContent <- fetch c firstMsg
|
msgContent <- fetch c firstMsg
|
||||||
B.putStrLn msgContent
|
B.putStrLn msgContent
|
||||||
logout c
|
logout c
|
||||||
where cfg = defaultSettingsIMAPSSL { sslMaxLineLength = 100000 }
|
where cfg = defaultSettingsIMAPSSL { sslMaxLineLength = 100000 }
|
||||||
|
|
||||||
smtpTest :: IO ()
|
|
||||||
smtpTest = doSMTPSTARTTLS "smtp.gmail.com" $ \c -> do
|
smtpTest = doSMTPSTARTTLS "smtp.gmail.com" $ \c -> do
|
||||||
authSucceed <- SMTP.authenticate LOGIN username password c
|
authSucceed <- SMTP.authenticate LOGIN username password c
|
||||||
if authSucceed
|
if authSucceed
|
||||||
then do
|
then sendPlainTextMail recipient username subject body c
|
||||||
mail <- simpleMail
|
|
||||||
recipient
|
|
||||||
username
|
|
||||||
subject
|
|
||||||
body
|
|
||||||
mempty
|
|
||||||
mempty
|
|
||||||
sendMail mail c -- recipient username subject body
|
|
||||||
else print "Authentication error."
|
else print "Authentication error."
|
||||||
where subject = "Test message"
|
where subject = "Test message"
|
||||||
body = "This is a test message"
|
body = "This is a test message"
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = smtpTest >> imapTest >> return ()
|
||||||
smtpTest
|
|
||||||
imapTest
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
-- | IMAP SSL Connections
|
|
||||||
module Network.HaskellNet.IMAP.SSL
|
module Network.HaskellNet.IMAP.SSL
|
||||||
( -- * Establishing connection
|
( -- * Establishing connection
|
||||||
connectIMAPSSL
|
connectIMAPSSL
|
||||||
@ -16,14 +15,11 @@ import Network.HaskellNet.SSL
|
|||||||
|
|
||||||
import Network.HaskellNet.SSL.Internal
|
import Network.HaskellNet.SSL.Internal
|
||||||
|
|
||||||
-- | Create IMAP connection with default settings
|
|
||||||
connectIMAPSSL :: String -> IO IMAPConnection
|
connectIMAPSSL :: String -> IO IMAPConnection
|
||||||
connectIMAPSSL hostname = connectIMAPSSLWithSettings hostname defaultSettingsIMAPSSL
|
connectIMAPSSL hostname = connectIMAPSSLWithSettings hostname defaultSettingsIMAPSSL
|
||||||
|
|
||||||
-- | Create IMAP connection with given settings
|
|
||||||
connectIMAPSSLWithSettings :: String -> Settings -> IO IMAPConnection
|
connectIMAPSSLWithSettings :: String -> Settings -> IO IMAPConnection
|
||||||
connectIMAPSSLWithSettings hostname cfg = connectSSL hostname cfg >>= connectStream
|
connectIMAPSSLWithSettings hostname cfg = connectSSL hostname cfg >>= connectStream
|
||||||
|
|
||||||
-- | Default IMAP SSL settings, port 993
|
|
||||||
defaultSettingsIMAPSSL :: Settings
|
defaultSettingsIMAPSSL :: Settings
|
||||||
defaultSettingsIMAPSSL = defaultSettingsWithPort 993
|
defaultSettingsIMAPSSL = defaultSettingsWithPort 993
|
||||||
|
|||||||
@ -48,12 +48,10 @@ connectSTARTTLS hostname cfg = do
|
|||||||
(bs, startTLS) <- connectPlain hostname cfg
|
(bs, startTLS) <- connectPlain hostname cfg
|
||||||
|
|
||||||
greeting <- bsGetLine bs
|
greeting <- bsGetLine bs
|
||||||
failIfNot bs 220 $ parse $ B.unpack greeting
|
failIfNot bs 220 $ parseResponse greeting
|
||||||
|
|
||||||
hn <- getHostName
|
hn <- getHostName
|
||||||
bsPut bs $ B.pack ("HELO " ++ hn ++ "\r\n")
|
bsPut bs $ B.pack ("HELO " ++ hn ++ "\r\n")
|
||||||
getResponse bs >>= failIfNotEx bs (`elem` [250, 502])
|
|
||||||
bsPut bs $ B.pack ("EHLO " ++ hn ++ "\r\n")
|
|
||||||
getResponse bs >>= failIfNot bs 250
|
getResponse bs >>= failIfNot bs 250
|
||||||
bsPut bs $ B.pack "STARTTLS\r\n"
|
bsPut bs $ B.pack "STARTTLS\r\n"
|
||||||
getResponse bs >>= failIfNot bs 220
|
getResponse bs >>= failIfNot bs 220
|
||||||
@ -62,22 +60,15 @@ connectSTARTTLS hostname cfg = do
|
|||||||
|
|
||||||
prefixRef <- newIORef [greeting]
|
prefixRef <- newIORef [greeting]
|
||||||
return $ bs {bsGetLine = prefixedGetLine prefixRef (bsGetLine bs)}
|
return $ bs {bsGetLine = prefixedGetLine prefixRef (bsGetLine bs)}
|
||||||
where getFinalResponse bs = do
|
where parseResponse = parse . B.unpack
|
||||||
line <- fmap B.unpack $ bsGetLine bs
|
parse s = (getCode s, s)
|
||||||
if (line !! 3) == '-' then getFinalResponse bs else return line
|
|
||||||
parse s = (getCode s, s)
|
|
||||||
getCode = read . head . words
|
getCode = read . head . words
|
||||||
getResponse bs = liftM parse $ getFinalResponse bs
|
getResponse bs = liftM parseResponse $ bsGetLine bs
|
||||||
|
|
||||||
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
|
||||||
where closeAndFail = bsClose bs >> fail ("cannot connect to server: " ++ rs)
|
where closeAndFail = bsClose bs >> fail ("cannot connect to server: " ++ rs)
|
||||||
|
|
||||||
-- | Extended version of fail if, can support multiple statuses
|
|
||||||
failIfNotEx :: BSStream -> (Integer -> Bool) -> (Integer, String) -> IO ()
|
|
||||||
failIfNotEx bs f (rc, rs) = unless (f rc) closeAndFail
|
|
||||||
where closeAndFail = bsClose bs >> fail ("cannot connect to server: " ++ rs)
|
|
||||||
|
|
||||||
-- This is a bit of a nasty hack. Network.HaskellNet.SMTP.connectStream
|
-- This is a bit of a nasty hack. Network.HaskellNet.SMTP.connectStream
|
||||||
-- expects to receive a status 220 from the server as soon as it connects,
|
-- expects to receive a status 220 from the server as soon as it connects,
|
||||||
-- but we've intercepted it in order to establish a STARTTLS connection.
|
-- but we've intercepted it in order to establish a STARTTLS connection.
|
||||||
|
|||||||
@ -1,24 +1,17 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
|
||||||
module Network.HaskellNet.SSL
|
module Network.HaskellNet.SSL
|
||||||
( Settings (..)
|
( Settings (..)
|
||||||
, defaultSettingsWithPort
|
, defaultSettingsWithPort
|
||||||
) where
|
) where
|
||||||
|
|
||||||
#if MIN_VERSION_network(3,0,0)
|
|
||||||
import Network.Socket (PortNumber)
|
import Network.Socket (PortNumber)
|
||||||
#else
|
|
||||||
import Network.Socket.Internal (PortNumber)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Settings for configuring HaskellNet connections
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ sslPort :: PortNumber -- ^ Port number to connect to
|
{ sslPort :: PortNumber
|
||||||
, sslMaxLineLength :: Int -- ^ Max line lengths
|
, sslMaxLineLength :: Int
|
||||||
, sslLogToConsole :: Bool -- ^ Log info to console
|
, sslLogToConsole :: Bool
|
||||||
, sslDisableCertificateValidation :: Bool -- ^ Disable certificate validation
|
, sslDisableCertificateValidation :: Bool
|
||||||
} deriving(Eq, Ord, Show)
|
} deriving(Eq, Ord, Show)
|
||||||
|
|
||||||
-- | Construct default settings for a port
|
|
||||||
defaultSettingsWithPort :: PortNumber -> Settings
|
defaultSettingsWithPort :: PortNumber -> Settings
|
||||||
defaultSettingsWithPort p = Settings
|
defaultSettingsWithPort p = Settings
|
||||||
{ sslPort = p
|
{ sslPort = p
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
# resolver:
|
# resolver:
|
||||||
# name: custom-snapshot
|
# name: custom-snapshot
|
||||||
# location: "./custom-snapshot.yaml"
|
# location: "./custom-snapshot.yaml"
|
||||||
resolver: lts-7.19
|
resolver: lts-15.0
|
||||||
|
|
||||||
# User packages to be built.
|
# User packages to be built.
|
||||||
# Various formats can be used as shown in the example below.
|
# Various formats can be used as shown in the example below.
|
||||||
@ -39,7 +39,9 @@ packages:
|
|||||||
- '.'
|
- '.'
|
||||||
# Dependency packages to be pulled from upstream that are not in the resolver
|
# Dependency packages to be pulled from upstream that are not in the resolver
|
||||||
# (e.g., acme-missiles-0.3)
|
# (e.g., acme-missiles-0.3)
|
||||||
extra-deps: []
|
extra-deps:
|
||||||
|
- git: git://github.com/jtdaugherty/HaskellNet.git
|
||||||
|
commit: 5aa1f3b009253b02c4822005ac59ee208a10a347
|
||||||
|
|
||||||
# Override default flag values for local packages and extra-deps
|
# Override default flag values for local packages and extra-deps
|
||||||
flags: {}
|
flags: {}
|
||||||
|
|||||||
26
stack.yaml.lock
Normal file
26
stack.yaml.lock
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# This file was autogenerated by Stack.
|
||||||
|
# You should not edit this file by hand.
|
||||||
|
# For more information, please see the documentation at:
|
||||||
|
# https://docs.haskellstack.org/en/stable/lock_files
|
||||||
|
|
||||||
|
packages:
|
||||||
|
- completed:
|
||||||
|
cabal-file:
|
||||||
|
size: 2069
|
||||||
|
sha256: 9192ac19ea5da3cd4b8c86a4266592aff7b9256311aa5f42ae6de94ccacf1366
|
||||||
|
name: HaskellNet
|
||||||
|
version: 0.5.1
|
||||||
|
git: git://github.com/jtdaugherty/HaskellNet.git
|
||||||
|
pantry-tree:
|
||||||
|
size: 4011
|
||||||
|
sha256: 921b437ef18ccb04f889301c407263d6b5b72c5864803a000b1e61328988ce70
|
||||||
|
commit: 5aa1f3b009253b02c4822005ac59ee208a10a347
|
||||||
|
original:
|
||||||
|
git: git://github.com/jtdaugherty/HaskellNet.git
|
||||||
|
commit: 5aa1f3b009253b02c4822005ac59ee208a10a347
|
||||||
|
snapshots:
|
||||||
|
- completed:
|
||||||
|
size: 488576
|
||||||
|
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/0.yaml
|
||||||
|
sha256: e4b6a87b47ec1cf63a7f1a0884a3b276fce2b0d174a10e8753c4f618e7983568
|
||||||
|
original: lts-15.0
|
||||||
Loading…
Reference in New Issue
Block a user