|
|
@ -21,7 +21,6 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
@ -34,9 +33,10 @@ import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
|
|
|
|
|
|
@ -87,11 +87,14 @@ public class FragmentDialogUnsubscribe extends FragmentDialogBase {
|
|
|
|
protected String onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
protected String onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
final String uri = args.getString("uri");
|
|
|
|
final String uri = args.getString("uri");
|
|
|
|
final String request = "List-Unsubscribe=One-Click";
|
|
|
|
final String request = "List-Unsubscribe=One-Click";
|
|
|
|
Log.i("Unsubscribe request=" + request + " uri=" + uri);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc8058
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc8058
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int redirects = 0;
|
|
|
|
URL url = new URL(uri);
|
|
|
|
URL url = new URL(uri);
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
Log.i("Unsubscribe request=" + request + " uri=" + uri);
|
|
|
|
|
|
|
|
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setDoInput(true);
|
|
|
|
connection.setDoInput(true);
|
|
|
@ -108,6 +111,20 @@ public class FragmentDialogUnsubscribe extends FragmentDialogBase {
|
|
|
|
connection.getOutputStream().write(request.getBytes());
|
|
|
|
connection.getOutputStream().write(request.getBytes());
|
|
|
|
|
|
|
|
|
|
|
|
int status = connection.getResponseCode();
|
|
|
|
int status = connection.getResponseCode();
|
|
|
|
|
|
|
|
if (status == HttpURLConnection.HTTP_MOVED_PERM ||
|
|
|
|
|
|
|
|
status == HttpURLConnection.HTTP_MOVED_TEMP ||
|
|
|
|
|
|
|
|
status == HttpURLConnection.HTTP_SEE_OTHER ||
|
|
|
|
|
|
|
|
status == 307 /* Temporary redirect */ ||
|
|
|
|
|
|
|
|
status == 308 /* Permanent redirect */) {
|
|
|
|
|
|
|
|
String header = connection.getHeaderField("Location");
|
|
|
|
|
|
|
|
if (header != null) {
|
|
|
|
|
|
|
|
String location = URLDecoder.decode(header, StandardCharsets.UTF_8.name());
|
|
|
|
|
|
|
|
Log.i("Unsubscribe redirect=" + location);
|
|
|
|
|
|
|
|
url = new URL(url, location);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (status >= 300) {
|
|
|
|
if (status >= 300) {
|
|
|
|
String error = status + ": " + connection.getResponseMessage();
|
|
|
|
String error = status + ": " + connection.getResponseMessage();
|
|
|
|
Log.i("Unsubscribe error=" + error);
|
|
|
|
Log.i("Unsubscribe error=" + error);
|
|
|
@ -119,6 +136,9 @@ public class FragmentDialogUnsubscribe extends FragmentDialogBase {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
connection.disconnect();
|
|
|
|
connection.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (++redirects <= ConnectionHelper.MAX_REDIRECTS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|