Loading k9mail-library/src/main/java/com/fsck/k9/mail/TransportProvider.java +8 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,15 @@ public class TransportProvider { public synchronized Transport getTransport(Context context, StoreConfig storeConfig) throws MessagingException { return getTransport(context, storeConfig, null); } public synchronized Transport getTransport(Context context, StoreConfig storeConfig, OAuth2TokenProvider oauth2TokenProvider) throws MessagingException { String uri = storeConfig.getTransportUri(); if (uri.startsWith("smtp")) { OAuth2TokenProvider oauth2TokenProvider = null; return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context), oauth2TokenProvider); return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context), oauth2TokenProvider); } else if (uri.startsWith("webdav")) { return new WebDavTransport(storeConfig); } else { Loading k9mail-library/src/main/java/com/fsck/k9/mail/oauth/OAuth2TokenProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -20,6 +20,17 @@ public interface OAuth2TokenProvider { */ List<String> getAccounts(); /** * Provides an asynchronous response to an * {@link OAuth2TokenProvider#authorizeAPI(String, Activity, OAuth2TokenProviderAuthCallback)} request */ interface OAuth2TokenProviderAuthCallback { void success(); void failure(AuthorizationException e); } /** * Request API authorization. This is a foreground action that may produce a dialog to interact with. * Loading @@ -30,10 +41,14 @@ public interface OAuth2TokenProvider { * @param callback * A callback to process the asynchronous response */ void authorizeApi(String username, Activity activity, OAuth2TokenProviderAuthCallback callback); void authorizeAPI(String username, Activity activity, OAuth2TokenProviderAuthCallback callback); /** * Fetch a token. No guarantees are provided for validity. * @param username Username * @return Token string * @throws AuthenticationFailedException */ String getToken(String username, long timeoutMillis) throws AuthenticationFailedException; Loading @@ -48,13 +63,4 @@ public interface OAuth2TokenProvider { */ void invalidateToken(String username); /** * Provides an asynchronous response to an * {@link OAuth2TokenProvider#authorizeApi(String, Activity, OAuth2TokenProviderAuthCallback)} request. */ interface OAuth2TokenProviderAuthCallback { void success(); void failure(AuthorizationException e); } } k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java +9 −6 Original line number Diff line number Diff line Loading @@ -41,7 +41,9 @@ public abstract class RemoteStore extends Store { /** * Get an instance of a remote mail store. */ public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException { public synchronized static Store getInstance(Context context, StoreConfig storeConfig, OAuth2TokenProvider oAuth2TokenProvider) throws MessagingException { String uri = storeConfig.getStoreUri(); if (uri.startsWith("local")) { Loading @@ -51,12 +53,13 @@ public abstract class RemoteStore extends Store { Store store = sStores.get(uri); if (store == null) { if (uri.startsWith("imap")) { OAuth2TokenProvider oAuth2TokenProvider = null; store = new ImapStore( storeConfig, new DefaultTrustedSocketFactory(context), (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider); (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider ); } else if (uri.startsWith("pop3")) { store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context)); } else if (uri.startsWith("webdav")) { Loading k9mail/src/main/AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <!-- Needed to mark a contact as contacted --> <uses-permission android:name="android.permission.WRITE_CONTACTS"/> Loading k9mail/src/main/java/com/fsck/k9/Account.java +2 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.Transport; import timber.log.Timber; import com.fsck.k9.account.AndroidAccountOAuth2TokenStore; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.MessagingException; Loading Loading @@ -1380,7 +1381,7 @@ public class Account implements BaseAccount, AccountConfig { } public Store getRemoteStore() throws MessagingException { return RemoteStore.getInstance(K9.app, this); return RemoteStore.getInstance(K9.app, this, Globals.getOAuth2TokenProvider()); } // It'd be great if this actually went into the store implementation Loading Loading
k9mail-library/src/main/java/com/fsck/k9/mail/TransportProvider.java +8 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,15 @@ public class TransportProvider { public synchronized Transport getTransport(Context context, StoreConfig storeConfig) throws MessagingException { return getTransport(context, storeConfig, null); } public synchronized Transport getTransport(Context context, StoreConfig storeConfig, OAuth2TokenProvider oauth2TokenProvider) throws MessagingException { String uri = storeConfig.getTransportUri(); if (uri.startsWith("smtp")) { OAuth2TokenProvider oauth2TokenProvider = null; return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context), oauth2TokenProvider); return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context), oauth2TokenProvider); } else if (uri.startsWith("webdav")) { return new WebDavTransport(storeConfig); } else { Loading
k9mail-library/src/main/java/com/fsck/k9/mail/oauth/OAuth2TokenProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -20,6 +20,17 @@ public interface OAuth2TokenProvider { */ List<String> getAccounts(); /** * Provides an asynchronous response to an * {@link OAuth2TokenProvider#authorizeAPI(String, Activity, OAuth2TokenProviderAuthCallback)} request */ interface OAuth2TokenProviderAuthCallback { void success(); void failure(AuthorizationException e); } /** * Request API authorization. This is a foreground action that may produce a dialog to interact with. * Loading @@ -30,10 +41,14 @@ public interface OAuth2TokenProvider { * @param callback * A callback to process the asynchronous response */ void authorizeApi(String username, Activity activity, OAuth2TokenProviderAuthCallback callback); void authorizeAPI(String username, Activity activity, OAuth2TokenProviderAuthCallback callback); /** * Fetch a token. No guarantees are provided for validity. * @param username Username * @return Token string * @throws AuthenticationFailedException */ String getToken(String username, long timeoutMillis) throws AuthenticationFailedException; Loading @@ -48,13 +63,4 @@ public interface OAuth2TokenProvider { */ void invalidateToken(String username); /** * Provides an asynchronous response to an * {@link OAuth2TokenProvider#authorizeApi(String, Activity, OAuth2TokenProviderAuthCallback)} request. */ interface OAuth2TokenProviderAuthCallback { void success(); void failure(AuthorizationException e); } }
k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java +9 −6 Original line number Diff line number Diff line Loading @@ -41,7 +41,9 @@ public abstract class RemoteStore extends Store { /** * Get an instance of a remote mail store. */ public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException { public synchronized static Store getInstance(Context context, StoreConfig storeConfig, OAuth2TokenProvider oAuth2TokenProvider) throws MessagingException { String uri = storeConfig.getStoreUri(); if (uri.startsWith("local")) { Loading @@ -51,12 +53,13 @@ public abstract class RemoteStore extends Store { Store store = sStores.get(uri); if (store == null) { if (uri.startsWith("imap")) { OAuth2TokenProvider oAuth2TokenProvider = null; store = new ImapStore( storeConfig, new DefaultTrustedSocketFactory(context), (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider); (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider ); } else if (uri.startsWith("pop3")) { store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context)); } else if (uri.startsWith("webdav")) { Loading
k9mail/src/main/AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <!-- Needed to mark a contact as contacted --> <uses-permission android:name="android.permission.WRITE_CONTACTS"/> Loading
k9mail/src/main/java/com/fsck/k9/Account.java +2 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.Transport; import timber.log.Timber; import com.fsck.k9.account.AndroidAccountOAuth2TokenStore; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.MessagingException; Loading Loading @@ -1380,7 +1381,7 @@ public class Account implements BaseAccount, AccountConfig { } public Store getRemoteStore() throws MessagingException { return RemoteStore.getInstance(K9.app, this); return RemoteStore.getInstance(K9.app, this, Globals.getOAuth2TokenProvider()); } // It'd be great if this actually went into the store implementation Loading