Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e436413 authored by Philip Whitehouse's avatar Philip Whitehouse Committed by Vincent Breitmoser
Browse files

Front-end changes for Google XOAUTH2

parent 59873a7d
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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 {
+16 −10
Original line number Diff line number Diff line
@@ -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.
     *
@@ -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;

@@ -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);
    }
}
+9 −6
Original line number Diff line number Diff line
@@ -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")) {
@@ -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")) {
+4 −0
Original line number Diff line number Diff line
@@ -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"/>
+2 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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