mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 22:51:02 +00:00
Use host/address for socket connect
This commit is contained in:
parent
b0007a4450
commit
b05cf6d7fa
2 changed files with 13 additions and 5 deletions
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.sun.mail.util;
|
package com.sun.mail.util;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import java.security.*;
|
import java.security.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -325,14 +327,19 @@ public class SocketFetcher {
|
||||||
if (localaddr != null)
|
if (localaddr != null)
|
||||||
socket.bind(new InetSocketAddress(localaddr, localport));
|
socket.bind(new InetSocketAddress(localaddr, localport));
|
||||||
try {
|
try {
|
||||||
|
InetAddress iaddr = InetAddress.getByName(host);
|
||||||
|
String server = props.getProperty("fairemail.server");
|
||||||
|
if (!TextUtils.isEmpty(server))
|
||||||
|
iaddr = InetAddress.getByAddress(server, iaddr.getAddress());
|
||||||
|
eu.faircode.email.Log.i("Socket connect " + iaddr);
|
||||||
logger.finest("connecting...");
|
logger.finest("connecting...");
|
||||||
if (proxyHost != null)
|
if (proxyHost != null)
|
||||||
proxyConnect(socket, proxyHost, proxyPort,
|
proxyConnect(socket, proxyHost, proxyPort,
|
||||||
proxyUser, proxyPassword, host, port, cto);
|
proxyUser, proxyPassword, host, port, cto);
|
||||||
else if (cto >= 0)
|
else if (cto >= 0)
|
||||||
socket.connect(new InetSocketAddress(host, port), cto);
|
socket.connect(new InetSocketAddress(iaddr, port), cto);
|
||||||
else
|
else
|
||||||
socket.connect(new InetSocketAddress(host, port));
|
socket.connect(new InetSocketAddress(iaddr, port));
|
||||||
logger.finest("success!");
|
logger.finest("success!");
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.FINEST, "connection failed", ex);
|
logger.log(Level.FINEST, "connection failed", ex);
|
||||||
|
|
|
@ -478,7 +478,7 @@ public class EmailService implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityLog.log(context, "Connecting to " + main);
|
EntityLog.log(context, "Connecting to " + main);
|
||||||
_connect(main, port, require_id, user, authenticator, factory);
|
_connect(host, main, port, require_id, user, authenticator, factory);
|
||||||
} catch (UnknownHostException ex) {
|
} catch (UnknownHostException ex) {
|
||||||
throw new MessagingException(ex.getMessage(), ex);
|
throw new MessagingException(ex.getMessage(), ex);
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
|
@ -552,7 +552,7 @@ public class EmailService implements AutoCloseable {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EntityLog.log(context, "Falling back to " + iaddr);
|
EntityLog.log(context, "Falling back to " + iaddr);
|
||||||
_connect(iaddr, port, require_id, user, authenticator, factory);
|
_connect(host, iaddr, port, require_id, user, authenticator, factory);
|
||||||
return;
|
return;
|
||||||
} catch (MessagingException ex1) {
|
} catch (MessagingException ex1) {
|
||||||
ex = ex1;
|
ex = ex1;
|
||||||
|
@ -570,9 +570,10 @@ public class EmailService implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _connect(
|
private void _connect(
|
||||||
InetAddress address, int port, boolean require_id,
|
String host, InetAddress address, int port, boolean require_id,
|
||||||
String user, Authenticator authenticator,
|
String user, Authenticator authenticator,
|
||||||
SSLSocketFactoryService factory) throws MessagingException {
|
SSLSocketFactoryService factory) throws MessagingException {
|
||||||
|
properties.setProperty("fairemail.server", host);
|
||||||
isession = Session.getInstance(properties, authenticator);
|
isession = Session.getInstance(properties, authenticator);
|
||||||
|
|
||||||
isession.setDebug(debug || log);
|
isession.setDebug(debug || log);
|
||||||
|
|
Loading…
Reference in a new issue