From 2dfb5dd67938d435c628de8e210d1e450fea0601 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 6 Feb 2019 13:51:41 +0000 Subject: [PATCH] Fixed JavaMail properties --- .../java/eu/faircode/email/ApplicationEx.java | 1 + .../java/eu/faircode/email/MessageHelper.java | 37 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 2553fd6fdb..0df17b3569 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -62,6 +62,7 @@ public class ApplicationEx extends Application { }); createNotificationChannels(); + MessageHelper.setSystemProperties(); } private void createNotificationChannels() { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index af478a5453..424ba88b5c 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -70,6 +70,20 @@ public class MessageHelper { static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes + static void setSystemProperties() { + System.setProperty("mail.mime.decodetext.strict", "false"); + + System.setProperty("mail.mime.ignoreunknownencoding", "true"); // Content-Transfer-Encoding + System.setProperty("mail.mime.base64.ignoreerrors", "true"); + System.setProperty("mail.mime.decodefilename", "true"); + System.setProperty("mail.mime.encodefilename", "true"); + System.setProperty("mail.mime.allowutf8", "true"); // InternetAddress, MimeBodyPart, MimeUtility + + // https://docs.oracle.com/javaee/6/api/javax/mail/internet/MimeMultipart.html + System.setProperty("mail.mime.multipart.ignoremissingboundaryparameter", "true"); // javax.mail.internet.ParseException: In parameter list + System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true"); + } + static Properties getSessionProperties(int auth_type, String realm, boolean insecure) { Properties props = new Properties(); @@ -151,29 +165,8 @@ public class MessageHelper { props.put("mail.smtp.writetimeout", Integer.toString(NETWORK_TIMEOUT)); // one thread overhead props.put("mail.smtp.timeout", Integer.toString(NETWORK_TIMEOUT)); - props.put("mail.mime.allowutf8", "true"); + props.put("mail.mime.allowutf8", "true"); // SMTPTransport, MimeMessage props.put("mail.mime.address.strict", "false"); - props.put("mail.mime.decodetext.strict", "false"); - - props.put("mail.mime.ignoreunknownencoding", "true"); // Content-Transfer-Encoding - props.put("mail.mime.base64.ignoreerrors", "true"); - props.put("mail.mime.decodefilename", "true"); - props.put("mail.mime.encodefilename", "true"); - - // https://docs.oracle.com/javaee/6/api/javax/mail/internet/MimeMultipart.html - props.put("mail.mime.multipart.ignoremissingboundaryparameter", "true"); // javax.mail.internet.ParseException: In parameter list - props.put("mail.mime.multipart.ignoreexistingboundaryparameter", "true"); - - // The documentation is unclear/inconsistent whether this are system or session properties: - System.setProperty("mail.mime.address.strict", "false"); - System.setProperty("mail.mime.decodetext.strict", "false"); - - System.setProperty("mail.mime.ignoreunknownencoding", "true"); // Content-Transfer-Encoding - System.setProperty("mail.mime.decodefilename", "true"); - System.setProperty("mail.mime.encodefilename", "true"); - - System.setProperty("mail.mime.multipart.ignoremissingboundaryparameter", "true"); // javax.mail.internet.ParseException: In parameter list - System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true"); if (false) { Log.i("Prefering IPv4");