mirror of https://github.com/M66B/FairEmail.git
Force plain sockets for no encryption
This commit is contained in:
parent
e728483d24
commit
6f9fe0e247
|
@ -70,6 +70,7 @@ import javax.mail.Service;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.Store;
|
import javax.mail.Store;
|
||||||
import javax.mail.event.StoreListener;
|
import javax.mail.event.StoreListener;
|
||||||
|
import javax.net.SocketFactory;
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
@ -189,6 +190,11 @@ public class EmailService implements AutoCloseable {
|
||||||
|
|
||||||
boolean starttls = (encryption == ENCRYPTION_STARTTLS);
|
boolean starttls = (encryption == ENCRYPTION_STARTTLS);
|
||||||
|
|
||||||
|
if (encryption == ENCRYPTION_NONE) {
|
||||||
|
properties.put("mail." + protocol + ".ssl.enable", "false");
|
||||||
|
properties.put("mail." + protocol + ".socketFactory", new SocketFactoryService());
|
||||||
|
}
|
||||||
|
|
||||||
if ("pop3".equals(protocol) || "pop3s".equals(protocol)) {
|
if ("pop3".equals(protocol) || "pop3s".equals(protocol)) {
|
||||||
// https://javaee.github.io/javamail/docs/api/com/sun/mail/pop3/package-summary.html#properties
|
// https://javaee.github.io/javamail/docs/api/com/sun/mail/pop3/package-summary.html#properties
|
||||||
properties.put("mail.pop3s.starttls.enable", "false");
|
properties.put("mail.pop3s.starttls.enable", "false");
|
||||||
|
@ -704,6 +710,40 @@ public class EmailService implements AutoCloseable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SocketFactoryService extends SocketFactory {
|
||||||
|
private SocketFactory factory = SocketFactory.getDefault();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket() throws IOException {
|
||||||
|
return configure(factory.createSocket());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
||||||
|
return configure(factory.createSocket(host, port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(InetAddress host, int port) throws IOException {
|
||||||
|
return configure(factory.createSocket(host, port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
||||||
|
return configure(factory.createSocket(host, port, localHost, localPort));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||||
|
return configure(factory.createSocket(address, port, localAddress, localPort));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Socket configure(Socket socket) {
|
||||||
|
Log.i("Socket type=" + socket.getClass());
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class SSLSocketFactoryService extends SSLSocketFactory {
|
private static class SSLSocketFactoryService extends SSLSocketFactory {
|
||||||
// openssl s_client -connect host:port < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout -in /dev/stdin
|
// openssl s_client -connect host:port < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout -in /dev/stdin
|
||||||
private String server;
|
private String server;
|
||||||
|
|
Loading…
Reference in New Issue