Skip to content

Commit 308af16

Browse files
committed
Merge pr #21 send EHLO before STARTTLS into master
2 parents ca84ef2 + 0ce4aa2 commit 308af16

File tree

1 file changed

+8
-4
lines changed
  • src/Network/HaskellNet/SMTP

1 file changed

+8
-4
lines changed

src/Network/HaskellNet/SMTP/SSL.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,26 @@ connectSTARTTLS hostname cfg = do
4848
(bs, startTLS) <- connectPlain hostname cfg
4949

5050
greeting <- bsGetLine bs
51-
failIfNot bs 220 $ parseResponse greeting
51+
failIfNot bs 220 $ parse $ B.unpack greeting
5252

5353
hn <- getHostName
5454
bsPut bs $ B.pack ("HELO " ++ hn ++ "\r\n")
5555
getResponse bs >>= failIfNot bs 250
56+
bsPut bs $ B.pack ("EHLO " ++ hn ++ "\r\n")
57+
getResponse bs >>= failIfNot bs 250
5658
bsPut bs $ B.pack "STARTTLS\r\n"
5759
getResponse bs >>= failIfNot bs 220
5860

5961
startTLS
6062

6163
prefixRef <- newIORef [greeting]
6264
return $ bs {bsGetLine = prefixedGetLine prefixRef (bsGetLine bs)}
63-
where parseResponse = parse . B.unpack
64-
parse s = (getCode s, s)
65+
where getFinalResponse bs = do
66+
line <- fmap B.unpack $ bsGetLine bs
67+
if (line !! 3) == '-' then getFinalResponse bs else return line
68+
parse s = (getCode s, s)
6569
getCode = read . head . words
66-
getResponse bs = liftM parseResponse $ bsGetLine bs
70+
getResponse bs = liftM parse $ getFinalResponse bs
6771

6872
failIfNot :: BSStream -> Integer -> (Integer, String) -> IO ()
6973
failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail

0 commit comments

Comments
 (0)