From 15001deed7b025df909ea1d9a00312b91e105743 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 30 Oct 2019 13:38:25 +0100 Subject: [PATCH] Use standard charset name --- .../eu/faircode/email/AdapterMessage.java | 5 +- .../email/BoundaryCallbackMessages.java | 3 +- .../eu/faircode/email/FragmentMessages.java | 3 +- .../java/eu/faircode/email/ImageHelper.java | 46 ++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index a6f524a974..750fa5df21 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -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 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)