in geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/pop3/connection/POP3Connection.java [100:155]
public boolean protocolConnect(String host, int port, String authid, String realm, String username, String password) throws MessagingException {
this.serverHost = host;
this.serverPort = port;
this.realm = realm;
this.authid = authid;
this.username = username;
this.password = password;
try {
// create socket and connect to server.
getConnection();
// consume the welcome line
getWelcome();
// if we're not already using an SSL connection, and we have permission to issue STARTTLS or its even required
// try to setup a SSL connection
if (!sslConnection && (useTLS || requireTLS)) {
// tell the server of our intention to start a TLS session
POP3Response starttlsResponse = null;
try {
starttlsResponse = sendCommand("STLS");
} catch (CommandFailedException e) {
}
//if the server does not support TLS check if its required.
//If true then throw an error, if not establish a non SSL connection
if(requireTLS && (starttlsResponse == null || starttlsResponse.isError())) {
throw new MessagingException("Server doesn't support required transport level security");
} else if(starttlsResponse != null && starttlsResponse.getStatus() == POP3Response.OK) {
// The connection is then handled by the superclass level.
getConnectedTLSSocket();
} else {
if (debug) {
debugOut("STARTTLS is enabled but not required and server does not support it. So we establish a connection without transport level security");
}
}
}
getConnection();
// go login with the server
if (login())
{
loggedIn = true;
return true;
}
return false;
} catch (IOException e) {
if (debug) {
debugOut("I/O exception establishing connection", e);
}
throw new MessagingException("Connection error", e);
}
}