summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Yubao <yubao.liu@gmail.com>2012-05-24 11:28:45 +0800
committerLiu Yubao <yubao.liu@gmail.com>2012-05-24 11:32:34 +0800
commit34d4d1929afa36ff81038d5ac7de50135a559421 (patch)
tree2a4d4db9ec9b2845a7d6383035964844c12e9c49
parente1e5ddd646d4492fec5c2a485984beb9a62e8b2d (diff)
Don't wait for banner message from SMTP server after STARTTLS negotiation
According to RFC 2847 section 5.2, SMTP server won't send banner message again after STARTTLS negotiation. The original code will hang until SMTP server kicks it off due to timeout and can't send email with STARTTLS enabled, aka. sendemail.smtpEncryption = tls. Bug: Issue 1397 Change-Id: I5822e7f1aae0e13ea082964702bde96132f73e2c
-rw-r--r--gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java b/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
index 7d7bc49c4c..1f08a81deb 100644
--- a/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
+++ b/gerrit-patch-commonsnet/src/main/java/org/apache/commons/net/smtp/AuthSMTPClient.java
@@ -18,7 +18,11 @@ import com.google.gerrit.util.ssl.BlindSSLSocketFactory;
import org.apache.commons.codec.binary.Base64;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.SocketException;
import java.security.InvalidKeyException;
@@ -50,7 +54,22 @@ public class AuthSMTPClient extends SMTPClient {
}
_socket_ = sslFactory(verify).createSocket(_socket_, hostname, port, true);
- _connectAction_();
+
+ // XXX: Can't call _connectAction_() because SMTP server doesn't
+ // give banner information again after STARTTLS, thus SMTP._connectAction_()
+ // will wait on __getReply() forever, see source code of commons-net-2.2.
+ //
+ // The lines below are copied from SocketClient._connectAction_() and
+ // SMTP._connectAction_() in commons-net-2.2.
+ _socket_.setSoTimeout(_timeout_);
+ _input_ = _socket_.getInputStream();
+ _output_ = _socket_.getOutputStream();
+ _reader =
+ new BufferedReader(new InputStreamReader(_input_,
+ UTF_8));
+ _writer =
+ new BufferedWriter(new OutputStreamWriter(_output_,
+ UTF_8));
return true;
}