Revert "Pre expire tokens"

This reverts commit 0a417725eb.
pull/200/head
M66B 3 years ago
parent 2e85b3bc0d
commit e49321af2c

@ -306,9 +306,8 @@ public class EmailService implements AutoCloseable {
this.listener = listener;
}
@NonNull
public ServiceAuthenticator connect(EntityAccount account) throws MessagingException {
return connect(
public void connect(EntityAccount account) throws MessagingException {
connect(
account.host, account.port,
account.auth_type, account.provider,
account.user, account.password,
@ -324,9 +323,8 @@ public class EmailService implements AutoCloseable {
account.certificate_alias, account.fingerprint);
}
@NonNull
public ServiceAuthenticator connect(EntityIdentity identity) throws MessagingException {
return connect(
public void connect(EntityIdentity identity) throws MessagingException {
connect(
identity.host, identity.port,
identity.auth_type, identity.provider,
identity.user, identity.password,
@ -342,16 +340,14 @@ public class EmailService implements AutoCloseable {
identity.certificate_alias, identity.fingerprint);
}
@NonNull
public ServiceAuthenticator connect(
public void connect(
String host, int port,
int auth, String provider, String user, String password,
String certificate, String fingerprint) throws MessagingException {
return connect(host, port, auth, provider, user, password, null, certificate, fingerprint);
connect(host, port, auth, provider, user, password, null, certificate, fingerprint);
}
@NonNull
private ServiceAuthenticator connect(
private void connect(
String host, int port,
int auth, String provider, String user, String password,
ServiceAuthenticator.IAuthenticated intf,
@ -395,13 +391,11 @@ 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(

@ -84,8 +84,7 @@ public class ServiceAuthenticator extends Authenticator {
return new PasswordAuthentication(user, token);
}
String refreshToken(boolean expire)
throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException {
String refreshToken(boolean expire) throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException {
if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password);
authState.refresh(context, user, expire);
@ -120,34 +119,6 @@ public class ServiceAuthenticator extends Authenticator {
return password;
}
boolean isTokenValid(int minValidity) {
Long expiration = null;
long validUntil = new Date().getTime() +
Math.round(minValidity * 60 * 1000L * 1.1f);
try {
if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
} else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
}
} catch (JSONException ex) {
Log.e(ex);
}
if (expiration != null && expiration < validUntil) {
EntityLog.log(context, user + " token" +
" expiration=" + new Date(expiration) +
" valid until" + new Date(validUntil) +
" min valid=" + minValidity + "m");
return false;
}
return true;
}
interface IAuthenticated {
void onPasswordChanged(String newPassword);
}

@ -1268,9 +1268,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.folder().setFolderStates(account.id, null);
db.account().setAccountState(account.id, "connecting");
ServiceAuthenticator authenticator;
try {
authenticator = iservice.connect(account);
iservice.connect(account);
} catch (Throwable ex) {
// Immediately report auth errors
if (ex instanceof AuthenticationFailedException) {
@ -1859,9 +1858,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"Unrecoverable",
new Exception(state.getUnrecoverable()));
if (!authenticator.isTokenValid(account.poll_interval))
throw new StoreClosedException(iservice.getStore(), "Token invalidation");
// Sends store NOOP
if (EmailService.SEPARATE_STORE_CONNECTION) {
EntityLog.log(this, account.name + " checking store" +

Loading…
Cancel
Save