Properly hande unsupported encoding

Refs #37
pull/50/head
M66B 6 years ago
parent 9d1fcf8ebc
commit 252a54a436

@ -242,18 +242,19 @@ public class MessageHelper {
return TextUtils.join(", ", formatted); return TextUtils.join(", ", formatted);
} }
String getHtml() throws MessagingException { String getHtml() throws MessagingException, UnsupportedEncodingException {
return getHtml(imessage); return getHtml(imessage);
} }
private String getHtml(Part part) throws MessagingException { private String getHtml(Part part) throws MessagingException, UnsupportedEncodingException {
if (part.isMimeType("text/*")) if (part.isMimeType("text/*"))
try { try {
String s; String s = part.getContent().toString();
try { if (part.isMimeType("text/plain"))
s = part.getContent().toString(); s = "<pre>" + s.replaceAll("\\r?\\n", "<br />") + "</pre>";
} catch (UnsupportedEncodingException ex) { return s;
throw new UnsupportedEncodingException(part.getContentType()); } catch (UnsupportedEncodingException ex) {
throw new UnsupportedEncodingException(part.getContentType());
/* /*
// https://javaee.github.io/javamail/FAQ#unsupen // https://javaee.github.io/javamail/FAQ#unsupen
InputStream is = part.getInputStream(); InputStream is = part.getInputStream();
@ -270,11 +271,7 @@ public class MessageHelper {
Log.w(Helper.TAG, uex + "\n" + Log.getStackTraceString(uex)); Log.w(Helper.TAG, uex + "\n" + Log.getStackTraceString(uex));
} }
*/ */
}
if (part.isMimeType("text/plain"))
s = "<pre>" + s.replaceAll("\\r?\\n", "<br />") + "</pre>";
return s;
} catch (IOException ex) { } catch (IOException ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
return null; return null;
@ -334,7 +331,8 @@ public class MessageHelper {
return result; return result;
} }
private List<EntityAttachment> getAttachments(BodyPart part) throws IOException, MessagingException { private List<EntityAttachment> getAttachments(BodyPart part) throws
IOException, MessagingException {
List<EntityAttachment> result = new ArrayList<>(); List<EntityAttachment> result = new ArrayList<>();
Object content = part.getContent(); Object content = part.getContent();

Loading…
Cancel
Save