@@ -48,22 +48,26 @@ connectSTARTTLS hostname cfg = do
48
48
(bs, startTLS) <- connectPlain hostname cfg
49
49
50
50
greeting <- bsGetLine bs
51
- failIfNot bs 220 $ parseResponse greeting
51
+ failIfNot bs 220 $ parse $ B. unpack greeting
52
52
53
53
hn <- getHostName
54
54
bsPut bs $ B. pack (" HELO " ++ hn ++ " \r\n " )
55
55
getResponse bs >>= failIfNot bs 250
56
+ bsPut bs $ B. pack (" EHLO " ++ hn ++ " \r\n " )
57
+ getResponse bs >>= failIfNot bs 250
56
58
bsPut bs $ B. pack " STARTTLS\r\n "
57
59
getResponse bs >>= failIfNot bs 220
58
60
59
61
startTLS
60
62
61
63
prefixRef <- newIORef [greeting]
62
64
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)
65
69
getCode = read . head . words
66
- getResponse bs = liftM parseResponse $ bsGetLine bs
70
+ getResponse bs = liftM parse $ getFinalResponse bs
67
71
68
72
failIfNot :: BSStream -> Integer -> (Integer , String ) -> IO ()
69
73
failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail
0 commit comments