From 0ac5c41052a84878b17a3ea0027fb9ea481669c3 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 28 Aug 2018 06:58:57 +0000 Subject: [PATCH] Refresh token on each connect --- .../eu/faircode/email/ServiceSynchronize.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 78837e8dc1..86636f444f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -389,23 +389,24 @@ public class ServiceSynchronize extends LifecycleService { final DB db = DB.getInstance(this); final ExecutorService executor = Executors.newSingleThreadExecutor(); - boolean debug = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("debug", false); - if (debug) - System.setProperty("mail.socket.debug", "true"); - - // Refresh token - if (account.auth_type == Helper.AUTH_TYPE_GMAIL) { - account.password = Helper.refreshToken(this, "com.google", account.user, account.password); - db.account().setAccountPassword(account.id, account.password); - } - - Properties props = MessageHelper.getSessionProperties(account.auth_type); - final Session isession = Session.getInstance(props, null); - isession.setDebug(debug); - // adb -t 1 logcat | grep "fairemail\|System.out" - int backoff = CONNECT_BACKOFF_START; while (state.running) { + // Debug + boolean debug = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("debug", false); + if (debug) + System.setProperty("mail.socket.debug", "true"); + + // Refresh token + if (account.auth_type == Helper.AUTH_TYPE_GMAIL) { + account.password = Helper.refreshToken(this, "com.google", account.user, account.password); + db.account().setAccountPassword(account.id, account.password); + } + + Properties props = MessageHelper.getSessionProperties(account.auth_type); + final Session isession = Session.getInstance(props, null); + isession.setDebug(debug); + // adb -t 1 logcat | grep "fairemail\|System.out" + final IMAPStore istore = (IMAPStore) isession.getStore("imaps"); final Map folders = new HashMap<>(); List noops = new ArrayList<>();