@@ -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
6872failIfNot :: BSStream -> Integer -> (Integer , String ) -> IO ()
6973failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail
0 commit comments