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

Unverified Commit d93f690c authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6045 from k9mail/replace_JSONObject

Replace usage of `JSONObject` with Moshi
parents 9cece907 906cc19b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ dependencies {
    implementation "com.squareup.okio:okio:${versions.okio}"
    implementation "commons-io:commons-io:${versions.commonsIo}"
    implementation "com.jakewharton.timber:timber:${versions.timber}"
    implementation "com.squareup.moshi:moshi:${versions.moshi}"

    testImplementation project(":mail:testing")
    testImplementation "org.robolectric:robolectric:${versions.robolectric}"
+12 −7
Original line number Diff line number Diff line
package com.fsck.k9.mail.oauth;


import java.io.IOException;

import com.fsck.k9.mail.K9MailLib;
import com.fsck.k9.mail.filter.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonDataException;
import com.squareup.moshi.Moshi;
import timber.log.Timber;


@@ -24,13 +27,15 @@ public class XOAuth2ChallengeParser {
        }

        try {
            JSONObject json = new JSONObject(decodedResponse);
            String status = json.getString("status");
            if (!BAD_RESPONSE.equals(status)) {
            Moshi moshi = new Moshi.Builder().build();
            JsonAdapter<XOAuth2Response> adapter = moshi.adapter(XOAuth2Response.class);
            XOAuth2Response responseObject = adapter.fromJson(decodedResponse);
            if (responseObject != null && responseObject.status != null &&
                    !BAD_RESPONSE.equals(responseObject.status)) {
                return false;
            }
        } catch (JSONException jsonException) {
            Timber.e("Error decoding JSON response from: %s. Response was: %s", host, decodedResponse);
        } catch (IOException | JsonDataException e) {
            Timber.e(e, "Error decoding JSON response from: %s. Response was: %s", host, decodedResponse);
        }

        return true;
+6 −0
Original line number Diff line number Diff line
package com.fsck.k9.mail.oauth;


class XOAuth2Response {
    public String status;
}