diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java index 6bb84d82..11a1cb7c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java @@ -32,8 +32,6 @@ import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; - /** * Use the {@link LatestPostsFragment#newInstance} factory method to create an instance of this fragment. */ @@ -205,7 +203,6 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap return true; } - deobfuscateElements(latestPostsRows, false); for (Element row : latestPostsRows) { String pTopicUrl, pTopicTitle, pDateTime, pPost; if (Integer.parseInt(row.attr("cellpadding")) == 4) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java index a0b3dafc..7f517f1e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java @@ -46,8 +46,6 @@ import okhttp3.Request; import okhttp3.Response; import timber.log.Timber; -import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; - public class StatsFragment extends Fragment { /** * The key to use when putting profile's url String to {@link StatsFragment}'s Bundle. @@ -173,7 +171,6 @@ public class StatsFragment extends Fragment { return false; { Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg"); - deobfuscateElements(titleRows, false); generalStatisticsTitle = titleRows.first().text(); if (userHasPosts) { postingActivityByTimeTitle = titleRows.get(1).text(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 4df4598f..c035ca26 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -27,9 +27,6 @@ import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import timber.log.Timber; -import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements; - - /** * Use the {@link SummaryFragment#newInstance} factory method to create an instance of this fragment. */ @@ -135,7 +132,6 @@ public class SummaryFragment extends Fragment { //Contains all summary's rows Elements summaryRows = profile.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"); - deobfuscateElements(summaryRows, false); for (Element summaryRow : summaryRows) { String rowText = summaryRow.text(), pHtml = ""; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java index 09206a1c..6c971d33 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java @@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; import android.os.AsyncTask; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Selector; @@ -46,7 +47,7 @@ public class PrepareForEditTask extends AsyncTask { .build(); try { Response response = BaseApplication.getInstance().getClient().newCall(request).execute(); - topic = ParseHelpers.parse(response.body().string()); + topic = Jsoup.parse(response.body().string()); ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index 4e91bc72..a907e057 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -8,6 +8,7 @@ import androidx.annotation.Nullable; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -112,7 +113,7 @@ public class SessionManager { try { //Make request & handle response Response response = client.newCall(request).execute(); - Document document = ParseHelpers.parse(response.body().string()); + Document document = Jsoup.parse(response.body().string()); if (validateRetrievedCookies()) { @@ -218,7 +219,7 @@ public class SessionManager { try { //Make request & handle response Response response = client.newCall(request).execute(); - Document document = ParseHelpers.parse(response.body().string()); + Document document = Jsoup.parse(response.body().string()); Elements loginButton = document.select("[value=Login]"); //Attempt to find login button if (!loginButton.isEmpty()) //If login button exists, logout was successful diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index 86db3441..950d9934 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -54,7 +54,7 @@ public abstract class NetworkTask extends ExternalAsyncTask return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null); } try { - T data = performTask(ParseHelpers.parse(responseBodyString), response); + T data = performTask(Jsoup.parse(responseBodyString), response); int resultCode = getResultCode(response, data); return new Parcel<>(resultCode, data); } catch (ParseException pe) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index 206d4c3b..f5198410 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -188,56 +188,6 @@ public class ParseHelpers { else return ""; } - /** - * Method that replaces CloudFlare-obfuscated emails with deobfuscated ones - * Replace Jsoup.parse with this wherever needed - * - * @param html html to parse - * @return a document with deobfuscated emails - */ - public static Document parse(String html) { - Document document = Jsoup.parse(html); - deobfuscateElements(document.select("span.__cf_email__,a.__cf_email__"), true); - return document; - } - - /** - * Use this method instead of parse() if you are targeting specific elements - */ - public static void deobfuscateElements(Elements elements, boolean found) { - if (!found) - elements = elements.select("span.__cf_email__,a.__cf_email__"); - - for (Element obfuscatedElement : elements) { - String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail")); - if (obfuscatedElement.is("span")) { - Element parent = obfuscatedElement.parent(); - if (parent.is("a") && parent.attr("href").contains("email-protection")) - parent.attr("href", "mailto:" + deobfuscatedEmail); - } else if (obfuscatedElement.attr("href").contains("email-protection")) - obfuscatedElement.attr("href", "mailto:" + deobfuscatedEmail); - - obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, "")); - } - } - - - /** - * @param obfuscatedEmail CloudFlare-obfuscated email - * @return deobfuscated email - */ - private static String deobfuscateEmail(String obfuscatedEmail) { - //Deobfuscate - final StringBuilder stringBuilder = new StringBuilder(); - final int r = Integer.parseInt(obfuscatedEmail.substring(0, 2), 16); - for (int n = 2; n < obfuscatedEmail.length(); n += 2) { - final int i = Integer.parseInt(obfuscatedEmail.substring(n, n + 2), 16) ^ r; - stringBuilder.append(Character.toString((char) i)); - } - - Timber.d("Email deobfuscated."); - return stringBuilder.toString(); - } public static String emojiTagToHtml(String emojiTagedString) { HashMap tagToHtmlMap = new HashMap<>(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java index 6936100f..4f335025 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java @@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.utils.parsing; import android.os.AsyncTask; import android.widget.Toast; +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; @@ -41,7 +42,7 @@ public abstract class ParseTask extends AsyncTask