Pre expire tokens

This commit is contained in:
M66B
2021-07-17 10:12:55 +02:00
parent 35fe0d2688
commit 0a417725eb
3 changed files with 48 additions and 9 deletions

View File

@@ -306,8 +306,9 @@ public class EmailService implements AutoCloseable {
this.listener = listener;
}
public void connect(EntityAccount account) throws MessagingException {
connect(
@NonNull
public ServiceAuthenticator connect(EntityAccount account) throws MessagingException {
return connect(
account.host, account.port,
account.auth_type, account.provider,
account.user, account.password,
@@ -323,8 +324,9 @@ public class EmailService implements AutoCloseable {
account.certificate_alias, account.fingerprint);
}
public void connect(EntityIdentity identity) throws MessagingException {
connect(
@NonNull
public ServiceAuthenticator connect(EntityIdentity identity) throws MessagingException {
return connect(
identity.host, identity.port,
identity.auth_type, identity.provider,
identity.user, identity.password,
@@ -340,14 +342,16 @@ public class EmailService implements AutoCloseable {
identity.certificate_alias, identity.fingerprint);
}
public void connect(
@NonNull
public ServiceAuthenticator connect(
String host, int port,
int auth, String provider, String user, String password,
String certificate, String fingerprint) throws MessagingException {
connect(host, port, auth, provider, user, password, null, certificate, fingerprint);
return connect(host, port, auth, provider, user, password, null, certificate, fingerprint);
}
private void connect(
@NonNull
private ServiceAuthenticator connect(
String host, int port,
int auth, String provider, String user, String password,
ServiceAuthenticator.IAuthenticated intf,
@@ -391,11 +395,13 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".yahoo.guid", "FAIRMAIL_V1");
connect(host, port, auth, user, authenticator, factory);
return authenticator;
} catch (AuthenticationFailedException ex) {
if (auth == AUTH_TYPE_GMAIL || auth == AUTH_TYPE_OAUTH) {
try {
authenticator.refreshToken(true);
connect(host, port, auth, user, authenticator, factory);
return authenticator;
} catch (Exception ex1) {
Log.e(ex1);
throw new AuthenticationFailedException(