From 371b858a130d34e3d6e563630b7c0c0c088154f0 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 24 Jan 2024 11:02:41 +0100 Subject: [PATCH] Small improvement --- .../com/sun/mail/handlers/text_plain.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/sun/mail/handlers/text_plain.java b/app/src/main/java/com/sun/mail/handlers/text_plain.java index 97fd6a712c..d4b082194d 100644 --- a/app/src/main/java/com/sun/mail/handlers/text_plain.java +++ b/app/src/main/java/com/sun/mail/handlers/text_plain.java @@ -59,7 +59,7 @@ public class text_plain extends handler_base { try { enc = getCharset(ds.getContentType()); is = new InputStreamReader(ds.getInputStream(), enc); - } catch (IllegalArgumentException iex) { + } catch (UnsupportedEncodingException | IllegalArgumentException iex) { /* * An unknown charset of the form ISO-XXX-XXX will cause * the JDK to throw an IllegalArgumentException. The @@ -68,9 +68,12 @@ public class text_plain extends handler_base { * and this results in an IllegalArgumentException, rather than * the expected UnsupportedEncodingException. Yikes. */ - //throw new UnsupportedEncodingException(enc); - is = new InputStreamReader(ds.getInputStream(), - eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(ds.getContentType()))); + try { + is = new InputStreamReader(ds.getInputStream(), + eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(ds.getContentType()))); + } catch (IllegalArgumentException ex) { + throw new UnsupportedEncodingException(enc); + } } try { @@ -118,7 +121,7 @@ public class text_plain extends handler_base { try { enc = getCharset(type); osw = new OutputStreamWriter(new NoCloseOutputStream(os), enc); - } catch (IllegalArgumentException iex) { + } catch (UnsupportedEncodingException | IllegalArgumentException iex) { /* * An unknown charset of the form ISO-XXX-XXX will cause * the JDK to throw an IllegalArgumentException. The @@ -127,9 +130,12 @@ public class text_plain extends handler_base { * and this results in an IllegalArgumentException, rather than * the expected UnsupportedEncodingException. Yikes. */ - //throw new UnsupportedEncodingException(enc); - osw = new OutputStreamWriter(new NoCloseOutputStream(os), - eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(type))); + try { + osw = new OutputStreamWriter(new NoCloseOutputStream(os), + eu.faircode.email.UnknownCharsetProvider.charsetForMime(getCharset(type))); + } catch (IllegalArgumentException ex) { + throw new UnsupportedEncodingException(enc); + } } String s = (String)obj;