Skip to content

Commit 18d0d08

Browse files
committed
[fix] fix example and add it to ci
- continuously build example - add example as executable to *cabal file
1 parent b2067f3 commit 18d0d08

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

HaskellNet-SSL.cabal

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ library
4343
network-bsd >= 2.7 && < 2.9
4444
else
4545
build-depends: network >= 2.4 && < 3.0
46+
47+
executable HaskellNet-SSL-example
48+
hs-source-dirs: examples
49+
main-is: gmail.hs
50+
other-modules:
51+
build-depends:
52+
base <5
53+
, HaskellNet-SSL
54+
, HaskellNet
55+
, bytestring
56+
57+
default-language: Haskell2010

examples/gmail.hs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,52 @@
33
import Network.HaskellNet.IMAP.SSL
44
import Network.HaskellNet.SMTP.SSL as SMTP
55

6-
import Network.HaskellNet.Auth (AuthType(LOGIN))
6+
import Network.HaskellNet.Auth (AuthType(LOGIN), Password)
7+
import Network.Mail.Mime
78

89
import qualified Data.ByteString.Char8 as B
10+
import Data.String
911

12+
username :: IsString s => s
1013
username = "[email protected]"
14+
15+
password :: Password
1116
password = "password"
17+
18+
recipient :: Address
1219
recipient = "[email protected]"
1320

21+
imapTest :: IO ()
1422
imapTest = do
1523
c <- connectIMAPSSLWithSettings "imap.gmail.com" cfg
1624
login c username password
1725
mboxes <- list c
1826
mapM_ print mboxes
1927
select c "INBOX"
20-
msgs <- search c [ALLs]
21-
let firstMsg = head msgs
28+
msgs@(firstMsg : _) <- search c [ALLs]
2229
msgContent <- fetch c firstMsg
2330
B.putStrLn msgContent
2431
logout c
2532
where cfg = defaultSettingsIMAPSSL { sslMaxLineLength = 100000 }
2633

34+
smtpTest :: IO ()
2735
smtpTest = doSMTPSTARTTLS "smtp.gmail.com" $ \c -> do
2836
authSucceed <- SMTP.authenticate LOGIN username password c
2937
if authSucceed
30-
then sendPlainTextMail recipient username subject body c
38+
then do
39+
mail <- simpleMail
40+
recipient
41+
username
42+
subject
43+
body
44+
mempty
45+
mempty
46+
sendMail mail c -- recipient username subject body
3147
else print "Authentication error."
3248
where subject = "Test message"
3349
body = "This is a test message"
3450

3551
main :: IO ()
36-
main = smtpTest >> imapTest >> return ()
52+
main = do
53+
smtpTest
54+
imapTest

0 commit comments

Comments
 (0)