Skip to content

Commit 22b782c

Browse files
authored
Merge pull request #32 from SiriusCourses/issue-31
Ignore 502 error on helo - fixes communication with some servers
2 parents f269e8a + 8ff8b54 commit 22b782c

File tree

1 file changed

+6
-1
lines changed
  • src/Network/HaskellNet/SMTP

1 file changed

+6
-1
lines changed

src/Network/HaskellNet/SMTP/SSL.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ connectSTARTTLS hostname cfg = do
5252

5353
hn <- getHostName
5454
bsPut bs $ B.pack ("HELO " ++ hn ++ "\r\n")
55-
getResponse bs >>= failIfNot bs 250
55+
getResponse bs >>= failIfNotEx bs (`elem` [250, 502])
5656
bsPut bs $ B.pack ("EHLO " ++ hn ++ "\r\n")
5757
getResponse bs >>= failIfNot bs 250
5858
bsPut bs $ B.pack "STARTTLS\r\n"
@@ -73,6 +73,11 @@ failIfNot :: BSStream -> Integer -> (Integer, String) -> IO ()
7373
failIfNot bs code (rc, rs) = when (code /= rc) closeAndFail
7474
where closeAndFail = bsClose bs >> fail ("cannot connect to server: " ++ rs)
7575

76+
-- | Extended version of fail if, can support multiple statuses
77+
failIfNotEx :: BSStream -> (Integer -> Bool) -> (Integer, String) -> IO ()
78+
failIfNotEx bs f (rc, rs) = unless (f rc) closeAndFail
79+
where closeAndFail = bsClose bs >> fail ("cannot connect to server: " ++ rs)
80+
7681
-- This is a bit of a nasty hack. Network.HaskellNet.SMTP.connectStream
7782
-- expects to receive a status 220 from the server as soon as it connects,
7883
-- but we've intercepted it in order to establish a STARTTLS connection.

0 commit comments

Comments
 (0)