Use standard charset name

pull/164/head
M66B 5 years ago
parent 6a94e8a5f9
commit 15001deed7

@ -128,6 +128,7 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.NumberFormat;
@ -1536,11 +1537,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setTextIsSelectable(true);
tvBody.setMovementMethod(new TouchHandler(message));
} else if (result instanceof String)
((WebView) wvBody).loadDataWithBaseURL(null, (String) result, "text/html", "UTF-8", null);
((WebView) wvBody).loadDataWithBaseURL(null, (String) result, "text/html", StandardCharsets.UTF_8.name(), null);
else if (result == null) {
boolean show_full = args.getBoolean("show_full");
if (show_full)
((WebView) wvBody).loadDataWithBaseURL(null, "", "text/html", "UTF-8", null);
((WebView) wvBody).loadDataWithBaseURL(null, "", "text/html", StandardCharsets.UTF_8.name(), null);
else
tvBody.setText(null);
} else

@ -38,6 +38,7 @@ import com.sun.mail.imap.protocol.IMAPResponse;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Arrays;
@ -332,7 +333,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} else {
if (!protocol.supportsUtf8()) {
arg.writeAtom("CHARSET");
arg.writeAtom("UTF-8");
arg.writeAtom(StandardCharsets.UTF_8.name());
}
if (keywords)
arg.writeAtom("OR");

@ -122,6 +122,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.text.Collator;
import java.text.DateFormat;
import java.text.NumberFormat;
@ -4583,7 +4584,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
});
printWebView.loadDataWithBaseURL("about:blank", data[1], "text/html", "UTF-8", null);
printWebView.loadDataWithBaseURL("about:blank", data[1], "text/html", StandardCharsets.UTF_8.name(), null);
}
@Override

@ -57,7 +57,10 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.ExecutorService;
@ -68,6 +71,8 @@ class ImageHelper {
private static final ExecutorService executor =
Helper.getBackgroundExecutor(1, "image");
private static final int MAX_REDIRECTS = 10;
static Bitmap generateIdenticon(@NonNull String email, int size, int pixels, Context context) {
byte[] hash = getHash(email);
float h = Math.abs(email.hashCode()) % 360;
@ -346,7 +351,43 @@ class ImageHelper {
}
Bitmap bm;
try (BufferedInputStream is = new BufferedInputStream(new URL(a.source).openStream())) {
HttpURLConnection urlConnection = null;
try {
String url = a.source;
int redirects = 0;
while (true) {
urlConnection = (HttpURLConnection) new URL(url).openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(false);
urlConnection.setInstanceFollowRedirects(true);
urlConnection.connect();
int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_PERM ||
status == HttpURLConnection.HTTP_MOVED_TEMP) {
redirects++;
if (redirects > MAX_REDIRECTS)
throw new IOException("Too many redirects");
String location = URLDecoder.decode(
urlConnection.getHeaderField("Location"),
StandardCharsets.UTF_8.name());
url = new URL(new URL(url), location).toExternalForm();
Log.i("Redirect #" + redirects + " to " + url);
urlConnection.disconnect();
continue;
}
if (status != HttpURLConnection.HTTP_OK)
throw new IOException("http " + status);
break;
}
BufferedInputStream is = new BufferedInputStream(urlConnection.getInputStream());
Log.i("Probe " + a.source);
is.mark(8192);
BitmapFactory.Options options = new BitmapFactory.Options();
@ -366,6 +407,9 @@ class ImageHelper {
bm = BitmapFactory.decodeStream(is, null, options);
} else
bm = BitmapFactory.decodeStream(is);
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
if (bm == null)

Loading…
Cancel
Save