From 359a65d818325b687ad09b2f63c4dd894ab1ea58 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 26 Sep 2018 12:22:10 +0000 Subject: [PATCH] Send alternative text/html --- .../java/eu/faircode/email/MessageHelper.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index e2857217fe..6135bff001 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -25,6 +25,8 @@ import android.util.Base64; import android.util.Log; import android.webkit.MimeTypeMap; +import org.jsoup.Jsoup; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -181,14 +183,26 @@ public class MessageHelper { // TODO: plain message? - if (attachments.size() == 0) - imessage.setText(message.read(context), Charset.defaultCharset().name(), "html"); - else { - Multipart multipart = new MimeMultipart(); + String body = message.read(context); + + BodyPart plain = new MimeBodyPart(); + plain.setContent(Jsoup.parse(body).text(), "text/plain; charset=" + Charset.defaultCharset().name()); + + BodyPart html = new MimeBodyPart(); + html.setContent(body, "text/html; charset=" + Charset.defaultCharset().name()); + + Multipart alternative = new MimeMultipart("alternative"); + alternative.addBodyPart(plain); + alternative.addBodyPart(html); + + if (attachments.size() == 0) { + imessage.setContent(alternative); + } else { + Multipart multipart = new MimeMultipart("mixed"); - BodyPart bpMessage = new MimeBodyPart(); - bpMessage.setContent(message.read(context), "text/html; charset=" + Charset.defaultCharset().name()); - multipart.addBodyPart(bpMessage); + BodyPart bp = new MimeBodyPart(); + bp.setContent(alternative); + multipart.addBodyPart(bp); for (final EntityAttachment attachment : attachments) if (attachment.available) {