Loading k9mail-library/src/main/java/foundation/e/mail/Log.java 0 → 100644 +63 −0 Original line number Diff line number Diff line package foundation.e.mail; import android.os.Environment; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created by phoenamandre on 19/07/17. */ public class Log { static FileWriter fw =null; public static boolean isDebug = false; public static final int LEVEL_ALWAYS_LOG = 0; public static final int LEVEL_LOGCAT_ONLY = 1; public static final int LEVEL_ONLY_DEBUG = 2; public static String getDebugLogPath(){ return new File("/sdcard/mail.log").getAbsolutePath(); } public static void d(String tag, String str){ d(tag, str, LEVEL_ONLY_DEBUG); } public static void d(String tag, String str, int level){ android.util.Log.d("LogDebug","level = "+level); if(true) { android.util.Log.d("LogDebug","write file"+level); if (fw == null) { try { fw = new FileWriter(getDebugLogPath()); } catch (IOException e) { e.printStackTrace(); } } if (fw != null) { try { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); fw.append(reportDate + " : " + tag + " " + str + " \n"); fw.flush(); } catch (IOException e) { e.printStackTrace(); } } } android.util.Log.d(tag, str); } } k9mail-library/src/main/java/foundation/e/mail/mail/store/imap/ImapConnection.java +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.util.zip.InflaterInputStream; import android.net.ConnectivityManager; import android.net.NetworkInfo; import foundation.e.mail.Log; import foundation.e.mail.mail.Authentication; import foundation.e.mail.mail.AuthenticationFailedException; import foundation.e.mail.mail.CertificateValidationException; Loading Loading @@ -392,6 +393,8 @@ class ImapConnection { private List<ImapResponse> authXoauth2withSASLIR() throws IOException, MessagingException { retryXoauth2WithNewToken = true; Log.d("authdebug","authXoauth2withSASLIR"); try { return attemptXOAuth2(); } catch (NegativeImapResponseException e) { Loading @@ -399,8 +402,12 @@ class ImapConnection { oauthTokenProvider.invalidateToken(settings.getUsername()); if (!retryXoauth2WithNewToken) { Log.d("authdebug","retryXoauth2WithNewToken is false"); throw handlePermanentXoauth2Failure(e); } else { Log.d("authdebug","retryXoauth2WithNewToken is true"); return handleTemporaryXoauth2Failure(e); } } Loading @@ -418,9 +425,13 @@ class ImapConnection { //This is the intended behaviour per AccountManager Timber.v(e, "Temporary failure - retrying with new token"); Log.d("authdebug","handleTemporaryXoauth2Failure"); try { return attemptXOAuth2(); } catch (NegativeImapResponseException e2) { Log.d("authdebug","NegativeImapResponseException"); //Okay, we failed on a new token. //Invalidate the token anyway but assume it's permanent. Timber.v(e, "Authentication exception for new token, permanent error assumed"); Loading @@ -431,6 +442,7 @@ class ImapConnection { } private List<ImapResponse> attemptXOAuth2() throws MessagingException, IOException { Log.d("authdebug","attemptXOAuth2"); String token = oauthTokenProvider.getToken(settings.getUsername(), OAuth2AuthorizationCodeFlowTokenProvider.OAUTH2_TIMEOUT); String authString = Authentication.computeXoauth(settings.getUsername(), token); String tag = sendSaslIrCommand(Commands.AUTHENTICATE_XOAUTH2, authString, true); Loading k9mail/src/main/java/foundation/e/mail/account/K9OAuth2TokenProvider.java +7 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.os.Bundle; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import foundation.e.mail.Log; import foundation.e.mail.mail.AuthenticationFailedException; import foundation.e.mail.mail.OAuth2NeedUserPromptException; import foundation.e.mail.mail.oauth.OAuth2TokenProvider; Loading Loading @@ -59,13 +60,17 @@ public class K9OAuth2TokenProvider extends OAuth2TokenProvider { @Override public String getToken(String email, long timeoutMillis) throws AuthenticationFailedException, OAuth2NeedUserPromptException { Log.d("authdebug","getToken "+email); getTokenFromAccountManager(email); if (authToken != null) { Log.d("authdebug","from account manager"); return authToken; } Account gmailAccount = getAccountFromManager(email); if (gmailAccount != null) { Log.d("authdebug","is gmail"); return gmailTokenProviderWithAccountSystem.getToken(email, gmailAccount, timeoutMillis); } Loading Loading @@ -122,6 +127,8 @@ public class K9OAuth2TokenProvider extends OAuth2TokenProvider { @Override public void invalidateToken(String email) { Log.d("authdebug","invalidateToken"); getTokenFromAccountManager(email); if (authToken != null) { accountManager.invalidateAuthToken(AUTH_TOKEN_TYPE,authToken); Loading Loading
k9mail-library/src/main/java/foundation/e/mail/Log.java 0 → 100644 +63 −0 Original line number Diff line number Diff line package foundation.e.mail; import android.os.Environment; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created by phoenamandre on 19/07/17. */ public class Log { static FileWriter fw =null; public static boolean isDebug = false; public static final int LEVEL_ALWAYS_LOG = 0; public static final int LEVEL_LOGCAT_ONLY = 1; public static final int LEVEL_ONLY_DEBUG = 2; public static String getDebugLogPath(){ return new File("/sdcard/mail.log").getAbsolutePath(); } public static void d(String tag, String str){ d(tag, str, LEVEL_ONLY_DEBUG); } public static void d(String tag, String str, int level){ android.util.Log.d("LogDebug","level = "+level); if(true) { android.util.Log.d("LogDebug","write file"+level); if (fw == null) { try { fw = new FileWriter(getDebugLogPath()); } catch (IOException e) { e.printStackTrace(); } } if (fw != null) { try { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); fw.append(reportDate + " : " + tag + " " + str + " \n"); fw.flush(); } catch (IOException e) { e.printStackTrace(); } } } android.util.Log.d(tag, str); } }
k9mail-library/src/main/java/foundation/e/mail/mail/store/imap/ImapConnection.java +12 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.util.zip.InflaterInputStream; import android.net.ConnectivityManager; import android.net.NetworkInfo; import foundation.e.mail.Log; import foundation.e.mail.mail.Authentication; import foundation.e.mail.mail.AuthenticationFailedException; import foundation.e.mail.mail.CertificateValidationException; Loading Loading @@ -392,6 +393,8 @@ class ImapConnection { private List<ImapResponse> authXoauth2withSASLIR() throws IOException, MessagingException { retryXoauth2WithNewToken = true; Log.d("authdebug","authXoauth2withSASLIR"); try { return attemptXOAuth2(); } catch (NegativeImapResponseException e) { Loading @@ -399,8 +402,12 @@ class ImapConnection { oauthTokenProvider.invalidateToken(settings.getUsername()); if (!retryXoauth2WithNewToken) { Log.d("authdebug","retryXoauth2WithNewToken is false"); throw handlePermanentXoauth2Failure(e); } else { Log.d("authdebug","retryXoauth2WithNewToken is true"); return handleTemporaryXoauth2Failure(e); } } Loading @@ -418,9 +425,13 @@ class ImapConnection { //This is the intended behaviour per AccountManager Timber.v(e, "Temporary failure - retrying with new token"); Log.d("authdebug","handleTemporaryXoauth2Failure"); try { return attemptXOAuth2(); } catch (NegativeImapResponseException e2) { Log.d("authdebug","NegativeImapResponseException"); //Okay, we failed on a new token. //Invalidate the token anyway but assume it's permanent. Timber.v(e, "Authentication exception for new token, permanent error assumed"); Loading @@ -431,6 +442,7 @@ class ImapConnection { } private List<ImapResponse> attemptXOAuth2() throws MessagingException, IOException { Log.d("authdebug","attemptXOAuth2"); String token = oauthTokenProvider.getToken(settings.getUsername(), OAuth2AuthorizationCodeFlowTokenProvider.OAUTH2_TIMEOUT); String authString = Authentication.computeXoauth(settings.getUsername(), token); String tag = sendSaslIrCommand(Commands.AUTHENTICATE_XOAUTH2, authString, true); Loading
k9mail/src/main/java/foundation/e/mail/account/K9OAuth2TokenProvider.java +7 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.os.Bundle; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import foundation.e.mail.Log; import foundation.e.mail.mail.AuthenticationFailedException; import foundation.e.mail.mail.OAuth2NeedUserPromptException; import foundation.e.mail.mail.oauth.OAuth2TokenProvider; Loading Loading @@ -59,13 +60,17 @@ public class K9OAuth2TokenProvider extends OAuth2TokenProvider { @Override public String getToken(String email, long timeoutMillis) throws AuthenticationFailedException, OAuth2NeedUserPromptException { Log.d("authdebug","getToken "+email); getTokenFromAccountManager(email); if (authToken != null) { Log.d("authdebug","from account manager"); return authToken; } Account gmailAccount = getAccountFromManager(email); if (gmailAccount != null) { Log.d("authdebug","is gmail"); return gmailTokenProviderWithAccountSystem.getToken(email, gmailAccount, timeoutMillis); } Loading Loading @@ -122,6 +127,8 @@ public class K9OAuth2TokenProvider extends OAuth2TokenProvider { @Override public void invalidateToken(String email) { Log.d("authdebug","invalidateToken"); getTokenFromAccountManager(email); if (authToken != null) { accountManager.invalidateAuthToken(AUTH_TOKEN_TYPE,authToken); Loading